xref: /aoo42x/main/solenv/gbuild/Module.mk (revision 7871dc3e)
1*7871dc3eSAndrew Rist#**************************************************************
2*7871dc3eSAndrew Rist#
3*7871dc3eSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
4*7871dc3eSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
5*7871dc3eSAndrew Rist#  distributed with this work for additional information
6*7871dc3eSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
7*7871dc3eSAndrew Rist#  to you under the Apache License, Version 2.0 (the
8*7871dc3eSAndrew Rist#  "License"); you may not use this file except in compliance
9*7871dc3eSAndrew Rist#  with the License.  You may obtain a copy of the License at
10*7871dc3eSAndrew Rist#
11*7871dc3eSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12*7871dc3eSAndrew Rist#
13*7871dc3eSAndrew Rist#  Unless required by applicable law or agreed to in writing,
14*7871dc3eSAndrew Rist#  software distributed under the License is distributed on an
15*7871dc3eSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*7871dc3eSAndrew Rist#  KIND, either express or implied.  See the License for the
17*7871dc3eSAndrew Rist#  specific language governing permissions and limitations
18*7871dc3eSAndrew Rist#  under the License.
19*7871dc3eSAndrew Rist#
20*7871dc3eSAndrew Rist#**************************************************************
21*7871dc3eSAndrew Rist
22*7871dc3eSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir
25cdf0e10cSrcweir# Module class
26cdf0e10cSrcweir
27cdf0e10cSrcweirgb_Module_ALLMODULES :=
28cdf0e10cSrcweirgb_Module_MODULELOCATIONS :=
29cdf0e10cSrcweirgb_Module_TARGETSTACK :=
30cdf0e10cSrcweirgb_Module_CHECKTARGETSTACK :=
31cdf0e10cSrcweirgb_Module_SUBSEQUENTCHECKTARGETSTACK :=
32cdf0e10cSrcweirgb_Module_CLEANTARGETSTACK :=
33cdf0e10cSrcweir
34cdf0e10cSrcweir.PHONY : $(call gb_Module_get_clean_target,%)
35cdf0e10cSrcweir$(call gb_Module_get_clean_target,%) :
36cdf0e10cSrcweir	$(call gb_Output_announce,$*,$(false),MOD,5)
37cdf0e10cSrcweir	$(call gb_Output_announce_title,module $* cleared.)
38cdf0e10cSrcweir	-$(call gb_Helper_abbreviate_dirs,\
39cdf0e10cSrcweir		rm -f $(call gb_Module_get_target,$*) $(call gb_Module_get_check_target,$*) $(call gb_Module_get_subsequentcheck_target,$*))
40cdf0e10cSrcweir
41cdf0e10cSrcweir$(call gb_Module_get_check_target,%) :
42cdf0e10cSrcweir	$(call gb_Output_announce,$*,$(true),CHK,5)
43cdf0e10cSrcweir	$(call gb_Output_announce_title,module $* checks done.)
44cdf0e10cSrcweir	-$(call gb_Helper_abbreviate_dirs,\
45cdf0e10cSrcweir		mkdir -p $(dir $@) && \
46cdf0e10cSrcweir		touch $@)
47cdf0e10cSrcweir
48cdf0e10cSrcweir$(call gb_Module_get_subsequentcheck_target,%) :
49cdf0e10cSrcweir	$(call gb_Output_announce,$*,$(true),SCK,5)
50cdf0e10cSrcweir	$(call gb_Output_announce_title,module $* subsequentchecks done.)
51cdf0e10cSrcweir	-$(call gb_Helper_abbreviate_dirs,\
52cdf0e10cSrcweir		mkdir -p $(dir $@) && \
53cdf0e10cSrcweir		touch $@)
54cdf0e10cSrcweir
55cdf0e10cSrcweir$(call gb_Module_get_target,%) :
56cdf0e10cSrcweir	$(call gb_Output_announce,$*,$(true),MOD,5)
57cdf0e10cSrcweir	$(call gb_Output_announce_title,module $* done.)
58cdf0e10cSrcweir	-$(call gb_Helper_abbreviate_dirs,\
59cdf0e10cSrcweir		mkdir -p $(dir $@) && \
60cdf0e10cSrcweir		touch $@)
61cdf0e10cSrcweir
62cdf0e10cSrcweir.PHONY : all allandcheck clean check subsequentcheck
63cdf0e10cSrcweir.DEFAULT_GOAL := allandcheck
64cdf0e10cSrcweir
65cdf0e10cSrcweirallandcheck : all check
66cdf0e10cSrcweir
67cdf0e10cSrcweir# compatibility with the old build system
68cdf0e10cSrcweirifneq ($(strip $(OOO_SUBSEQUENT_TESTS)),)
69cdf0e10cSrcweir.DEFAULT_GOAL := subsequentcheck
70cdf0e10cSrcweirendif
71cdf0e10cSrcweir
72cdf0e10cSrcweirall :
73cdf0e10cSrcweir	$(call gb_Output_announce,top level modules: $(foreach module,$(filter-out deliverlog,$^),$(notdir $(module))),$(true),ALL,6)
74cdf0e10cSrcweir	$(call gb_Output_announce,loaded modules: $(sort $(gb_Module_ALLMODULES)),$(true),ALL,6)
75cdf0e10cSrcweir	$(call gb_Output_announce_title,all done.)
76cdf0e10cSrcweir	$(call gb_Output_announce_bell)
77cdf0e10cSrcweir
78cdf0e10cSrcweircheck :
79cdf0e10cSrcweir	$(call gb_Output_announce,loaded modules: $(sort $(gb_Module_ALLMODULES)),$(true),CHK,6)
80cdf0e10cSrcweir	$(call gb_Output_announce_title,all tests checked.)
81cdf0e10cSrcweir	$(call gb_Output_announce_bell)
82cdf0e10cSrcweir
83cdf0e10cSrcweirsubsequentcheck : all
84cdf0e10cSrcweir	$(call gb_Output_announce,loaded modules: $(sort $(gb_Module_ALLMODULES)),$(true),SCK,6)
85cdf0e10cSrcweir	$(call gb_Output_announce_title,all subsequent tests checked.)
86cdf0e10cSrcweir	$(call gb_Output_announce_bell)
87cdf0e10cSrcweir
88cdf0e10cSrcweirclean :
89cdf0e10cSrcweir	$(call gb_Output_announce,top level modules: $(foreach module,$^,$(notdir $(module))),$(false),ALL,6)
90cdf0e10cSrcweir	$(call gb_Output_announce,loaded modules: $(sort $(gb_Module_ALLMODULES)),$(false),ALL,6)
91cdf0e10cSrcweir	$(call gb_Output_announce_title,all cleared.)
92cdf0e10cSrcweir	$(call gb_Output_announce_bell)
93cdf0e10cSrcweir
94cdf0e10cSrcweirdefine gb_Module_Module
95cdf0e10cSrcweirgb_Module_ALLMODULES += $(1)
96cdf0e10cSrcweirgb_Module_MODULELOCATIONS += $(1):$(dir $(realpath $(lastword $(MAKEFILE_LIST))))
97cdf0e10cSrcweirgb_Module_TARGETSTACK := $(call gb_Module_get_target,$(1)) $(gb_Module_TARGETSTACK)
98cdf0e10cSrcweirgb_Module_CHECKTARGETSTACK := $(call gb_Module_get_check_target,$(1)) $(gb_Module_CHECKTARGETSTACK)
99cdf0e10cSrcweirgb_Module_SUBSEQUENTCHECKTARGETSTACK := $(call gb_Module_get_subsequentcheck_target,$(1)) $(gb_Module_SUBSEQUENTCHECKTARGETSTACK)
100cdf0e10cSrcweirgb_Module_CLEANTARGETSTACK := $(call gb_Module_get_clean_target,$(1)) $(gb_Module_CLEANTARGETSTACK)
101cdf0e10cSrcweir
102cdf0e10cSrcweirendef
103cdf0e10cSrcweir
104cdf0e10cSrcweir# This is called inside the included file and pushes one target on each stack.
105cdf0e10cSrcweir# This has to be called with full late evaluation ($$(eval $$(call ))) and
106cdf0e10cSrcweir# should never be inlined ($(call )) as the calls defining it might be sourced
107cdf0e10cSrcweir# before gb_Module.
108cdf0e10cSrcweirdefine gb_Module_register_target
109cdf0e10cSrcweirgb_Module_CURRENTTARGET := $(1)
110cdf0e10cSrcweirgb_Module_CURRENTCLEANTARGET := $(2)
111cdf0e10cSrcweir
112cdf0e10cSrcweirendef
113cdf0e10cSrcweir
114cdf0e10cSrcweir# Here we include the file (in it there will be a call to gb_Module_register_target)
115cdf0e10cSrcweirdefine gb_Module__read_targetfile
116cdf0e10cSrcweirgb_Module_CURRENTTARGET :=
117cdf0e10cSrcweirgb_Module_CURRENTCLEANTARGET :=
118cdf0e10cSrcweirinclude $(patsubst $(1):%,%,$(filter $(1):%,$(gb_Module_MODULELOCATIONS)))$(2).mk
119cdf0e10cSrcweirifneq ($$(words $$(gb_Module_CURRENTTARGET)) $$(words $$(gb_Module_CURRENTCLEANTARGET)),1 1)
120cdf0e10cSrcweir$$(eval $$(call gb_Output_error,No $(3) registered while reading $(patsubst $(1):%,%,$(filter $(1):%,$(gb_Module_MODULELOCATIONS)))$(2).mk!))
121cdf0e10cSrcweirendif
122cdf0e10cSrcweir
123cdf0e10cSrcweirendef
124cdf0e10cSrcweir
125cdf0e10cSrcweirdefine gb_Module_add_target
126cdf0e10cSrcweir$(call gb_Module__read_targetfile,$(1),$(2),target)
127cdf0e10cSrcweir
128cdf0e10cSrcweir$(call gb_Module_get_target,$(1)) : $$(gb_Module_CURRENTTARGET)
129cdf0e10cSrcweir$(call gb_Module_get_clean_target,$(1)) : $$(gb_Module_CURRENTCLEANTARGET)
130cdf0e10cSrcweir
131cdf0e10cSrcweirendef
132cdf0e10cSrcweir
133cdf0e10cSrcweirdefine gb_Module_add_check_target
134cdf0e10cSrcweir$(call gb_Module__read_targetfile,$(1),$(2),check target)
135cdf0e10cSrcweir
136cdf0e10cSrcweir$(call gb_Module_get_check_target,$(1)) : $$(gb_Module_CURRENTTARGET)
137cdf0e10cSrcweir$(call gb_Module_get_clean_target,$(1)) : $$(gb_Module_CURRENTCLEANTARGET)
138cdf0e10cSrcweir
139cdf0e10cSrcweirendef
140cdf0e10cSrcweir
141cdf0e10cSrcweirdefine gb_Module_add_subsequentcheck_target
142cdf0e10cSrcweir$(call gb_Module__read_targetfile,$(1),$(2),subsequentcheck target)
143cdf0e10cSrcweir
144cdf0e10cSrcweir$(call gb_Module_get_subsequentcheck_target,$(1)) : $$(gb_Module_CURRENTTARGET)
145cdf0e10cSrcweir$(call gb_Module_get_clean_target,$(1)) : $$(gb_Module_CURRENTCLEANTARGET)
146cdf0e10cSrcweir
147cdf0e10cSrcweirendef
148cdf0e10cSrcweir
149cdf0e10cSrcweirdefine gb_Module_add_moduledir
150cdf0e10cSrcweirinclude $(patsubst $(1):%,%,$(filter $(1):%,$(gb_Module_MODULELOCATIONS)))/$(2)/Module_$(2).mk
151cdf0e10cSrcweir$(call gb_Module_get_target,$(1)) : $$(firstword $$(gb_Module_TARGETSTACK))
152cdf0e10cSrcweir$(call gb_Module_get_check_target,$(1)) : $$(firstword $$(gb_Module_CHECKTARGETSTACK))
153cdf0e10cSrcweir$(call gb_Module_get_subsequentcheck_target,$(1)) : $$(firstword $$(gb_Module_SUBSEQUENTCHECKTARGETSTACK))
154cdf0e10cSrcweir$(call gb_Module_get_clean_target,$(1)) : $$(firstword $$(gb_Module_CLEANTARGETSTACK))
155cdf0e10cSrcweirgb_Module_TARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_TARGETSTACK)),$$(gb_Module_TARGETSTACK))
156cdf0e10cSrcweirgb_Module_CHECKTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_CHECKTARGETSTACK)),$$(gb_Module_CHECKTARGETSTACK))
157cdf0e10cSrcweirgb_Module_SUBSEQUENTCHECKTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_SUBSEQUENTCHECKTARGETSTACK)),$$(gb_Module_SUBSEQUENTCHECKTARGETSTACK))
158cdf0e10cSrcweirgb_Module_CLEANTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_CLEANTARGETSTACK)),$$(gb_Module_CLEANTARGETSTACK))
159cdf0e10cSrcweir
160cdf0e10cSrcweirendef
161cdf0e10cSrcweir
162cdf0e10cSrcweirdefine gb_Module_add_targets
163cdf0e10cSrcweir$(foreach target,$(2),$(call gb_Module_add_target,$(1),$(target)))
164cdf0e10cSrcweir
165cdf0e10cSrcweirendef
166cdf0e10cSrcweir
167cdf0e10cSrcweirdefine gb_Module_add_check_targets
168cdf0e10cSrcweir$(foreach target,$(2),$(call gb_Module_add_check_target,$(1),$(target)))
169cdf0e10cSrcweir
170cdf0e10cSrcweirendef
171cdf0e10cSrcweir
172cdf0e10cSrcweirdefine gb_Module_add_subsequentcheck_targets
173cdf0e10cSrcweir$(foreach target,$(2),$(call gb_Module_add_subsequentcheck_target,$(1),$(target)))
174cdf0e10cSrcweir
175cdf0e10cSrcweirendef
176cdf0e10cSrcweir
177cdf0e10cSrcweirdefine gb_Module_add_moduledirs
178cdf0e10cSrcweir$(foreach target,$(2),$(call gb_Module_add_moduledir,$(1),$(target)))
179cdf0e10cSrcweirendef
180cdf0e10cSrcweir
181cdf0e10cSrcweirdefine gb_Module_make_global_targets
182cdf0e10cSrcweirifneq ($$(gb_Module_TARGETSTACK),)
183cdf0e10cSrcweir$$(eval $$(call gb_Output_error,Corrupted module target stack!1))
184cdf0e10cSrcweirendif
185cdf0e10cSrcweir
186cdf0e10cSrcweirinclude $(1)
187cdf0e10cSrcweir
188cdf0e10cSrcweirall : $$(firstword $$(gb_Module_TARGETSTACK))
189cdf0e10cSrcweircheck : $$(firstword $$(gb_Module_CHECKTARGETSTACK))
190cdf0e10cSrcweirsubsequentcheck : $$(firstword $$(gb_Module_SUBSEQUENTCHECKTARGETSTACK))
191cdf0e10cSrcweirclean : $$(firstword $$(gb_Module_CLEANTARGETSTACK))
192cdf0e10cSrcweir
193cdf0e10cSrcweirifneq ($$(words $$(gb_Module_TARGETSTACK)),1)
194cdf0e10cSrcweir$$(eval $$(call gb_Output_error,Corrupted module target stack! $(gb_Module_TARGETSTACK)))
195cdf0e10cSrcweirendif
196cdf0e10cSrcweir
197cdf0e10cSrcweirgb_Module_TARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_TARGETSTACK)),$$(gb_Module_TARGETSTACK))
198cdf0e10cSrcweirgb_Module_CHECKTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_CHECKTARGETSTACK)),$$(gb_Module_CHECKTARGETSTACK))
199cdf0e10cSrcweirgb_Module_SUBSEQUENTCHECKTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_SUBSEQUENTCHECKTARGETSTACK)),$$(gb_Module_SUBSEQUENTCHECKTARGETSTACK))
200cdf0e10cSrcweirgb_Module_CLEANTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_CLEANTARGETSTACK)),$$(gb_Module_CLEANTARGETSTACK))
201cdf0e10cSrcweir
202cdf0e10cSrcweirifneq ($$(and $$(gb_Module_TARGETSTACK),$$(gb_Module_CHECKTARGETSTACK),$$(gb_Module_SUBSEQUENTCHECKTARGETSTACK)),)
203cdf0e10cSrcweir$$(eval $$(call gb_Output_error,Corrupted module target stack!3))
204cdf0e10cSrcweirendif
205cdf0e10cSrcweir
206cdf0e10cSrcweirendef
207cdf0e10cSrcweir
208cdf0e10cSrcweir# vim: set noet sw=4 ts=4:
209