2
# Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
# This code is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 2 only, as
7
# published by the Free Software Foundation. Oracle designates this
8
# particular file as subject to the "Classpath" exception as provided
9
# by Oracle in the LICENSE file that accompanied this code.
11
# This code is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
# version 2 for more details (a copy is included in the LICENSE file that
15
# accompanied this code).
17
# You should have received a copy of the GNU General Public License version
18
# 2 along with this work; if not, write to the Free Software Foundation,
19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
# or visit www.oracle.com if you need additional information or have any
26
################################################################################
27
# This is the bootstrapping part of the build. This file is included from the
28
# top level Makefile, and is responsible for launching the Main.gmk file with
29
# the proper make and the proper make arguments.
30
################################################################################
32
# This must be the first rule
36
# Inclusion of this pseudo-target will cause make to execute this file
37
# serially, regardless of -j.
41
##############################################################################
42
# This is the default mode. We have not been recursively called with a SPEC.
43
##############################################################################
45
# Include our helper functions.
46
include $(topdir)/make/InitSupport.gmk
48
# Here are "global" targets, i.e. targets that can be executed without having
49
# a configuration. This will define ALL_GLOBAL_TARGETS.
50
include $(topdir)/make/Global.gmk
52
# Targets provided by Init.gmk.
53
ALL_INIT_TARGETS := print-modules print-targets print-configuration \
54
print-tests reconfigure pre-compare-build post-compare-build
56
# CALLED_TARGETS is the list of targets that the user provided,
57
# or "default" if unspecified.
58
CALLED_TARGETS := $(if $(MAKECMDGOALS), $(MAKECMDGOALS), default)
60
# Extract non-global targets that require a spec file.
61
CALLED_SPEC_TARGETS := $(filter-out $(ALL_GLOBAL_TARGETS), $(CALLED_TARGETS))
63
# If we have only global targets, or if we are called with -qp (assuming an
64
# external part, e.g. bash completion, is trying to understand our targets),
65
# we will skip SPEC location and the sanity checks.
66
ifeq ($(CALLED_SPEC_TARGETS), )
67
ONLY_GLOBAL_TARGETS := true
69
ifeq ($(findstring p, $(MAKEFLAGS))$(findstring q, $(MAKEFLAGS)), pq)
70
ONLY_GLOBAL_TARGETS := true
73
ifeq ($(ONLY_GLOBAL_TARGETS), true)
74
############################################################################
75
# We have only global targets, or are called with -pq.
76
############################################################################
78
ifeq ($(wildcard $(SPEC)), )
79
# If we have no SPEC provided, we will just make a "best effort" target list.
80
# First try to grab any available pre-existing main-targets.gmk.
81
main_targets_file := $(firstword $(wildcard $(build_dir)/*/make-support/main-targets.gmk))
82
ifneq ($(main_targets_file), )
83
# Extract the SPEC that corresponds to this main-targets.gmk file.
84
SPEC := $(patsubst %/make-support/main-targets.gmk, %/spec.gmk, $(main_targets_file))
86
# None found, pick an arbitrary SPEC for which to generate a file
87
SPEC := $(firstword $(all_spec_files))
91
ifneq ($(wildcard $(SPEC)), )
92
$(eval $(call DefineMainTargets, LAZY, $(SPEC)))
94
# If we have no configurations we can not provide any main targets.
98
ALL_TARGETS := $(sort $(ALL_GLOBAL_TARGETS) $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS))
100
# Just list all our targets.
103
.PHONY: $(ALL_TARGETS)
106
############################################################################
107
# This is the normal case, we have been called from the command line by the
108
# user and we need to call ourself back with a proper SPEC.
109
# We have at least one non-global target, so we need to find a spec file.
110
############################################################################
112
# Basic checks on environment and command line.
113
$(eval $(call CheckControlVariables))
114
$(eval $(call CheckDeprecatedEnvironment))
115
$(eval $(call CheckInvalidMakeFlags))
117
# Check that CONF_CHECK is valid.
118
$(eval $(call ParseConfCheckOption))
120
# Check that the LOG given is valid, and set LOG_LEVEL, LOG_NOFILE, MAKE_LOG_VARS and MAKE_LOG_FLAGS.
121
$(eval $(call ParseLogLevel))
123
# After this SPECS contain 1..N spec files (otherwise ParseConfAndSpec fails).
124
$(eval $(call ParseConfAndSpec))
126
# Extract main targets from Main.gmk using the spec(s) provided. In theory,
127
# with multiple specs, we should find the intersection of targets provided
128
# by all specs, but we approximate this by an arbitrary spec from the list.
129
# This will setup ALL_MAIN_TARGETS.
130
$(eval $(call DefineMainTargets, FORCE, $(firstword $(SPECS))))
132
# Separate called targets depending on type.
133
INIT_TARGETS := $(filter $(ALL_INIT_TARGETS), $(CALLED_SPEC_TARGETS))
134
MAIN_TARGETS := $(filter $(ALL_MAIN_TARGETS), $(CALLED_SPEC_TARGETS))
135
SEQUENTIAL_TARGETS := $(filter dist-clean clean%, $(MAIN_TARGETS))
136
PARALLEL_TARGETS := $(filter-out $(SEQUENTIAL_TARGETS), $(MAIN_TARGETS))
138
# The spec files depend on the autoconf source code. This check makes sure
139
# the configuration is up to date after changes to configure.
140
$(SPECS): $(wildcard $(topdir)/make/autoconf/*) \
141
$(if $(CUSTOM_CONFIG_DIR), $(wildcard $(CUSTOM_CONFIG_DIR)/*)) \
142
$(addprefix $(topdir)/make/conf/, version-numbers.conf branding.conf) \
143
$(if $(CUSTOM_CONF_DIR), $(wildcard $(addprefix $(CUSTOM_CONF_DIR)/, \
144
version-numbers.conf branding.conf)))
145
ifeq ($(CONF_CHECK), fail)
146
@echo Error: The configuration is not up to date for \
147
"'$(lastword $(subst /, , $(dir $@)))'."
148
$(call PrintConfCheckFailed)
150
else ifeq ($(CONF_CHECK), auto)
151
@echo Note: The configuration is not up to date for \
152
"'$(lastword $(subst /, , $(dir $@)))'."
154
$(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \
155
SPEC=$@ HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \
157
else ifeq ($(CONF_CHECK), ignore)
161
# Do not let make delete spec files even if aborted while doing a reconfigure
164
# Unless reconfigure is explicitly called, let all main targets depend on
165
# the spec files to be up to date.
166
ifeq ($(findstring reconfigure, $(INIT_TARGETS)), )
167
$(MAIN_TARGETS): $(SPECS)
171
ifneq ($(findstring $(LOG_LEVEL),info debug trace),)
172
$(info Running make as '$(strip $(MAKE) $(MFLAGS) \
173
$(COMMAND_LINE_VARIABLES) $(MAKECMDGOALS))')
176
MAKE_INIT_WITH_SPEC_ARGUMENTS := ACTUAL_TOPDIR=$(topdir) \
177
USER_MAKE_VARS="$(USER_MAKE_VARS)" MAKE_LOG_FLAGS=$(MAKE_LOG_FLAGS) \
179
INIT_TARGETS="$(INIT_TARGETS)" \
180
SEQUENTIAL_TARGETS="$(SEQUENTIAL_TARGETS)" \
181
PARALLEL_TARGETS="$(PARALLEL_TARGETS)"
183
# Now the init and main targets will be called, once for each SPEC. The
184
# recipe will be run once for every target specified, but we only want to
185
# execute the recipe a single time, hence the TARGET_DONE with a dummy
187
# The COMPARE_BUILD part implements special support for makefile development.
188
$(ALL_INIT_TARGETS) $(ALL_MAIN_TARGETS): make-info
189
@$(if $(TARGET_DONE), \
193
$(foreach spec, $(SPECS), \
194
$(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \
195
SPEC=$(spec) HAS_SPEC=true $(MAKE_INIT_WITH_SPEC_ARGUMENTS) \
197
$(if $(and $(COMPARE_BUILD), $(PARALLEL_TARGETS)), \
198
$(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \
199
SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \
200
COMPARE_BUILD="$(COMPARE_BUILD)" pre-compare-build && \
201
$(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \
202
SPEC=$(spec) HAS_SPEC=true $(MAKE_INIT_WITH_SPEC_ARGUMENTS) \
203
COMPARE_BUILD="$(COMPARE_BUILD):NODRYRUN=true" main && \
204
$(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \
205
SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \
206
COMPARE_BUILD="$(COMPARE_BUILD):NODRYRUN=true" post-compare-build && \
209
$(eval TARGET_DONE=true) \
212
.PHONY: $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS)
214
endif # $(ONLY_GLOBAL_TARGETS)!=true
218
##############################################################################
219
# Now we have a spec. This part provides the "main" target that acts as a
220
# trampoline to call the Main.gmk with the value of $(MAKE) found in the spec
222
##############################################################################
226
# Our helper functions.
227
include $(TOPDIR)/make/InitSupport.gmk
229
# Parse COMPARE_BUILD (for makefile development)
230
$(eval $(call ParseCompareBuild))
232
# Setup reproducible build environment
233
$(eval $(call SetupReproducibleBuild))
235
# If no LOG= was given on command line, but we have a non-standard default
236
# value, use that instead and re-parse log level.
238
ifneq ($(DEFAULT_LOG), )
239
override LOG := $(DEFAULT_LOG)
240
$(eval $(call ParseLogLevel))
244
ifeq ($(LOG_NOFILE), true)
245
# Disable build log if LOG=[level,]nofile was given
246
override BUILD_LOG_PIPE :=
247
override BUILD_LOG_PIPE_SIMPLE :=
250
ifeq ($(filter dist-clean, $(SEQUENTIAL_TARGETS)), dist-clean)
251
# We can't have a log file if we're about to remove it.
252
override BUILD_LOG_PIPE :=
253
override BUILD_LOG_PIPE_SIMPLE :=
256
ifeq ($(OUTPUT_SYNC_SUPPORTED), true)
257
OUTPUT_SYNC_FLAG := -O$(OUTPUT_SYNC)
260
##############################################################################
262
##############################################################################
266
$(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
267
NO_RECIPES=true print-modules )
271
$(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
272
NO_RECIPES=true print-targets )
276
$(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
277
NO_RECIPES=true print-tests )
280
$(ECHO) $(CONFIGURE_COMMAND_LINE)
283
ifneq ($(REAL_CONFIGURE_COMMAND_EXEC_FULL), )
284
$(ECHO) "Re-running configure using original command line '$(REAL_CONFIGURE_COMMAND_EXEC_SHORT) $(REAL_CONFIGURE_COMMAND_LINE)'"
285
$(eval RECONFIGURE_COMMAND := $(REAL_CONFIGURE_COMMAND_EXEC_FULL) $(REAL_CONFIGURE_COMMAND_LINE))
286
else ifneq ($(CONFIGURE_COMMAND_LINE), )
287
$(ECHO) "Re-running configure using arguments '$(CONFIGURE_COMMAND_LINE)'"
288
$(eval RECONFIGURE_COMMAND := $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE))
290
$(ECHO) "Re-running configure using default settings"
291
$(eval RECONFIGURE_COMMAND := $(BASH) $(TOPDIR)/configure)
293
( cd $(CONFIGURE_START_DIR) && PATH="$(ORIGINAL_PATH)" AUTOCONF="$(AUTOCONF)" \
294
CUSTOM_ROOT="$(CUSTOM_ROOT)" \
295
CUSTOM_CONFIG_DIR="$(CUSTOM_CONFIG_DIR)" \
296
$(RECONFIGURE_COMMAND) )
298
##############################################################################
299
# The main target, for delegating into Main.gmk
300
##############################################################################
302
MAIN_TARGETS := $(SEQUENTIAL_TARGETS) $(PARALLEL_TARGETS) $(COMPARE_BUILD_MAKE)
303
# If building the default target, add what they are to the description.
304
DESCRIPTION_TARGETS := $(strip $(MAIN_TARGETS))
305
ifeq ($(DESCRIPTION_TARGETS), default)
306
DESCRIPTION_TARGETS += ($(DEFAULT_MAKE_TARGET))
308
TARGET_DESCRIPTION := target$(if $(word 2, $(MAIN_TARGETS)),s) \
309
'$(strip $(DESCRIPTION_TARGETS))' in configuration '$(CONF_NAME)'
311
# MAKEOVERRIDES is automatically set and propagated by Make to sub-Make calls.
312
# We need to clear it of the init-specific variables. The user-specified
313
# variables are explicitly propagated using $(USER_MAKE_VARS).
314
main: MAKEOVERRIDES :=
316
main: $(INIT_TARGETS)
317
ifneq ($(SEQUENTIAL_TARGETS)$(PARALLEL_TARGETS), )
318
$(call RotateLogFiles)
319
$(PRINTF) "Building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE_SIMPLE)
320
ifneq ($(SEQUENTIAL_TARGETS), )
321
# Don't touch build output dir since we might be cleaning. That
324
$(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
325
$(SEQUENTIAL_TARGETS) )
327
ifneq ($(PARALLEL_TARGETS), )
328
$(call PrepareFailureLogs)
329
$(call StartGlobalTimer)
330
$(call PrepareJavacServer)
331
# JOBS will only be empty for a bootcycle-images recursive call
332
# or if specified via a make argument directly. In those cases
333
# treat it as NOT using jobs at all.
335
$(NICE) $(MAKE) $(MAKE_ARGS) $(OUTPUT_SYNC_FLAG) \
336
$(if $(JOBS), -j $(JOBS)) \
337
-f make/Main.gmk $(USER_MAKE_VARS) \
338
$(PARALLEL_TARGETS) $(COMPARE_BUILD_MAKE) $(BUILD_LOG_PIPE) || \
340
$(PRINTF) "\nERROR: Build failed for $(TARGET_DESCRIPTION) (exit code $$exitcode) \n" \
341
$(BUILD_LOG_PIPE_SIMPLE) && \
342
cd $(TOPDIR) && $(MAKE) $(MAKE_ARGS) -j 1 -f make/Init.gmk \
343
HAS_SPEC=true on-failure ; \
345
$(call CleanupJavacServer)
346
$(call StopGlobalTimer)
347
$(call ReportBuildTimes)
349
if test -f $(MAKESUPPORT_OUTPUTDIR)/exit-with-error ; then \
352
$(PRINTF) "Finished building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE_SIMPLE)
353
$(call ReportProfileTimes)
357
$(call CleanupJavacServer)
358
$(call StopGlobalTimer)
359
$(call ReportBuildTimes)
360
$(call PrintFailureReports)
361
$(call PrintBuildLogFailures)
362
$(call ReportProfileTimes)
363
$(PRINTF) "HELP: Run 'make doctor' to diagnose build problems.\n\n"
364
ifneq ($(COMPARE_BUILD), )
365
$(call CleanupCompareBuild)
368
# Support targets for COMPARE_BUILD, used for makefile development
370
$(call WaitForJavacServerFinish)
371
$(call PrepareCompareBuild)
374
$(call WaitForJavacServerFinish)
375
$(call CleanupCompareBuild)
376
$(call CompareBuildDoComparison)
378
.PHONY: print-targets print-modules reconfigure main on-failure