xref: /trunk/main/solenv/gbuild/CustomTarget.mk (revision 05b23b56)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24gb_CustomTarget_REPOSITORYNAMES := $(gb_Helper_REPOSITORYNAMES)
25
26# N.B.: putting the "+" there at the start activates the GNU make job server
27define gb_CustomTarget__command
28+$(call gb_Helper_abbreviate_dirs,\
29	mkdir -p $(call gb_CustomTarget_get_workdir,$(2)) && \
30	$(MAKE) -C $(call gb_CustomTarget_get_workdir,$(2)) -f $< && \
31	touch $(1))
32
33endef
34
35$(call gb_CustomTarget_get_target,%) :
36	$(call gb_Output_announce,$*,$(true),MAK,3)
37	$(call gb_CustomTarget__command,$@,$*)
38
39.PHONY: $(call gb_CustomTarget_get_clean_target,%)
40$(call gb_CustomTarget_get_clean_target,%) :
41	$(call gb_Output_announce,$*,$(false),MAK,3)
42	$(call gb_Helper_abbreviate_dirs,\
43		rm -rf $(call gb_CustomTarget_get_workdir,$*) && \
44		rm -f $(call gb_CustomTarget_get_target,$*))
45
46define gb_CustomTarget__get_makefile
47$(1)/$(2)/Makefile
48endef
49
50define gb_CustomTarget_CustomTarget
51$(if $(filter $(2),$(gb_CustomTarget_REPOSITORYNAMES)),,\
52 $(error CustomTarget: no or invalid repository given; known repositories: \
53  $(gb_JavaClassSet_REPOSITORYNAMES)))
54gb_CustomTarget_REPO_$(1) := $(2)
55$(call gb_CustomTarget_get_target,$(1)) : \
56  $(call gb_CustomTarget__get_makefile,$($(2)),$(1))
57$(call gb_CustomTarget_get_workdir,$(1))/% : \
58  $(call gb_CustomTarget_get_target,$(1))
59$(eval $(call gb_Module_register_target,$(call gb_CustomTarget_get_target,$(1)),$(call gb_CustomTarget_get_clean_target,$(1))))
60endef
61
62
63define gb_CustomTarget_add_dependency
64$(eval $(call gb_CustomTarget_get_target,$(1)) : \
65	$($(gb_CustomTarget_REPO_$(1)))/$(2))
66endef
67
68define gb_CustomTarget_add_dependencies
69$(foreach dependency,$(2),$(call gb_CustomTarget_add_dependency,$(1),$(dependency)))
70endef
71
72define gb_CustomTarget_add_outdir_dependency
73$(eval $(call gb_CustomTarget_get_target,$(1)) : $(2))
74endef
75
76define gb_CustomTarget_add_outdir_dependencies
77$(foreach dependency,$(2),$(call gb_CustomTarget_add_outdir_dependency,$(1),$(dependency)))
78
79endef
80
81# vim: set noet sw=4 ts=4:
82