xref: /aoo41x/main/solenv/gbuild/Module.mk (revision cdf0e10c)
1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2011 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27
28
29# Module class
30
31gb_Module_ALLMODULES :=
32gb_Module_MODULELOCATIONS :=
33gb_Module_TARGETSTACK :=
34gb_Module_CHECKTARGETSTACK :=
35gb_Module_SUBSEQUENTCHECKTARGETSTACK :=
36gb_Module_CLEANTARGETSTACK :=
37
38.PHONY : $(call gb_Module_get_clean_target,%)
39$(call gb_Module_get_clean_target,%) :
40	$(call gb_Output_announce,$*,$(false),MOD,5)
41	$(call gb_Output_announce_title,module $* cleared.)
42	-$(call gb_Helper_abbreviate_dirs,\
43		rm -f $(call gb_Module_get_target,$*) $(call gb_Module_get_check_target,$*) $(call gb_Module_get_subsequentcheck_target,$*))
44
45$(call gb_Module_get_check_target,%) :
46	$(call gb_Output_announce,$*,$(true),CHK,5)
47	$(call gb_Output_announce_title,module $* checks done.)
48	-$(call gb_Helper_abbreviate_dirs,\
49		mkdir -p $(dir $@) && \
50		touch $@)
51
52$(call gb_Module_get_subsequentcheck_target,%) :
53	$(call gb_Output_announce,$*,$(true),SCK,5)
54	$(call gb_Output_announce_title,module $* subsequentchecks done.)
55	-$(call gb_Helper_abbreviate_dirs,\
56		mkdir -p $(dir $@) && \
57		touch $@)
58
59$(call gb_Module_get_target,%) :
60	$(call gb_Output_announce,$*,$(true),MOD,5)
61	$(call gb_Output_announce_title,module $* done.)
62	-$(call gb_Helper_abbreviate_dirs,\
63		mkdir -p $(dir $@) && \
64		touch $@)
65
66.PHONY : all allandcheck clean check subsequentcheck
67.DEFAULT_GOAL := allandcheck
68
69allandcheck : all check
70
71# compatibility with the old build system
72ifneq ($(strip $(OOO_SUBSEQUENT_TESTS)),)
73.DEFAULT_GOAL := subsequentcheck
74endif
75
76all :
77	$(call gb_Output_announce,top level modules: $(foreach module,$(filter-out deliverlog,$^),$(notdir $(module))),$(true),ALL,6)
78	$(call gb_Output_announce,loaded modules: $(sort $(gb_Module_ALLMODULES)),$(true),ALL,6)
79	$(call gb_Output_announce_title,all done.)
80	$(call gb_Output_announce_bell)
81
82check :
83	$(call gb_Output_announce,loaded modules: $(sort $(gb_Module_ALLMODULES)),$(true),CHK,6)
84	$(call gb_Output_announce_title,all tests checked.)
85	$(call gb_Output_announce_bell)
86
87subsequentcheck : all
88	$(call gb_Output_announce,loaded modules: $(sort $(gb_Module_ALLMODULES)),$(true),SCK,6)
89	$(call gb_Output_announce_title,all subsequent tests checked.)
90	$(call gb_Output_announce_bell)
91
92clean :
93	$(call gb_Output_announce,top level modules: $(foreach module,$^,$(notdir $(module))),$(false),ALL,6)
94	$(call gb_Output_announce,loaded modules: $(sort $(gb_Module_ALLMODULES)),$(false),ALL,6)
95	$(call gb_Output_announce_title,all cleared.)
96	$(call gb_Output_announce_bell)
97
98define gb_Module_Module
99gb_Module_ALLMODULES += $(1)
100gb_Module_MODULELOCATIONS += $(1):$(dir $(realpath $(lastword $(MAKEFILE_LIST))))
101gb_Module_TARGETSTACK := $(call gb_Module_get_target,$(1)) $(gb_Module_TARGETSTACK)
102gb_Module_CHECKTARGETSTACK := $(call gb_Module_get_check_target,$(1)) $(gb_Module_CHECKTARGETSTACK)
103gb_Module_SUBSEQUENTCHECKTARGETSTACK := $(call gb_Module_get_subsequentcheck_target,$(1)) $(gb_Module_SUBSEQUENTCHECKTARGETSTACK)
104gb_Module_CLEANTARGETSTACK := $(call gb_Module_get_clean_target,$(1)) $(gb_Module_CLEANTARGETSTACK)
105
106endef
107
108# This is called inside the included file and pushes one target on each stack.
109# This has to be called with full late evaluation ($$(eval $$(call ))) and
110# should never be inlined ($(call )) as the calls defining it might be sourced
111# before gb_Module.
112define gb_Module_register_target
113gb_Module_CURRENTTARGET := $(1)
114gb_Module_CURRENTCLEANTARGET := $(2)
115
116endef
117
118# Here we include the file (in it there will be a call to gb_Module_register_target)
119define gb_Module__read_targetfile
120gb_Module_CURRENTTARGET :=
121gb_Module_CURRENTCLEANTARGET :=
122include $(patsubst $(1):%,%,$(filter $(1):%,$(gb_Module_MODULELOCATIONS)))$(2).mk
123ifneq ($$(words $$(gb_Module_CURRENTTARGET)) $$(words $$(gb_Module_CURRENTCLEANTARGET)),1 1)
124$$(eval $$(call gb_Output_error,No $(3) registered while reading $(patsubst $(1):%,%,$(filter $(1):%,$(gb_Module_MODULELOCATIONS)))$(2).mk!))
125endif
126
127endef
128
129define gb_Module_add_target
130$(call gb_Module__read_targetfile,$(1),$(2),target)
131
132$(call gb_Module_get_target,$(1)) : $$(gb_Module_CURRENTTARGET)
133$(call gb_Module_get_clean_target,$(1)) : $$(gb_Module_CURRENTCLEANTARGET)
134
135endef
136
137define gb_Module_add_check_target
138$(call gb_Module__read_targetfile,$(1),$(2),check target)
139
140$(call gb_Module_get_check_target,$(1)) : $$(gb_Module_CURRENTTARGET)
141$(call gb_Module_get_clean_target,$(1)) : $$(gb_Module_CURRENTCLEANTARGET)
142
143endef
144
145define gb_Module_add_subsequentcheck_target
146$(call gb_Module__read_targetfile,$(1),$(2),subsequentcheck target)
147
148$(call gb_Module_get_subsequentcheck_target,$(1)) : $$(gb_Module_CURRENTTARGET)
149$(call gb_Module_get_clean_target,$(1)) : $$(gb_Module_CURRENTCLEANTARGET)
150
151endef
152
153define gb_Module_add_moduledir
154include $(patsubst $(1):%,%,$(filter $(1):%,$(gb_Module_MODULELOCATIONS)))/$(2)/Module_$(2).mk
155$(call gb_Module_get_target,$(1)) : $$(firstword $$(gb_Module_TARGETSTACK))
156$(call gb_Module_get_check_target,$(1)) : $$(firstword $$(gb_Module_CHECKTARGETSTACK))
157$(call gb_Module_get_subsequentcheck_target,$(1)) : $$(firstword $$(gb_Module_SUBSEQUENTCHECKTARGETSTACK))
158$(call gb_Module_get_clean_target,$(1)) : $$(firstword $$(gb_Module_CLEANTARGETSTACK))
159gb_Module_TARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_TARGETSTACK)),$$(gb_Module_TARGETSTACK))
160gb_Module_CHECKTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_CHECKTARGETSTACK)),$$(gb_Module_CHECKTARGETSTACK))
161gb_Module_SUBSEQUENTCHECKTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_SUBSEQUENTCHECKTARGETSTACK)),$$(gb_Module_SUBSEQUENTCHECKTARGETSTACK))
162gb_Module_CLEANTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_CLEANTARGETSTACK)),$$(gb_Module_CLEANTARGETSTACK))
163
164endef
165
166define gb_Module_add_targets
167$(foreach target,$(2),$(call gb_Module_add_target,$(1),$(target)))
168
169endef
170
171define gb_Module_add_check_targets
172$(foreach target,$(2),$(call gb_Module_add_check_target,$(1),$(target)))
173
174endef
175
176define gb_Module_add_subsequentcheck_targets
177$(foreach target,$(2),$(call gb_Module_add_subsequentcheck_target,$(1),$(target)))
178
179endef
180
181define gb_Module_add_moduledirs
182$(foreach target,$(2),$(call gb_Module_add_moduledir,$(1),$(target)))
183endef
184
185define gb_Module_make_global_targets
186ifneq ($$(gb_Module_TARGETSTACK),)
187$$(eval $$(call gb_Output_error,Corrupted module target stack!1))
188endif
189
190include $(1)
191
192all : $$(firstword $$(gb_Module_TARGETSTACK))
193check : $$(firstword $$(gb_Module_CHECKTARGETSTACK))
194subsequentcheck : $$(firstword $$(gb_Module_SUBSEQUENTCHECKTARGETSTACK))
195clean : $$(firstword $$(gb_Module_CLEANTARGETSTACK))
196
197ifneq ($$(words $$(gb_Module_TARGETSTACK)),1)
198$$(eval $$(call gb_Output_error,Corrupted module target stack! $(gb_Module_TARGETSTACK)))
199endif
200
201gb_Module_TARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_TARGETSTACK)),$$(gb_Module_TARGETSTACK))
202gb_Module_CHECKTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_CHECKTARGETSTACK)),$$(gb_Module_CHECKTARGETSTACK))
203gb_Module_SUBSEQUENTCHECKTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_SUBSEQUENTCHECKTARGETSTACK)),$$(gb_Module_SUBSEQUENTCHECKTARGETSTACK))
204gb_Module_CLEANTARGETSTACK := $$(wordlist 2,$$(words $$(gb_Module_CLEANTARGETSTACK)),$$(gb_Module_CLEANTARGETSTACK))
205
206ifneq ($$(and $$(gb_Module_TARGETSTACK),$$(gb_Module_CHECKTARGETSTACK),$$(gb_Module_SUBSEQUENTCHECKTARGETSTACK)),)
207$$(eval $$(call gb_Output_error,Corrupted module target stack!3))
208endif
209
210endef
211
212# vim: set noet sw=4 ts=4:
213