Init.gmk revision 1628:4fb0ae864a1d
1# 2# Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 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. 10# 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). 16# 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. 20# 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 23# questions. 24# 25 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################################################################################ 31 32# This must be the first rule 33default: 34.PHONY: default 35 36# Inclusion of this pseudo-target will cause make to execute this file 37# serially, regardless of -j. 38.NOTPARALLEL: 39 40ifeq ($(HAS_SPEC),) 41 ############################################################################## 42 # This is the default mode. We have not been recursively called with a SPEC. 43 ############################################################################## 44 45 # Include our helper functions. 46 include $(topdir)/make/InitSupport.gmk 47 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/Help.gmk 51 52 # Targets provided by Init.gmk. 53 ALL_INIT_TARGETS := print-modules print-targets print-configuration reconfigure 54 55 # CALLED_TARGETS is the list of targets that the user provided, 56 # or "default" if unspecified. 57 CALLED_TARGETS := $(if $(MAKECMDGOALS), $(MAKECMDGOALS), default) 58 59 # Extract non-global targets that require a spec file. 60 CALLED_SPEC_TARGETS := $(filter-out $(ALL_GLOBAL_TARGETS), $(CALLED_TARGETS)) 61 62 # If we have only global targets, or if we are called with -qp (assuming an 63 # external part, e.g. bash completion, is trying to understand our targets), 64 # we will skip SPEC location and the sanity checks. 65 ifeq ($(CALLED_SPEC_TARGETS), ) 66 ONLY_GLOBAL_TARGETS := true 67 endif 68 ifneq ($(findstring qp, $(MAKEFLAGS)),) 69 ONLY_GLOBAL_TARGETS := true 70 endif 71 72 ifeq ($(ONLY_GLOBAL_TARGETS), true) 73 ############################################################################ 74 # We have only global targets, or are called with -pq. 75 ############################################################################ 76 77 ifeq ($(wildcard $(SPEC)), ) 78 # If we have no SPEC provided, we will just make a "best effort" target list. 79 # First try to grab any available pre-existing main-targets.gmk. 80 main_targets_file := $(firstword $(wildcard $(build_dir)/*/make-support/main-targets.gmk)) 81 ifneq ($(main_targets_file), ) 82 # Extract the SPEC that corresponds to this main-targets.gmk file. 83 SPEC := $(patsubst %/make-support/main-targets.gmk, %/spec.gmk, $(main_targets_file)) 84 else 85 # None found, pick an arbitrary SPEC for which to generate a file 86 SPEC := $(firstword $(all_spec_files)) 87 endif 88 endif 89 90 ifneq ($(wildcard $(SPEC)), ) 91 $(eval $(call DefineMainTargets, LAZY, $(SPEC))) 92 else 93 # If we have no configurations we can not provide any main targets. 94 ALL_MAIN_TARGETS := 95 endif 96 97 ALL_TARGETS := $(sort $(ALL_GLOBAL_TARGETS) $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS)) 98 99 # Just list all our targets. 100 $(ALL_TARGETS): 101 102 .PHONY: $(ALL_TARGETS) 103 104 else 105 ############################################################################ 106 # This is the normal case, we have been called from the command line by the 107 # user and we need to call ourself back with a proper SPEC. 108 # We have at least one non-global target, so we need to find a spec file. 109 ############################################################################ 110 111 # Basic checks on environment and command line. 112 $(eval $(call CheckControlVariables)) 113 $(eval $(call CheckDeprecatedEnvironment)) 114 $(eval $(call CheckInvalidMakeFlags)) 115 116 # Check that CONF_CHECK is valid. 117 $(eval $(call ParseConfCheckOption)) 118 119 # Check that the LOG given is valid, and set LOG_LEVEL, LOG_NOFILE and MAKE_LOG_FLAGS. 120 $(eval $(call ParseLogLevel)) 121 122 # After this SPECS contain 1..N spec files (otherwise ParseConfAndSpec fails). 123 $(eval $(call ParseConfAndSpec)) 124 125 # Extract main targets from Main.gmk using the spec(s) provided. In theory, 126 # with multiple specs, we should find the intersection of targets provided 127 # by all specs, but we approximate this by an arbitrary spec from the list. 128 # This will setup ALL_MAIN_TARGETS. 129 $(eval $(call DefineMainTargets, FORCE, $(firstword $(SPECS)))) 130 131 # Separate called targets depending on type. 132 INIT_TARGETS := $(filter $(ALL_INIT_TARGETS), $(CALLED_SPEC_TARGETS)) 133 MAIN_TARGETS := $(filter $(ALL_MAIN_TARGETS), $(CALLED_SPEC_TARGETS)) 134 SEQUENTIAL_TARGETS := $(filter dist-clean clean%, $(MAIN_TARGETS)) 135 PARALLEL_TARGETS := $(filter-out $(SEQUENTIAL_TARGETS), $(MAIN_TARGETS)) 136 137 # The spec files depend on the autoconf source code. This check makes sure 138 # the configuration is up to date after changes to configure. 139 $(SPECS): $(wildcard $(topdir)/common/autoconf/*) 140 ifeq ($(CONF_CHECK), fail) 141 @echo "Error: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'." 142 $(call PrintConfCheckFailed) 143 @exit 2 144 else ifeq ($(CONF_CHECK), auto) 145 @echo "Note: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'." 146 @( cd $(topdir) && \ 147 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \ 148 SPEC=$@ HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \ 149 reconfigure ) 150 else ifeq ($(CONF_CHECK), ignore) 151 # Do nothing 152 endif 153 154 # Unless reconfigure is explicitely called, let all main targets depend on 155 # the spec files to be up to date. 156 ifeq ($(findstring reconfigure, $(INIT_TARGETS)), ) 157 $(MAIN_TARGETS): $(SPECS) 158 endif 159 160 make-info: 161 ifneq ($(findstring $(LOG_LEVEL),info debug trace),) 162 $(info Running make as '$(strip $(MAKE) $(MFLAGS) \ 163 $(COMMAND_LINE_VARIABLES) $(MAKECMDGOALS))') 164 endif 165 166 # Now the init and main targets will be called, once for each SPEC. The 167 # recipe will be run once for every target specified, but we only want to 168 # execute the recipe a single time, hence the TARGET_DONE with a dummy 169 # command if true. 170 $(ALL_INIT_TARGETS) $(ALL_MAIN_TARGETS): make-info 171 @$(if $(TARGET_DONE), \ 172 true \ 173 , \ 174 $(foreach spec, $(SPECS), \ 175 ( cd $(topdir) && \ 176 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \ 177 SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \ 178 USER_MAKE_VARS="$(USER_MAKE_VARS)" MAKE_LOG_FLAGS=$(MAKE_LOG_FLAGS) \ 179 LOG_LEVEL=$(LOG_LEVEL) LOG_NOFILE=$(LOG_NOFILE) \ 180 INIT_TARGETS="$(INIT_TARGETS)" \ 181 SEQUENTIAL_TARGETS="$(SEQUENTIAL_TARGETS)" \ 182 PARALLEL_TARGETS="$(PARALLEL_TARGETS)" \ 183 main ) && \ 184 ) true \ 185 $(eval TARGET_DONE=true) \ 186 ) 187 188 .PHONY: $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS) 189 190 endif # $(ONLY_GLOBAL_TARGETS)!=true 191 192else # HAS_SPEC=true 193 194 ############################################################################## 195 # Now we have a spec. This part provides the "main" target that acts as a 196 # trampoline to call the Main.gmk with the value of $(MAKE) found in the spec 197 # file. 198 ############################################################################## 199 200 include $(SPEC) 201 202 # Our helper functions. 203 include $(TOPDIR)/make/InitSupport.gmk 204 205 # Verify that the spec file we included seems okay. 206 $(eval $(call CheckSpecSanity)) 207 208 ifeq ($(LOG_NOFILE), true) 209 # Disable log wrapper if LOG=[level,]nofile was given 210 override BUILD_LOG_WRAPPER := 211 endif 212 213 ifeq ($(OUTPUT_SYNC_SUPPORTED), true) 214 OUTPUT_SYNC_FLAG := -O$(OUTPUT_SYNC) 215 endif 216 217 ############################################################################## 218 # Init targets 219 ############################################################################## 220 221 print-modules: 222 ( cd $(TOPDIR) && \ 223 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 224 NO_RECIPES=true print-modules ) 225 226 print-targets: 227 ( cd $(TOPDIR) && \ 228 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 229 NO_RECIPES=true print-targets ) 230 231 print-configuration: 232 $(ECHO) $(CONFIGURE_COMMAND_LINE) 233 234 reconfigure: 235 ifneq ($(CONFIGURE_COMMAND_LINE), ) 236 $(ECHO) "Re-running configure using arguments '$(CONFIGURE_COMMAND_LINE)'" 237 else 238 $(ECHO) "Re-running configure using default settings" 239 endif 240 ( cd $(OUTPUT_ROOT) && PATH="$(ORIGINAL_PATH)" \ 241 $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) ) 242 243 ############################################################################## 244 # The main target, for delegating into Main.gmk 245 ############################################################################## 246 247 MAIN_TARGETS := $(SEQUENTIAL_TARGETS) $(PARALLEL_TARGETS) 248 TARGET_DESCRIPTION := target$(if $(word 2, $(MAIN_TARGETS)),s) \ 249 '$(strip $(MAIN_TARGETS))' in configuration '$(CONF_NAME)' 250 251 # MAKEOVERRIDES is automatically set and propagated by Make to sub-Make calls. 252 # We need to clear it of the init-specific variables. The user-specified 253 # variables are explicitely propagated using $(USER_MAKE_VARS). 254 main: MAKEOVERRIDES := 255 256 main: $(INIT_TARGETS) 257 ifneq ($(SEQUENTIAL_TARGETS)$(PARALLEL_TARGETS), ) 258 $(call RotateLogFiles) 259 $(call PrepareFailureLogs) 260 $(BUILD_LOG_WRAPPER) $(PRINTF) "Building $(TARGET_DESCRIPTION)\n" 261 ifneq ($(SEQUENTIAL_TARGETS), ) 262 # Don't touch build output dir since we might be cleaning. That 263 # means no log wrapper. 264 ( cd $(TOPDIR) && \ 265 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 266 $(SEQUENTIAL_TARGETS) ) 267 endif 268 ifneq ($(PARALLEL_TARGETS), ) 269 $(call StartGlobalTimer) 270 $(call PrepareSmartJavac) 271 ( cd $(TOPDIR) && \ 272 $(BUILD_LOG_WRAPPER) $(MAKE) $(MAKE_ARGS) $(OUTPUT_SYNC_FLAG) \ 273 -j $(JOBS) -f make/Main.gmk $(USER_MAKE_VARS) \ 274 $(PARALLEL_TARGETS) || \ 275 ( exitcode=$$? && $(BUILD_LOG_WRAPPER) \ 276 $(PRINTF) "\nERROR: Build failed for $(TARGET_DESCRIPTION) (exit code $$exitcode) \n" && \ 277 cd $(TOPDIR) && $(MAKE) $(MAKE_ARGS) -j 1 -f make/Init.gmk \ 278 HAS_SPEC=true on-failure ; \ 279 exit $$exitcode ) ) 280 $(call CleanupSmartJavac) 281 $(call StopGlobalTimer) 282 $(call ReportBuildTimes) 283 endif 284 $(BUILD_LOG_WRAPPER) $(PRINTF) "Finished building $(TARGET_DESCRIPTION)\n" 285 endif 286 287 on-failure: 288 ifneq ($(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*), ) 289 $(PRINTF) "=== Output from failing command(s) repeated here ===\n" 290 $(foreach logfile, $(sort $(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*)), \ 291 $(PRINTF) "* For target $(notdir $(basename $(logfile))):\n" $(NEWLINE) \ 292 $(CAT) $(logfile) | $(GREP) -v -e "^Note: including file:" $(NEWLINE) \ 293 ) 294 $(PRINTF) "=== End of repeated output ===\n" 295 endif 296 if $(GREP) -q "recipe for target .* failed" $(BUILD_LOG) 2> /dev/null; then \ 297 $(PRINTF) "=== Make failure sequence repeated here ===\n" ; \ 298 $(GREP) "recipe for target .* failed" $(BUILD_LOG) ; \ 299 $(PRINTF) "=== End of repeated output ===\n" ; \ 300 $(PRINTF) "Hint: Try searching the build log for the name of the first failed target.\n" ; \ 301 else \ 302 $(PRINTF) "No indication of failed target found.\n" ; \ 303 $(PRINTF) "Hint: Try searching the build log for '] Error'.\n" ; \ 304 fi 305 $(PRINTF) "Hint: If caused by a warning, try configure --disable-warnings-as-errors.\n\n" 306 307 .PHONY: print-targets print-modules reconfigure main on-failure 308endif 309