xref: /aoo42x/main/solenv/gbuild/CustomTarget.mk (revision b63233d8)
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))
59endef
60
61
62define gb_CustomTarget_add_dependency
63$(eval $(call gb_CustomTarget_get_target,$(1)) : \
64	$($(gb_CustomTarget_REPO_$(1)))/$(2))
65endef
66
67define gb_CustomTarget_add_dependencies
68$(foreach dependency,$(2),$(call gb_CustomTarget_add_dependency,$(1),$(dependency)))
69endef
70
71define gb_CustomTarget_add_outdir_dependency
72$(eval $(call gb_CustomTarget_get_target,$(1)) : $(2))
73endef
74
75define gb_CustomTarget_add_outdir_dependencies
76$(foreach dependency,$(2),$(call gb_CustomTarget_add_outdir_dependency,$(1),$(dependency)))
77
78endef
79
80# vim: set noet sw=4 ts=4:
81