xref: /aoo4110/main/solenv/gbuild/CustomTarget.mk (revision b1cdbd2c)
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
35define gb_CustomTarget__rules
36$$(call gb_CustomTarget_get_repo_target,$(1),%) :
37	$$(call gb_Output_announce,$$*,$$(true),MAK,3)
38	$$(call gb_CustomTarget__command,$$@,$$*)
39
40$$(call gb_CustomTarget_get_target,%) : $$(call gb_CustomTarget_get_repo_target,$(1),%)
41	$$(call gb_Helper_abbreviate_dirs,\
42		touch $$@)
43
44endef
45
46.PHONY: $(call gb_CustomTarget_get_clean_target,%)
47$(call gb_CustomTarget_get_clean_target,%) :
48	$(call gb_Output_announce,$*,$(false),MAK,3)
49	$(call gb_Helper_abbreviate_dirs,\
50		rm -rf $(call gb_CustomTarget_get_workdir,$*) && \
51		rm -f $(call gb_CustomTarget_get_target,$*) \
52			$(foreach reponame,$(gb_CustomTarget_REPOSITORYNAMES),$(call gb_CustomTarget_get_repo_target,$(reponame),$*)))
53
54
55$(foreach reponame,$(gb_CustomTarget_REPOSITORYNAMES),$(eval $(call gb_CustomTarget__rules,$(reponame))))
56
57define gb_CustomTarget__get_makefile
58$(1)/$(2)/Makefile
59endef
60
61define gb_CustomTarget_CustomTarget
62$(foreach reponame,$(gb_CustomTarget_REPOSITORYNAMES),\
63	$(eval $(call gb_CustomTarget_get_repo_target,$(reponame),$(1)) : $(call gb_CustomTarget__get_makefile,$($(reponame)),$(1))))
64
65$(call gb_CustomTarget_get_workdir,$(1))/% : $(call gb_CustomTarget_get_target,$(1))
66
67endef
68
69
70define gb_CustomTarget_add_dependency
71$(foreach reponame,$(gb_CustomTarget_REPOSITORYNAMES),\
72	$(eval $(call gb_CustomTarget_get_repo_target,$(reponame),$(1)) : $($(reponame))/$(2)))
73
74endef
75
76define gb_CustomTarget_add_dependencies
77$(foreach dependency,$(2),$(call gb_CustomTarget_add_dependency,$(1),$(dependency)))
78
79endef
80
81define gb_CustomTarget_add_outdir_dependency
82$(foreach reponame,$(gb_CustomTarget_REPOSITORYNAMES),\
83	$(eval $(call gb_CustomTarget_get_repo_target,$(reponame),$(1)) : $(2)))
84
85endef
86
87define gb_CustomTarget_add_outdir_dependencies
88$(foreach dependency,$(2),$(call gb_CustomTarget_add_outdir_dependency,$(1),$(dependency)))
89
90endef
91
92# vim: set noet sw=4 ts=4:
93