Init.gmk revision 2034:c3efe6acb2ae
199461Sobrien# 2218822Sdim# Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 3218822Sdim# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 499461Sobrien# 599461Sobrien# This code is free software; you can redistribute it and/or modify it 699461Sobrien# under the terms of the GNU General Public License version 2 only, as 799461Sobrien# published by the Free Software Foundation. Oracle designates this 899461Sobrien# particular file as subject to the "Classpath" exception as provided 999461Sobrien# by Oracle in the LICENSE file that accompanied this code. 1099461Sobrien# 1199461Sobrien# This code is distributed in the hope that it will be useful, but WITHOUT 1299461Sobrien# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1399461Sobrien# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1499461Sobrien# version 2 for more details (a copy is included in the LICENSE file that 1599461Sobrien# accompanied this code). 1699461Sobrien# 1799461Sobrien# You should have received a copy of the GNU General Public License version 1899461Sobrien# 2 along with this work; if not, write to the Free Software Foundation, 1999461Sobrien# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20218822Sdim# 21218822Sdim# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2299461Sobrien# or visit www.oracle.com if you need additional information or have any 23218822Sdim# questions. 2499461Sobrien# 2599461Sobrien 2699461Sobrien################################################################################ 2799461Sobrien# This is the bootstrapping part of the build. This file is included from the 2899461Sobrien# top level Makefile, and is responsible for launching the Main.gmk file with 2999461Sobrien# the proper make and the proper make arguments. 3099461Sobrien################################################################################ 3199461Sobrien 3299461Sobrien# This must be the first rule 33130561Sobriendefault: 3499461Sobrien.PHONY: default 3599461Sobrien 3699461Sobrien# Inclusion of this pseudo-target will cause make to execute this file 3799461Sobrien# serially, regardless of -j. 3899461Sobrien.NOTPARALLEL: 39130561Sobrien 4099461Sobrienifeq ($(HAS_SPEC),) 41130561Sobrien ############################################################################## 4299461Sobrien # This is the default mode. We have not been recursively called with a SPEC. 4399461Sobrien ############################################################################## 44218822Sdim 45107492Sobrien # Include our helper functions. 46130561Sobrien include $(topdir)/make/InitSupport.gmk 4799461Sobrien 4899461Sobrien # Here are "global" targets, i.e. targets that can be executed without having 49130561Sobrien # a configuration. This will define ALL_GLOBAL_TARGETS. 50130561Sobrien include $(topdir)/make/Help.gmk 51130561Sobrien 52130561Sobrien # Targets provided by Init.gmk. 5399461Sobrien ALL_INIT_TARGETS := print-modules print-targets print-configuration \ 54130561Sobrien reconfigure pre-compare-build post-compare-build 5599461Sobrien 56130561Sobrien # CALLED_TARGETS is the list of targets that the user provided, 5799461Sobrien # or "default" if unspecified. 58130561Sobrien CALLED_TARGETS := $(if $(MAKECMDGOALS), $(MAKECMDGOALS), default) 5999461Sobrien 60130561Sobrien # Extract non-global targets that require a spec file. 6199461Sobrien CALLED_SPEC_TARGETS := $(filter-out $(ALL_GLOBAL_TARGETS), $(CALLED_TARGETS)) 6299461Sobrien 63130561Sobrien # If we have only global targets, or if we are called with -qp (assuming an 6499461Sobrien # external part, e.g. bash completion, is trying to understand our targets), 6599461Sobrien # we will skip SPEC location and the sanity checks. 6699461Sobrien ifeq ($(CALLED_SPEC_TARGETS), ) 6799461Sobrien ONLY_GLOBAL_TARGETS := true 68130561Sobrien endif 6999461Sobrien ifneq ($(findstring qp, $(MAKEFLAGS)),) 70130561Sobrien ONLY_GLOBAL_TARGETS := true 71130561Sobrien endif 72130561Sobrien 73130561Sobrien ifeq ($(ONLY_GLOBAL_TARGETS), true) 74130561Sobrien ############################################################################ 75130561Sobrien # We have only global targets, or are called with -pq. 76130561Sobrien ############################################################################ 77130561Sobrien 78130561Sobrien ifeq ($(wildcard $(SPEC)), ) 79130561Sobrien # If we have no SPEC provided, we will just make a "best effort" target list. 80130561Sobrien # First try to grab any available pre-existing main-targets.gmk. 81130561Sobrien main_targets_file := $(firstword $(wildcard $(build_dir)/*/make-support/main-targets.gmk)) 82130561Sobrien ifneq ($(main_targets_file), ) 83130561Sobrien # Extract the SPEC that corresponds to this main-targets.gmk file. 8499461Sobrien SPEC := $(patsubst %/make-support/main-targets.gmk, %/spec.gmk, $(main_targets_file)) 8599461Sobrien else 8699461Sobrien # None found, pick an arbitrary SPEC for which to generate a file 8799461Sobrien SPEC := $(firstword $(all_spec_files)) 8899461Sobrien endif 8999461Sobrien endif 9099461Sobrien 9199461Sobrien ifneq ($(wildcard $(SPEC)), ) 9299461Sobrien $(eval $(call DefineMainTargets, LAZY, $(SPEC))) 9399461Sobrien else 9499461Sobrien # If we have no configurations we can not provide any main targets. 9599461Sobrien ALL_MAIN_TARGETS := 9699461Sobrien endif 9799461Sobrien 98130561Sobrien ALL_TARGETS := $(sort $(ALL_GLOBAL_TARGETS) $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS)) 9999461Sobrien 10099461Sobrien # Just list all our targets. 10199461Sobrien $(ALL_TARGETS): 10299461Sobrien 103130561Sobrien .PHONY: $(ALL_TARGETS) 10499461Sobrien 10599461Sobrien else 106130561Sobrien ############################################################################ 10799461Sobrien # This is the normal case, we have been called from the command line by the 108130561Sobrien # user and we need to call ourself back with a proper SPEC. 109130561Sobrien # We have at least one non-global target, so we need to find a spec file. 110130561Sobrien ############################################################################ 111130561Sobrien 112130561Sobrien # Basic checks on environment and command line. 113130561Sobrien $(eval $(call CheckControlVariables)) 114130561Sobrien $(eval $(call CheckDeprecatedEnvironment)) 115130561Sobrien $(eval $(call CheckInvalidMakeFlags)) 116130561Sobrien 117130561Sobrien # Check that CONF_CHECK is valid. 118130561Sobrien $(eval $(call ParseConfCheckOption)) 119130561Sobrien 120130561Sobrien # Check that the LOG given is valid, and set LOG_LEVEL, LOG_NOFILE and MAKE_LOG_FLAGS. 121130561Sobrien $(eval $(call ParseLogLevel)) 122130561Sobrien 123130561Sobrien # After this SPECS contain 1..N spec files (otherwise ParseConfAndSpec fails). 124130561Sobrien $(eval $(call ParseConfAndSpec)) 125130561Sobrien 126130561Sobrien # Extract main targets from Main.gmk using the spec(s) provided. In theory, 127130561Sobrien # with multiple specs, we should find the intersection of targets provided 128130561Sobrien # by all specs, but we approximate this by an arbitrary spec from the list. 129130561Sobrien # This will setup ALL_MAIN_TARGETS. 130130561Sobrien $(eval $(call DefineMainTargets, FORCE, $(firstword $(SPECS)))) 131130561Sobrien 132130561Sobrien # Separate called targets depending on type. 133130561Sobrien INIT_TARGETS := $(filter $(ALL_INIT_TARGETS), $(CALLED_SPEC_TARGETS)) 134130561Sobrien MAIN_TARGETS := $(filter $(ALL_MAIN_TARGETS), $(CALLED_SPEC_TARGETS)) 135130561Sobrien SEQUENTIAL_TARGETS := $(filter dist-clean clean%, $(MAIN_TARGETS)) 136130561Sobrien PARALLEL_TARGETS := $(filter-out $(SEQUENTIAL_TARGETS), $(MAIN_TARGETS)) 137130561Sobrien 138130561Sobrien # The spec files depend on the autoconf source code. This check makes sure 139130561Sobrien # the configuration is up to date after changes to configure. 140130561Sobrien CUSTOM_CONFIG_DIR ?= $(topdir)/closed/autoconf 141130561Sobrien 142130561Sobrien $(SPECS): $(wildcard $(topdir)/common/autoconf/*) $(wildcard $(CUSTOM_CONFIG_DIR)/*) 143130561Sobrien ifeq ($(CONF_CHECK), fail) 144130561Sobrien @echo "Error: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'." 145130561Sobrien $(call PrintConfCheckFailed) 146130561Sobrien @exit 2 147130561Sobrien else ifeq ($(CONF_CHECK), auto) 148130561Sobrien @echo "Note: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'." 149130561Sobrien @( cd $(topdir) && \ 150130561Sobrien $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \ 151130561Sobrien SPEC=$@ HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \ 152130561Sobrien reconfigure ) 153130561Sobrien else ifeq ($(CONF_CHECK), ignore) 154130561Sobrien # Do nothing 155130561Sobrien endif 156130561Sobrien 157130561Sobrien # Do not let make delete spec files even if aborted while doing a reconfigure 158130561Sobrien .PRECIOUS: $(SPECS) 159130561Sobrien 160130561Sobrien # Unless reconfigure is explicitely called, let all main targets depend on 161130561Sobrien # the spec files to be up to date. 162130561Sobrien ifeq ($(findstring reconfigure, $(INIT_TARGETS)), ) 163130561Sobrien $(MAIN_TARGETS): $(SPECS) 164130561Sobrien endif 165130561Sobrien 166130561Sobrien make-info: 167130561Sobrien ifneq ($(findstring $(LOG_LEVEL),info debug trace),) 168130561Sobrien $(info Running make as '$(strip $(MAKE) $(MFLAGS) \ 169130561Sobrien $(COMMAND_LINE_VARIABLES) $(MAKECMDGOALS))') 170130561Sobrien endif 171130561Sobrien 172130561Sobrien MAKE_INIT_WITH_SPEC_ARGUMENTS := ACTUAL_TOPDIR=$(topdir) \ 173130561Sobrien USER_MAKE_VARS="$(USER_MAKE_VARS)" MAKE_LOG_FLAGS=$(MAKE_LOG_FLAGS) \ 174130561Sobrien LOG_LEVEL=$(LOG_LEVEL) LOG_NOFILE=$(LOG_NOFILE) LOG_CMDLINES=$(LOG_CMDLINES) \ 175130561Sobrien INIT_TARGETS="$(INIT_TARGETS)" \ 176130561Sobrien SEQUENTIAL_TARGETS="$(SEQUENTIAL_TARGETS)" \ 177130561Sobrien PARALLEL_TARGETS="$(PARALLEL_TARGETS)" 178130561Sobrien 179130561Sobrien # Now the init and main targets will be called, once for each SPEC. The 180130561Sobrien # recipe will be run once for every target specified, but we only want to 181130561Sobrien # execute the recipe a single time, hence the TARGET_DONE with a dummy 182130561Sobrien # command if true. 183130561Sobrien # The COMPARE_BUILD part implements special support for makefile development. 184130561Sobrien $(ALL_INIT_TARGETS) $(ALL_MAIN_TARGETS): make-info 185130561Sobrien @$(if $(TARGET_DONE), \ 186130561Sobrien true \ 187130561Sobrien , \ 188130561Sobrien ( cd $(topdir) && \ 189130561Sobrien $(foreach spec, $(SPECS), \ 190130561Sobrien $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \ 191130561Sobrien SPEC=$(spec) HAS_SPEC=true $(MAKE_INIT_WITH_SPEC_ARGUMENTS) \ 192130561Sobrien main && \ 193130561Sobrien $(if $(and $(COMPARE_BUILD), $(PARALLEL_TARGETS)), \ 194130561Sobrien $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \ 195130561Sobrien SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \ 196130561Sobrien COMPARE_BUILD="$(COMPARE_BUILD)" pre-compare-build && \ 197130561Sobrien $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \ 198130561Sobrien SPEC=$(spec) HAS_SPEC=true $(MAKE_INIT_WITH_SPEC_ARGUMENTS) \ 199130561Sobrien COMPARE_BUILD="$(COMPARE_BUILD)" main && \ 200130561Sobrien $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \ 201130561Sobrien SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \ 202130561Sobrien COMPARE_BUILD="$(COMPARE_BUILD)" post-compare-build && \ 203130561Sobrien ) \ 204130561Sobrien ) true ) \ 205130561Sobrien $(eval TARGET_DONE=true) \ 206130561Sobrien ) 207130561Sobrien 208130561Sobrien .PHONY: $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS) 209130561Sobrien 210130561Sobrien endif # $(ONLY_GLOBAL_TARGETS)!=true 211130561Sobrien 212130561Sobrienelse # HAS_SPEC=true 213130561Sobrien 214130561Sobrien ############################################################################## 215130561Sobrien # Now we have a spec. This part provides the "main" target that acts as a 216130561Sobrien # trampoline to call the Main.gmk with the value of $(MAKE) found in the spec 217130561Sobrien # file. 218130561Sobrien ############################################################################## 219130561Sobrien 220130561Sobrien include $(SPEC) 221130561Sobrien 22299461Sobrien # Our helper functions. 22399461Sobrien include $(TOPDIR)/make/InitSupport.gmk 22499461Sobrien 22599461Sobrien # Verify that the spec file we included seems okay. 226130561Sobrien $(eval $(call CheckSpecSanity)) 22799461Sobrien 228130561Sobrien # Parse COMPARE_BUILD (for makefile development) 22999461Sobrien $(eval $(call ParseCompareBuild)) 23099461Sobrien 23199461Sobrien ifeq ($(LOG_NOFILE), true) 23299461Sobrien # Disable build log if LOG=[level,]nofile was given 23399461Sobrien override BUILD_LOG_PIPE := 23499461Sobrien endif 23599461Sobrien 23699461Sobrien ifeq ($(OUTPUT_SYNC_SUPPORTED), true) 23799461Sobrien OUTPUT_SYNC_FLAG := -O$(OUTPUT_SYNC) 23899461Sobrien endif 23999461Sobrien 24099461Sobrien ############################################################################## 24199461Sobrien # Init targets 24299461Sobrien ############################################################################## 24399461Sobrien 24499461Sobrien print-modules: 24599461Sobrien ( cd $(TOPDIR) && \ 24699461Sobrien $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 24799461Sobrien NO_RECIPES=true print-modules ) 24899461Sobrien 24999461Sobrien print-targets: 25099461Sobrien ( cd $(TOPDIR) && \ 25199461Sobrien $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 25299461Sobrien NO_RECIPES=true print-targets ) 25399461Sobrien 25499461Sobrien print-configuration: 25599461Sobrien $(ECHO) $(CONFIGURE_COMMAND_LINE) 25699461Sobrien 25799461Sobrien reconfigure: 25899461Sobrien ifneq ($(CONFIGURE_COMMAND_LINE), ) 25999461Sobrien $(ECHO) "Re-running configure using arguments '$(CONFIGURE_COMMAND_LINE)'" 26099461Sobrien else 26199461Sobrien $(ECHO) "Re-running configure using default settings" 26299461Sobrien endif 26399461Sobrien ( cd $(OUTPUT_ROOT) && PATH="$(ORIGINAL_PATH)" \ 26499461Sobrien $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) ) 26599461Sobrien 266130561Sobrien ############################################################################## 26799461Sobrien # The main target, for delegating into Main.gmk 26899461Sobrien ############################################################################## 26999461Sobrien 27099461Sobrien MAIN_TARGETS := $(SEQUENTIAL_TARGETS) $(PARALLEL_TARGETS) $(COMPARE_BUILD_MAKE) 27199461Sobrien # If building the default target, add what they are to the description. 27299461Sobrien DESCRIPTION_TARGETS := $(strip $(MAIN_TARGETS)) 27399461Sobrien ifeq ($(DESCRIPTION_TARGETS), default) 27499461Sobrien DESCRIPTION_TARGETS += ($(DEFAULT_MAKE_TARGET)) 27599461Sobrien endif 27699461Sobrien TARGET_DESCRIPTION := target$(if $(word 2, $(MAIN_TARGETS)),s) \ 27799461Sobrien '$(strip $(DESCRIPTION_TARGETS))' in configuration '$(CONF_NAME)' 27899461Sobrien 27999461Sobrien # MAKEOVERRIDES is automatically set and propagated by Make to sub-Make calls. 28099461Sobrien # We need to clear it of the init-specific variables. The user-specified 28199461Sobrien # variables are explicitely propagated using $(USER_MAKE_VARS). 28299461Sobrien main: MAKEOVERRIDES := 28399461Sobrien 28499461Sobrien main: $(INIT_TARGETS) 28599461Sobrien ifneq ($(SEQUENTIAL_TARGETS)$(PARALLEL_TARGETS), ) 28699461Sobrien $(call RotateLogFiles) 28799461Sobrien $(call PrepareFailureLogs) 28899461Sobrien $(PRINTF) "Building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE) 28999461Sobrien ifneq ($(SEQUENTIAL_TARGETS), ) 29099461Sobrien # Don't touch build output dir since we might be cleaning. That 29199461Sobrien # means no log pipe. 29299461Sobrien ( cd $(TOPDIR) && \ 293130561Sobrien $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 294130561Sobrien $(SEQUENTIAL_TARGETS) ) 295130561Sobrien endif 296130561Sobrien ifneq ($(PARALLEL_TARGETS), ) 297130561Sobrien $(call StartGlobalTimer) 298130561Sobrien $(call PrepareSmartJavac) 299130561Sobrien ( cd $(TOPDIR) && \ 300130561Sobrien $(NICE) $(MAKE) $(MAKE_ARGS) $(OUTPUT_SYNC_FLAG) \ 301130561Sobrien -j $(JOBS) -f make/Main.gmk $(USER_MAKE_VARS) \ 302130561Sobrien $(PARALLEL_TARGETS) $(COMPARE_BUILD_MAKE) $(BUILD_LOG_PIPE) || \ 303130561Sobrien ( exitcode=$$? && \ 304130561Sobrien $(PRINTF) "\nERROR: Build failed for $(TARGET_DESCRIPTION) (exit code $$exitcode) \n" \ 305130561Sobrien $(BUILD_LOG_PIPE) && \ 306130561Sobrien cd $(TOPDIR) && $(MAKE) $(MAKE_ARGS) -j 1 -f make/Init.gmk \ 307130561Sobrien HAS_SPEC=true on-failure ; \ 308130561Sobrien exit $$exitcode ) ) 309130561Sobrien $(call CleanupSmartJavac) 310130561Sobrien $(call StopGlobalTimer) 311130561Sobrien $(call ReportBuildTimes) 312130561Sobrien endif 313130561Sobrien $(PRINTF) "Finished building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE) 314130561Sobrien endif 315130561Sobrien 316130561Sobrien on-failure: 317130561Sobrien $(call PrintFailureReports) 318130561Sobrien $(call PrintBuildLogFailures) 319130561Sobrien $(PRINTF) "Hint: If caused by a warning, try configure --disable-warnings-as-errors.\n\n" 320130561Sobrien ifneq ($(COMPARE_BUILD), ) 321130561Sobrien $(call CleanupCompareBuild) 322130561Sobrien endif 323130561Sobrien 324130561Sobrien # Support targets for COMPARE_BUILD, used for makefile development 325130561Sobrien pre-compare-build: 326130561Sobrien $(call WaitForSmartJavacFinish) 327130561Sobrien $(call PrepareCompareBuild) 328130561Sobrien 329130561Sobrien post-compare-build: 330130561Sobrien $(call WaitForSmartJavacFinish) 331130561Sobrien $(call CleanupCompareBuild) 332130561Sobrien $(call CompareBuildDoComparison) 333130561Sobrien 334130561Sobrien .PHONY: print-targets print-modules reconfigure main on-failure 335130561Sobrienendif 336130561Sobrien