Init.gmk revision 1926:678f4d9b1fe9
1287117Scem# 2287117Scem# Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 3287117Scem# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4287117Scem# 5287117Scem# This code is free software; you can redistribute it and/or modify it 6287117Scem# under the terms of the GNU General Public License version 2 only, as 7287117Scem# published by the Free Software Foundation. Oracle designates this 8287117Scem# particular file as subject to the "Classpath" exception as provided 9287117Scem# by Oracle in the LICENSE file that accompanied this code. 10287117Scem# 11287117Scem# This code is distributed in the hope that it will be useful, but WITHOUT 12287117Scem# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13287117Scem# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14287117Scem# version 2 for more details (a copy is included in the LICENSE file that 15287117Scem# accompanied this code). 16287117Scem# 17287117Scem# You should have received a copy of the GNU General Public License version 18287117Scem# 2 along with this work; if not, write to the Free Software Foundation, 19287117Scem# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20287117Scem# 21287117Scem# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22287117Scem# or visit www.oracle.com if you need additional information or have any 23287117Scem# questions. 24287117Scem# 25287117Scem 26287117Scem################################################################################ 27287117Scem# This is the bootstrapping part of the build. This file is included from the 28287117Scem# top level Makefile, and is responsible for launching the Main.gmk file with 29287117Scem# the proper make and the proper make arguments. 30287117Scem################################################################################ 31287117Scem 32287117Scem# This must be the first rule 33287117Scemdefault: 34287117Scem.PHONY: default 35287117Scem 36287117Scem# Inclusion of this pseudo-target will cause make to execute this file 37287117Scem# serially, regardless of -j. 38287117Scem.NOTPARALLEL: 39287117Scem 40287117Scemifeq ($(HAS_SPEC),) 41287117Scem ############################################################################## 42287117Scem # This is the default mode. We have not been recursively called with a SPEC. 43287117Scem ############################################################################## 44287117Scem 45287117Scem # Include our helper functions. 46289776Scem include $(topdir)/make/InitSupport.gmk 47287117Scem 48287117Scem # Here are "global" targets, i.e. targets that can be executed without having 49287117Scem # a configuration. This will define ALL_GLOBAL_TARGETS. 50287117Scem include $(topdir)/make/Help.gmk 51287117Scem 52287117Scem # Targets provided by Init.gmk. 53287117Scem ALL_INIT_TARGETS := print-modules print-targets print-configuration \ 54287117Scem reconfigure pre-compare-build post-compare-build 55289733Scem 56289733Scem # CALLED_TARGETS is the list of targets that the user provided, 57289733Scem # or "default" if unspecified. 58289733Scem CALLED_TARGETS := $(if $(MAKECMDGOALS), $(MAKECMDGOALS), default) 59287117Scem 60287117Scem # Extract non-global targets that require a spec file. 61289733Scem CALLED_SPEC_TARGETS := $(filter-out $(ALL_GLOBAL_TARGETS), $(CALLED_TARGETS)) 62287117Scem 63287117Scem # If we have only global targets, or if we are called with -qp (assuming an 64287117Scem # external part, e.g. bash completion, is trying to understand our targets), 65287117Scem # we will skip SPEC location and the sanity checks. 66289733Scem ifeq ($(CALLED_SPEC_TARGETS), ) 67287117Scem ONLY_GLOBAL_TARGETS := true 68289733Scem endif 69287117Scem ifneq ($(findstring qp, $(MAKEFLAGS)),) 70287117Scem ONLY_GLOBAL_TARGETS := true 71289733Scem endif 72289733Scem 73289733Scem ifeq ($(ONLY_GLOBAL_TARGETS), true) 74289733Scem ############################################################################ 75289733Scem # We have only global targets, or are called with -pq. 76289733Scem ############################################################################ 77287117Scem 78287117Scem ifeq ($(wildcard $(SPEC)), ) 79287117Scem # If we have no SPEC provided, we will just make a "best effort" target list. 80289777Scem # First try to grab any available pre-existing main-targets.gmk. 81289776Scem main_targets_file := $(firstword $(wildcard $(build_dir)/*/make-support/main-targets.gmk)) 82289776Scem ifneq ($(main_targets_file), ) 83287117Scem # Extract the SPEC that corresponds to this main-targets.gmk file. 84287117Scem SPEC := $(patsubst %/make-support/main-targets.gmk, %/spec.gmk, $(main_targets_file)) 85287117Scem else 86287117Scem # None found, pick an arbitrary SPEC for which to generate a file 87287117Scem SPEC := $(firstword $(all_spec_files)) 88287117Scem endif 89287117Scem endif 90289733Scem 91287117Scem ifneq ($(wildcard $(SPEC)), ) 92287117Scem $(eval $(call DefineMainTargets, LAZY, $(SPEC))) 93287117Scem else 94287117Scem # If we have no configurations we can not provide any main targets. 95287117Scem ALL_MAIN_TARGETS := 96287117Scem endif 97287117Scem 98287117Scem ALL_TARGETS := $(sort $(ALL_GLOBAL_TARGETS) $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS)) 99289733Scem 100287117Scem # Just list all our targets. 101287117Scem $(ALL_TARGETS): 102287117Scem 103289733Scem .PHONY: $(ALL_TARGETS) 104287117Scem 105289733Scem else 106287117Scem ############################################################################ 107287117Scem # This is the normal case, we have been called from the command line by the 108287117Scem # user and we need to call ourself back with a proper SPEC. 109287117Scem # We have at least one non-global target, so we need to find a spec file. 110287117Scem ############################################################################ 111287117Scem 112287117Scem # Basic checks on environment and command line. 113287117Scem $(eval $(call CheckControlVariables)) 114287117Scem $(eval $(call CheckDeprecatedEnvironment)) 115287117Scem $(eval $(call CheckInvalidMakeFlags)) 116287117Scem 117287117Scem # Check that CONF_CHECK is valid. 118287117Scem $(eval $(call ParseConfCheckOption)) 119287117Scem 120287117Scem # Check that the LOG given is valid, and set LOG_LEVEL, LOG_NOFILE and MAKE_LOG_FLAGS. 121287117Scem $(eval $(call ParseLogLevel)) 122287117Scem 123289733Scem # After this SPECS contain 1..N spec files (otherwise ParseConfAndSpec fails). 124289733Scem $(eval $(call ParseConfAndSpec)) 125289733Scem 126290021Scem # Extract main targets from Main.gmk using the spec(s) provided. In theory, 127290021Scem # with multiple specs, we should find the intersection of targets provided 128290021Scem # by all specs, but we approximate this by an arbitrary spec from the list. 129289733Scem # This will setup ALL_MAIN_TARGETS. 130290021Scem $(eval $(call DefineMainTargets, FORCE, $(firstword $(SPECS)))) 131290021Scem 132289733Scem # Separate called targets depending on type. 133290021Scem INIT_TARGETS := $(filter $(ALL_INIT_TARGETS), $(CALLED_SPEC_TARGETS)) 134290021Scem MAIN_TARGETS := $(filter $(ALL_MAIN_TARGETS), $(CALLED_SPEC_TARGETS)) 135290021Scem SEQUENTIAL_TARGETS := $(filter dist-clean clean%, $(MAIN_TARGETS)) 136290021Scem PARALLEL_TARGETS := $(filter-out $(SEQUENTIAL_TARGETS), $(MAIN_TARGETS)) 137290021Scem 138290021Scem # The spec files depend on the autoconf source code. This check makes sure 139290021Scem # the configuration is up to date after changes to configure. 140290021Scem CUSTOM_CONFIG_DIR ?= $(topdir)/closed/autoconf 141290021Scem 142290021Scem $(SPECS): $(wildcard $(topdir)/common/autoconf/*) $(wildcard $(CUSTOM_CONFIG_DIR)/*) 143290021Scem ifeq ($(CONF_CHECK), fail) 144290021Scem @echo "Error: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'." 145290021Scem $(call PrintConfCheckFailed) 146289733Scem @exit 2 147289733Scem else ifeq ($(CONF_CHECK), auto) 148289733Scem @echo "Note: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'." 149289733Scem @( cd $(topdir) && \ 150287117Scem $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \ 151287117Scem SPEC=$@ HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \ 152287117Scem reconfigure ) 153287117Scem else ifeq ($(CONF_CHECK), ignore) 154287117Scem # Do nothing 155287117Scem endif 156287117Scem 157287117Scem # Unless reconfigure is explicitely called, let all main targets depend on 158287117Scem # the spec files to be up to date. 159289733Scem ifeq ($(findstring reconfigure, $(INIT_TARGETS)), ) 160289776Scem $(MAIN_TARGETS): $(SPECS) 161289733Scem endif 162289733Scem 163289733Scem make-info: 164289733Scem ifneq ($(findstring $(LOG_LEVEL),info debug trace),) 165289733Scem $(info Running make as '$(strip $(MAKE) $(MFLAGS) \ 166289733Scem $(COMMAND_LINE_VARIABLES) $(MAKECMDGOALS))') 167289733Scem endif 168289733Scem 169289733Scem MAKE_INIT_WITH_SPEC_ARGUMENTS := ACTUAL_TOPDIR=$(topdir) \ 170289733Scem USER_MAKE_VARS="$(USER_MAKE_VARS)" MAKE_LOG_FLAGS=$(MAKE_LOG_FLAGS) \ 171289733Scem LOG_LEVEL=$(LOG_LEVEL) LOG_NOFILE=$(LOG_NOFILE) LOG_CMDLINES=$(LOG_CMDLINES) \ 172289733Scem INIT_TARGETS="$(INIT_TARGETS)" \ 173289733Scem SEQUENTIAL_TARGETS="$(SEQUENTIAL_TARGETS)" \ 174289733Scem PARALLEL_TARGETS="$(PARALLEL_TARGETS)" 175289733Scem 176289733Scem # Now the init and main targets will be called, once for each SPEC. The 177289733Scem # recipe will be run once for every target specified, but we only want to 178289733Scem # execute the recipe a single time, hence the TARGET_DONE with a dummy 179289733Scem # command if true. 180289733Scem # The COMPARE_BUILD part implements special support for makefile development. 181289733Scem $(ALL_INIT_TARGETS) $(ALL_MAIN_TARGETS): make-info 182289776Scem @$(if $(TARGET_DONE), \ 183289733Scem true \ 184289733Scem , \ 185289733Scem ( cd $(topdir) && \ 186289733Scem $(foreach spec, $(SPECS), \ 187289733Scem $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \ 188289733Scem SPEC=$(spec) HAS_SPEC=true $(MAKE_INIT_WITH_SPEC_ARGUMENTS) \ 189289733Scem main && \ 190289733Scem $(if $(and $(COMPARE_BUILD), $(PARALLEL_TARGETS)), \ 191289733Scem $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \ 192289733Scem SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \ 193289733Scem COMPARE_BUILD="$(COMPARE_BUILD)" pre-compare-build && \ 194289733Scem $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \ 195289733Scem SPEC=$(spec) HAS_SPEC=true $(MAKE_INIT_WITH_SPEC_ARGUMENTS) \ 196289733Scem COMPARE_BUILD="$(COMPARE_BUILD)" main && \ 197289733Scem $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \ 198289733Scem SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \ 199289733Scem COMPARE_BUILD="$(COMPARE_BUILD)" post-compare-build && \ 200289733Scem ) \ 201287117Scem ) true ) \ 202289733Scem $(eval TARGET_DONE=true) \ 203287117Scem ) 204287117Scem 205287117Scem .PHONY: $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS) 206289733Scem 207289733Scem endif # $(ONLY_GLOBAL_TARGETS)!=true 208289733Scem 209289733Scemelse # HAS_SPEC=true 210289733Scem 211289733Scem ############################################################################## 212289733Scem # Now we have a spec. This part provides the "main" target that acts as a 213289733Scem # trampoline to call the Main.gmk with the value of $(MAKE) found in the spec 214289733Scem # file. 215289733Scem ############################################################################## 216289733Scem 217289733Scem include $(SPEC) 218289733Scem 219289733Scem # Our helper functions. 220289733Scem include $(TOPDIR)/make/InitSupport.gmk 221289733Scem 222289733Scem # Verify that the spec file we included seems okay. 223289733Scem $(eval $(call CheckSpecSanity)) 224289733Scem 225289733Scem # Parse COMPARE_BUILD (for makefile development) 226290021Scem $(eval $(call ParseCompareBuild)) 227289733Scem 228289733Scem ifeq ($(LOG_NOFILE), true) 229290021Scem # Disable build log if LOG=[level,]nofile was given 230290021Scem override BUILD_LOG_PIPE := 231289733Scem endif 232289733Scem 233289733Scem ifeq ($(OUTPUT_SYNC_SUPPORTED), true) 234289733Scem OUTPUT_SYNC_FLAG := -O$(OUTPUT_SYNC) 235289733Scem endif 236289733Scem 237289733Scem ############################################################################## 238289733Scem # Init targets 239289733Scem ############################################################################## 240289733Scem 241289733Scem print-modules: 242289733Scem ( cd $(TOPDIR) && \ 243289733Scem $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 244289733Scem NO_RECIPES=true print-modules ) 245289733Scem 246289733Scem print-targets: 247289733Scem ( cd $(TOPDIR) && \ 248289733Scem $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 249289733Scem NO_RECIPES=true print-targets ) 250289733Scem 251289733Scem print-configuration: 252289733Scem $(ECHO) $(CONFIGURE_COMMAND_LINE) 253290021Scem 254290021Scem reconfigure: 255290021Scem ifneq ($(CONFIGURE_COMMAND_LINE), ) 256290021Scem $(ECHO) "Re-running configure using arguments '$(CONFIGURE_COMMAND_LINE)'" 257290021Scem else 258290021Scem $(ECHO) "Re-running configure using default settings" 259290021Scem endif 260290021Scem ( cd $(OUTPUT_ROOT) && PATH="$(ORIGINAL_PATH)" \ 261290021Scem $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) ) 262289733Scem 263289733Scem ############################################################################## 264289733Scem # The main target, for delegating into Main.gmk 265289733Scem ############################################################################## 266289733Scem 267289733Scem MAIN_TARGETS := $(SEQUENTIAL_TARGETS) $(PARALLEL_TARGETS) $(COMPARE_BUILD_MAKE) 268289733Scem TARGET_DESCRIPTION := target$(if $(word 2, $(MAIN_TARGETS)),s) \ 269289733Scem '$(strip $(MAIN_TARGETS))' in configuration '$(CONF_NAME)' 270287117Scem 271287117Scem # MAKEOVERRIDES is automatically set and propagated by Make to sub-Make calls. 272287117Scem # We need to clear it of the init-specific variables. The user-specified 273287117Scem # variables are explicitely propagated using $(USER_MAKE_VARS). 274287117Scem main: MAKEOVERRIDES := 275289733Scem 276287117Scem main: $(INIT_TARGETS) 277287117Scem ifneq ($(SEQUENTIAL_TARGETS)$(PARALLEL_TARGETS), ) 278289733Scem $(call RotateLogFiles) 279287117Scem $(call PrepareFailureLogs) 280289733Scem $(PRINTF) "Building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE) 281289776Scem ifneq ($(SEQUENTIAL_TARGETS), ) 282289733Scem # Don't touch build output dir since we might be cleaning. That 283289733Scem # means no log pipe. 284289733Scem ( cd $(TOPDIR) && \ 285287117Scem $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 286289733Scem $(SEQUENTIAL_TARGETS) ) 287289776Scem endif 288289733Scem ifneq ($(PARALLEL_TARGETS), ) 289289733Scem $(call StartGlobalTimer) 290289733Scem $(call PrepareSmartJavac) 291289733Scem ( cd $(TOPDIR) && \ 292289733Scem $(NICE) $(MAKE) $(MAKE_ARGS) $(OUTPUT_SYNC_FLAG) \ 293289733Scem -j $(JOBS) -f make/Main.gmk $(USER_MAKE_VARS) \ 294289733Scem $(PARALLEL_TARGETS) $(COMPARE_BUILD_MAKE) $(BUILD_LOG_PIPE) || \ 295289776Scem ( exitcode=$$? && \ 296289733Scem $(PRINTF) "\nERROR: Build failed for $(TARGET_DESCRIPTION) (exit code $$exitcode) \n" \ 297289733Scem $(BUILD_LOG_PIPE) && \ 298289733Scem cd $(TOPDIR) && $(MAKE) $(MAKE_ARGS) -j 1 -f make/Init.gmk \ 299289733Scem HAS_SPEC=true on-failure ; \ 300289733Scem exit $$exitcode ) ) 301289733Scem $(call CleanupSmartJavac) 302289776Scem $(call StopGlobalTimer) 303289733Scem $(call ReportBuildTimes) 304289733Scem endif 305289733Scem $(PRINTF) "Finished building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE) 306289733Scem endif 307289733Scem 308290021Scem on-failure: 309290021Scem $(call PrintFailureReports) 310290021Scem $(call PrintBuildLogFailures) 311290021Scem $(PRINTF) "Hint: If caused by a warning, try configure --disable-warnings-as-errors.\n\n" 312290021Scem ifneq ($(COMPARE_BUILD), ) 313290021Scem $(call CleanupCompareBuild) 314290021Scem endif 315287117Scem 316287117Scem # Support targets for COMPARE_BUILD, used for makefile development 317289776Scem pre-compare-build: 318289733Scem $(call WaitForSmartJavacFinish) 319287117Scem $(call PrepareCompareBuild) 320287117Scem 321287117Scem post-compare-build: 322289733Scem $(call WaitForSmartJavacFinish) 323289733Scem $(call CleanupCompareBuild) 324289733Scem $(call CompareBuildDoComparison) 325287117Scem 326289733Scem .PHONY: print-targets print-modules reconfigure main on-failure 327289776Scemendif 328289733Scem