common/makefiles/Makefile

changeset 458
c8d320b48626
parent 445
efd26e051e50
child 478
2ba6f4da4bf3
equal deleted inserted replaced
455:633f2378c904 458:c8d320b48626
24 # 24 #
25 25
26 # This must be the first rule 26 # This must be the first rule
27 default: all 27 default: all
28 28
29 # Find out which variables were passed explicitely on the make command line. These 29 # Locate this Makefile
30 # will be passed on to sub-makes, overriding spec.gmk settings. 30 ifeq ($(filter /%,$(lastword $(MAKEFILE_LIST))),)
31 MAKE_ARGS=$(foreach var,$(subst =command,,$(filter %=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))),$(var)=$($(var))) 31 makefile_path:=$(CURDIR)/$(lastword $(MAKEFILE_LIST))
32 32 else
33 define fatal-error 33 makefile_path:=$(lastword $(MAKEFILE_LIST))
34 # If the user specificed a "global" target (e.g. 'help'), do not exit but continue running 34 endif
35 $$(if $$(findstring help,$$(MAKECMDGOALS)),,$$(error Cannot continue)) 35 root_dir:=$(patsubst %/common/makefiles/Makefile,%,$(makefile_path))
36 endef 36
37 37 # ... and then we can include our helper functions
38 ifeq ($(origin VERBOSE),undefined) 38 include $(dir $(makefile_path))/MakeHelpers.gmk
39 # Setup logging according to LOG (but only if VERBOSE is not given) 39
40 ifeq ($(LOG),) 40 $(eval $(call ParseLogLevel))
41 # Set LOG to "warn" as default if not set (and no VERBOSE given) 41 $(eval $(call SetupLogging))
42 LOG=warn 42 $(eval $(call ParseConfAndSpec))
43
44 # Setup number of jobs to use. -jN is unfortunately not available for us to parse from the command line,
45 # hence this workaround.
46 ifeq ($(JOBS),)
47 JOBS=$(NUM_CORES)
48 endif
49
50 ifneq ($(words $(SPEC)),1)
51 ### We have multiple configurations to build, call make repeatedly
52 all jdk hotspot jaxws jaxp corba langtools install images clean dist-clean:
53 @$(foreach spec,$(SPEC),($(MAKE) -f $(makefile_path) SPEC=$(spec) $(VERBOSE) VERBOSE=$(VERBOSE) $@ $(MAKE_ARGS)) &&) true
54
55 .PHONY: all jdk hotspot jaxws jaxp corba langtools install images clean dist-clean
56
57 else
58 ### This is the main part of the Makefile, for the normal case with SPEC specifying a single existing spec.gmk file.
59
60 # Now load the spec
61 include $(SPEC)
62
63 # Load the vital tools for all the makefiles.
64 include $(SRC_ROOT)/common/makefiles/MakeBase.gmk
65
66 ### Clean up from previous run
67
68 # Remove any build.log from a previous run, if they exist
69 ifneq (,$(BUILD_LOG))
70 ifneq (,$(BUILD_LOG_PREVIOUS))
71 # Rotate old log
72 $(shell $(RM) $(BUILD_LOG_PREVIOUS) 2> /dev/null)
73 $(shell $(MV) $(BUILD_LOG) $(BUILD_LOG_PREVIOUS) 2> /dev/null)
74 else
75 $(shell $(RM) $(BUILD_LOG) 2> /dev/null)
43 endif 76 endif
44 ifeq ($(LOG),warn) 77 endif
45 VERBOSE=-s
46 else ifeq ($(LOG),info)
47 VERBOSE=
48 else ifeq ($(LOG),debug)
49 VERBOSE=
50 else ifeq ($(LOG),trace)
51 VERBOSE=-d -p
52 else
53 $(info Error: LOG must be one of: warn, info, debug or trace.)
54 $(eval $(call fatal-error))
55 endif
56 else
57 ifneq ($(LOG),)
58 # We have both a VERBOSE and a LOG argument. This is OK only if this is a repeated call by ourselves,
59 # but complain if this is the top-level make call.
60 ifeq ($(MAKELEVEL),0)
61 $(info Cannot use LOG=$(LOG) and VERBOSE=$(VERBOSE) at the same time. Choose one.)
62 $(eval $(call fatal-error))
63 endif
64 endif
65 endif
66
67 # TODO: Fix duplication in MakeBase.gmk
68 define SetupLogging
69 ifneq ($(findstring $(LOG),debug trace),)
70 # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
71 OLD_SHELL:=$$(SHELL)
72 SHELL = $$(warning Building $$@$$(if $$<, (from $$<))$(if $$?, ($$? newer)))$$(OLD_SHELL) -x
73 endif
74 endef
75
76 $(eval $(call SetupLogging))
77
78 # Find all environment or command line variables that begin with ALT.
79 list_alt_overrides_with_origins = $(filter ALT_%=environment ALT_%=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))
80 list_alt_overrides=$(subst =command,,$(subst =environment,,$(list_alt_overrides_with_origins)))
81
82 ifeq ($(filter /%,$(lastword $(MAKEFILE_LIST))),)
83 makefile_path=$(CURDIR)/$(lastword $(MAKEFILE_LIST))
84 else
85 makefile_path=$(lastword $(MAKEFILE_LIST))
86 endif
87 root_dir=$(patsubst %/common/makefiles/Makefile,%,$(makefile_path))
88 output_dir=$(root_dir)/build
89
90 ifneq ($(origin SPEC),undefined)
91 # We have been given a SPEC, check that it works out properly
92 ifeq ($(wildcard $(SPEC)),)
93 $(info Cannot locate spec.gmk, given by SPEC=$(SPEC))
94 $(eval $(call fatal-error))
95 endif
96 ifneq ($(origin CONF),undefined)
97 # We also have a CONF argument. This is OK only if this is a repeated call by ourselves,
98 # but complain if this is the top-level make call.
99 ifeq ($(MAKELEVEL),0)
100 $(info Cannot use CONF=$(CONF) and SPEC=$(SPEC) at the same time. Choose one.)
101 $(eval $(call fatal-error))
102 endif
103 endif
104 # ... OK, we're satisfied, we'll use this SPEC later on
105 else
106 # Find all spec.gmk files in the build output directory
107 all_spec_files=$(wildcard $(output_dir)/*/spec.gmk)
108 ifeq ($(all_spec_files),)
109 $(info No configurations found for $(root_dir)! Please run configure to create a configuration.)
110 $(eval $(call fatal-error))
111 endif
112 # Extract the configuration names from the path
113 all_confs=$(patsubst %/spec.gmk,%,$(patsubst $(output_dir)/%,%,$(all_spec_files)))
114
115 ifneq ($(origin CONF),undefined)
116 # User have given a CONF= argument.
117 ifeq ($(CONF),)
118 # If given CONF=, match all configurations
119 matching_confs=$(strip $(all_confs))
120 else
121 # Otherwise select those that contain the given CONF string
122 matching_confs=$(strip $(foreach var,$(all_confs),$(if $(findstring $(CONF),$(var)),$(var))))
123 endif
124 ifeq ($(matching_confs),)
125 $(info No configurations found matching CONF=$(CONF))
126 $(info Available configurations:)
127 $(foreach var,$(all_confs),$(info * $(var)))
128 $(eval $(call fatal-error))
129 else
130 ifeq ($(words $(matching_confs)),1)
131 $(info Building '$(matching_confs)' (matching CONF=$(CONF)))
132 else
133 $(info Building the following configurations (matching CONF=$(CONF)):)
134 $(foreach var,$(matching_confs),$(info * $(var)))
135 endif
136 endif
137
138 # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
139 SPEC=$(addsuffix /spec.gmk,$(addprefix $(output_dir)/,$(matching_confs)))
140 else
141 # No CONF or SPEC given, check the available configurations
142 ifneq ($(words $(all_spec_files)),1)
143 $(info No CONF or SPEC given, but more than one spec.gmk found in $(output_dir).)
144 $(info Available configurations:)
145 $(foreach var,$(all_confs),$(info * $(var)))
146 $(info Please retry building with CONF=<config> or SPEC=<specfile>)
147 $(eval $(call fatal-error))
148 endif
149
150 # We found exactly one configuration, use it
151 SPEC=$(strip $(all_spec_files))
152 endif
153 endif
154
155 ifneq ($(words $(SPEC)),1)
156 # We have multiple configurations to build, call make repeatedly
157 all jdk hotspot jaxws jaxp corba langtools install images packages clean dist-clean:
158 @$(foreach spec,$(SPEC),($(MAKE) -f $(makefile_path) SPEC=$(spec) $(VERBOSE) VERBOSE=$(VERBOSE) $@ $(MAKE_ARGS)) &&) true
159
160 .PHONY: all jdk hotspot jaxws jaxp corba langtools install images packages clean dist-clean
161
162 else
163 # This is the main part of the Makefile, for the normal case with SPEC specifying a single existing spec.gmk file.
164
165 # Now load the spec
166 -include $(SPEC)
167
168 # Load the vital tools for all the makefiles.
169 -include $(SRC_ROOT)/common/makefiles/MakeBase.gmk
170
171 # Remove any build.log from a previous run
172 ifneq (,$(BUILD_LOG))
173 $(shell $(RM) $(BUILD_LOG))
174 endif
175
176 # Remove any javac server logs and port files. This 78 # Remove any javac server logs and port files. This
177 # prevents a new make run to reuse the previous servers. 79 # prevents a new make run to reuse the previous servers.
178 ifneq (,$(JAVAC_SERVERS)) 80 ifneq (,$(JAVAC_SERVERS))
179 $(shell mkdir -p $(JAVAC_SERVERS) && rm -rf $(JAVAC_SERVERS)/*) 81 $(shell mkdir -p $(JAVAC_SERVERS) && rm -rf $(JAVAC_SERVERS)/*)
180 endif 82 endif
83 # Clean out any notifications from the previous build.
84 $(shell find $(OUTPUT_ROOT) -name "_the.*.notify" $(FIND_DELETE))
85
181 # Reset the build timers. 86 # Reset the build timers.
182 $(eval $(call ResetTimers)) 87 $(eval $(call ResetTimers))
183 # Clean out any notifications from the previous build. 88
184 $(shell find $(OUTPUT_ROOT) -name "_the.*.notify" $(FIND_DELETE)) 89 ### Main targets
185
186 # If make was called explicitely with -j, don't add a -j ourself to sub-makes, since
187 # this will be inherited automatically by make. Otherwise use our default for sub-makes.
188 # The -j in MAKEFLAGS is only visible when executing a recipe, hence this macro.
189 define GetMakeJobFlag
190 $(if $(findstring -j,$(MAKEFLAGS)),,-j$(NUM_CORES))
191 endef
192
193 define CheckEnvironment
194 $(if $(list_alt_overrides),
195 @$(PRINTF) "\nWARNING: You have the following ALT_ variables set:\n"
196 @$(PRINTF) "$(foreach var,$(list_alt_overrides),$(var)=$$$(var))\n"
197 @$(PRINTF) "ALT_ variables are deprecated and will be ignored. Please clean your environment.\n"
198 )
199 endef
200
201 define PrintStartMessage
202 $(if $(VERBOSE),,@$(ECHO) Running make as $(MAKE) $(MFLAGS) $(MAKE_ARGS))
203 $(call CheckEnvironment)
204 @$(ECHO) "Building OpenJDK for target $(if $(MAKECMDGOALS),'$(MAKECMDGOALS)','all') in configuration '$(CONF_NAME)'"
205 endef
206
207 define PrintEndMessage
208 @$(ECHO) "Finished building OpenJDK for target '$@'"
209 $(call CheckEnvironment)
210 endef
211 90
212 all: jdk 91 all: jdk
213 @$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port) 92 @$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
214 @$(call AtRootMakeEnd) 93 @$(call AtRootMakeEnd)
215 94
216 langtools: start-make 95 langtools: start-make langtools-only
96 langtools-only:
217 @$(call MakeStart,langtools,all) 97 @$(call MakeStart,langtools,all)
218 @($(CD) $(LANGTOOLS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(LANGTOOLS_MAKE_ARGS) $(MAKE_ARGS)) 98 @($(CD) $(LANGTOOLS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
219 @$(call MakeFinish,langtools,all) 99 @$(call MakeFinish,langtools,all)
220 100
221 corba: langtools 101 corba: langtools corba-only
102 corba-only:
222 @$(call MakeStart,corba,all) 103 @$(call MakeStart,corba,all)
223 @($(CD) $(CORBA_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS)) 104 @($(CD) $(CORBA_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
224 @$(call MakeFinish,corba,all) 105 @$(call MakeFinish,corba,all)
225 106
226 jaxp: langtools 107 jaxp: langtools jaxp-only
108 jaxp-only:
227 @$(call MakeStart,jaxp,all) 109 @$(call MakeStart,jaxp,all)
228 @($(CD) $(JAXP_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS)) 110 @($(CD) $(JAXP_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
229 @$(call MakeFinish,jaxp,all) 111 @$(call MakeFinish,jaxp,all)
230 112
231 jaxws: langtools jaxp 113 jaxws: langtools jaxp jaxws-only
114 jaxws-only:
232 @$(call MakeStart,jaxws,all) 115 @$(call MakeStart,jaxws,all)
233 @($(CD) $(JAXWS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(CORBA_MAKE_ARGS) $(MAKE_ARGS)) 116 @($(CD) $(JAXWS_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
234 @$(call MakeFinish,jaxws,all) 117 @$(call MakeFinish,jaxws,all)
235 118
236 hotspot: langtools 119 hotspot: langtools hotspot-only
120 hotspot-only:
237 @$(call MakeStart,hotspot,all) 121 @$(call MakeStart,hotspot,all)
238 @($(CD) $(HOTSPOT_TOPDIR)/make && $(BUILD_LOG_WRAPPER) $(MAKE) -j1 $(HOTSPOT_MAKE_ARGS) $(MAKE_ARGS)) 122 @($(CD) $(HOTSPOT_TOPDIR)/make && $(BUILD_LOG_WRAPPER) $(MAKE) -j1 $(HOTSPOT_MAKE_ARGS) $(MAKE_ARGS))
239 @$(call MakeFinish,hotspot,all) 123 @$(call MakeFinish,hotspot,all)
240 124
241 jdk: langtools corba jaxp jaxws hotspot 125 jdk: langtools corba jaxp jaxws hotspot jdk-only
126 jdk-only:
242 @$(call MakeStart,jdk,all) 127 @$(call MakeStart,jdk,all)
243 @($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS)) 128 @($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(MAKE_ARGS))
244 @$(call MakeFinish,jdk,all) 129 @$(call MakeFinish,jdk,all)
245 130
246 images install packages: source-tips start-make jdk langtools corba jaxp jaxws hotspot 131 images: source-tips start-make jdk langtools corba jaxp jaxws hotspot images-only
132 images-only:
247 @$(call MakeStart,jdk-images,$@) 133 @$(call MakeStart,jdk-images,$@)
248 @($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS) $@) 134 @($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(JDK_MAKE_ARGS) $(MAKE_ARGS) images)
249 @$(call MakeFinish,jdk-images,$@) 135 @$(call MakeFinish,jdk-images,$@)
250 @$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port) 136 @$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
251 @$(call AtRootMakeEnd) 137 @$(call AtRootMakeEnd)
252 138
253 old-images: source-tips start-make jdk langtools corba jaxp jaxws hotspot 139 install: source-tips start-make jdk langtools corba jaxp jaxws hotspot install-only
254 @$(call MakeStart,jdk-old-images,$@) 140 install-only:
255 @($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) $(call GetMakeJobFlag) $(JDK_MAKE_ARGS) $(MAKE_ARGS) $@) 141 @$(call MakeStart,jdk-images,$@)
256 @$(call MakeFinish,old-jdk-images,$@) 142 @($(CD) $(JDK_TOPDIR)/makefiles && $(BUILD_LOG_WRAPPER) $(MAKE) -j$(JOBS) $(JDK_MAKE_ARGS) $(MAKE_ARGS) install)
143 @$(call MakeFinish,jdk-images,$@)
257 @$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port) 144 @$(if $(JAVAC_SERVERS),rm -rf $(JAVAC_SERVERS)/*.port)
258 @$(call AtRootMakeEnd) 145 @$(call AtRootMakeEnd)
259 146
260 start-make: 147 start-make:
261 @$(call AtRootMakeStart) 148 @$(call AtRootMakeStart)
262 149
263 .PHONY: jdk hotspot jaxws jaxp corba langtools install images packages start-make 150 .PHONY: jdk hotspot jaxws jaxp corba langtools install images start-make
264 151
265 test: start-make 152 test: start-make
266 @$(call MakeStart,test,$(if $(TEST),$(TEST),all)) 153 @$(call MakeStart,test,$(if $(TEST),$(TEST),all))
267 @($(CD) $(SRC_ROOT)/test && $(BUILD_LOG_WRAPPER) $(MAKE) MAKEFLAGS= -j1 PRODUCT_HOME=$(OUTPUT_ROOT)/jdk JPRT_JAVA_HOME=$(OUTPUT_ROOT)/jdk ALT_OUTPUTDIR=$(OUTPUT_ROOT) $(TEST)) || true 154 @($(CD) $(SRC_ROOT)/test && $(BUILD_LOG_WRAPPER) $(MAKE) MAKEFLAGS= -j1 PRODUCT_HOME=$(OUTPUT_ROOT)/jdk JPRT_JAVA_HOME=$(OUTPUT_ROOT)/jdk ALT_OUTPUTDIR=$(OUTPUT_ROOT) $(TEST)) || true
268 @$(call MakeFinish,test,$(if $(TEST),$(TEST),all)) 155 @$(call MakeFinish,test,$(if $(TEST),$(TEST),all))
279 @$(call GetSourceTips) 166 @$(call GetSourceTips)
280 167
281 168
282 # Remove everything, except the output from configure. 169 # Remove everything, except the output from configure.
283 clean: 170 clean:
284 @(cd $(OUTPUT_ROOT) && $(RM) -r `$(LS) $(OUTPUT_ROOT) | grep -v spec.gmk | grep -v Makefile | grep -v config.status | grep -v config.log | grep -v config.h | grep -v configure-arguments | grep -v "localdevenv.*" | grep -v uncygdrive.exe`) 171 @(cd $(OUTPUT_ROOT) && $(RM) -r `$(LS) $(OUTPUT_ROOT) | grep -v spec.gmk | grep -v spec.sh | grep -v Makefile | grep -v config.status | grep -v config.log | grep -v config.h | grep -v configure-arguments | grep -v "localdevenv.*" | grep -v uncygdrive.exe`)
285 @$(ECHO) Cleaned everything except the build configuration. 172 @$(ECHO) Cleaned everything except the build configuration.
286 .PHONY: clean 173 .PHONY: clean
287 174
288 # Remove everything, you have to rerun configure. 175 # Remove everything, you have to rerun configure.
289 dist-clean: 176 dist-clean:
290 @$(RM) -r $(OUTPUT_ROOT) 177 @$(RM) -r $(OUTPUT_ROOT)
291 @$(ECHO) Cleaned everything, you will have to re-run configure. 178 @$(ECHO) Cleaned everything, you will have to re-run configure.
292 .PHONY: dist-clean 179 .PHONY: dist-clean
293 180
294 clean-jdk: 181 clean-jdk:
295 @(cd $(OUTPUT_ROOT) && $(RM) -r `$(LS) $(OUTPUT_ROOT) | grep -v spec.gmk | grep -v Makefile | grep -v config.status | grep -v config.log | grep -v config.h | grep -v configure-arguments | \ 182 @(cd $(OUTPUT_ROOT) && $(RM) -r `$(LS) $(OUTPUT_ROOT) | grep -v spec.gmk | grep -v spec.sh | grep -v Makefile | grep -v config.status | grep -v config.log | grep -v config.h | grep -v configure-arguments | \
296 grep -v langtools | grep -v corba | grep -v jaxp | grep -v jaxws | grep -v hotspot`) 183 grep -v langtools | grep -v corba | grep -v jaxp | grep -v jaxws | grep -v hotspot`)
297 @$(ECHO) "Cleaned jdk build artifacts (but not langtools,corba,jaxp,jaxws,hotspot nor the build configuration)" 184 @$(ECHO) "Cleaned jdk build artifacts (but not langtools,corba,jaxp,jaxws,hotspot nor the build configuration)"
298 .PHONY: clean 185 .PHONY: clean
299 186
300 endif 187 endif

mercurial