annotate make/Init.gmk @ 52753:528d904ccf11

refactor and improve performance
author rpressler
date Sun, 25 Nov 2018 16:11:37 +0000
parents 3903ab54107e
children 9e1c9dc23c99
rev   line source
duke@0 1 #
ihse@49568 2 # Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
duke@0 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 #
duke@0 5 # This code is free software; you can redistribute it and/or modify it
duke@0 6 # under the terms of the GNU General Public License version 2 only, as
ohair@5499 7 # published by the Free Software Foundation. Oracle designates this
duke@0 8 # particular file as subject to the "Classpath" exception as provided
ohair@5499 9 # by Oracle in the LICENSE file that accompanied this code.
duke@0 10 #
duke@0 11 # This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 # version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 # accompanied this code).
duke@0 16 #
duke@0 17 # You should have received a copy of the GNU General Public License version
duke@0 18 # 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 #
ohair@5499 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@5499 22 # or visit www.oracle.com if you need additional information or have any
ohair@5499 23 # questions.
duke@0 24 #
duke@0 25
ihse@29662 26 ################################################################################
ihse@29662 27 # This is the bootstrapping part of the build. This file is included from the
ihse@29662 28 # top level Makefile, and is responsible for launching the Main.gmk file with
ihse@29662 29 # the proper make and the proper make arguments.
ihse@29662 30 ################################################################################
ihse@29662 31
ihse@21759 32 # This must be the first rule
ihse@21759 33 default:
ihse@29662 34 .PHONY: default
ohair@13697 35
ihse@21759 36 # Inclusion of this pseudo-target will cause make to execute this file
ihse@29662 37 # serially, regardless of -j.
ihse@21759 38 .NOTPARALLEL:
ihse@21759 39
ihse@29788 40 ifeq ($(HAS_SPEC),)
ihse@29662 41 ##############################################################################
ihse@29788 42 # This is the default mode. We have not been recursively called with a SPEC.
ihse@29662 43 ##############################################################################
ohair@13697 44
ihse@29788 45 # Include our helper functions.
ihse@29788 46 include $(topdir)/make/InitSupport.gmk
ohair@13697 47
ihse@29788 48 # Here are "global" targets, i.e. targets that can be executed without having
ihse@29788 49 # a configuration. This will define ALL_GLOBAL_TARGETS.
ihse@29788 50 include $(topdir)/make/Help.gmk
ohair@13697 51
ihse@29788 52 # Targets provided by Init.gmk.
ihse@32715 53 ALL_INIT_TARGETS := print-modules print-targets print-configuration \
ihse@44027 54 print-tests reconfigure pre-compare-build post-compare-build
ohair@17 55
ihse@29662 56 # CALLED_TARGETS is the list of targets that the user provided,
ihse@29662 57 # or "default" if unspecified.
ihse@29662 58 CALLED_TARGETS := $(if $(MAKECMDGOALS), $(MAKECMDGOALS), default)
ihse@29788 59
ihse@29788 60 # Extract non-global targets that require a spec file.
ihse@29788 61 CALLED_SPEC_TARGETS := $(filter-out $(ALL_GLOBAL_TARGETS), $(CALLED_TARGETS))
ihse@29788 62
ihse@29788 63 # If we have only global targets, or if we are called with -qp (assuming an
ihse@29788 64 # external part, e.g. bash completion, is trying to understand our targets),
ihse@29788 65 # we will skip SPEC location and the sanity checks.
ihse@29788 66 ifeq ($(CALLED_SPEC_TARGETS), )
ihse@29788 67 ONLY_GLOBAL_TARGETS := true
ihse@29788 68 endif
ihse@43653 69 ifeq ($(findstring p, $(MAKEFLAGS))$(findstring q, $(MAKEFLAGS)), pq)
ihse@29788 70 ONLY_GLOBAL_TARGETS := true
ihse@29788 71 endif
ihse@29788 72
ihse@29788 73 ifeq ($(ONLY_GLOBAL_TARGETS), true)
ihse@29788 74 ############################################################################
ihse@29788 75 # We have only global targets, or are called with -pq.
ihse@29788 76 ############################################################################
ihse@29788 77
ihse@29788 78 ifeq ($(wildcard $(SPEC)), )
ihse@29788 79 # If we have no SPEC provided, we will just make a "best effort" target list.
ihse@29788 80 # First try to grab any available pre-existing main-targets.gmk.
ihse@29788 81 main_targets_file := $(firstword $(wildcard $(build_dir)/*/make-support/main-targets.gmk))
ihse@29788 82 ifneq ($(main_targets_file), )
ihse@29788 83 # Extract the SPEC that corresponds to this main-targets.gmk file.
ihse@29788 84 SPEC := $(patsubst %/make-support/main-targets.gmk, %/spec.gmk, $(main_targets_file))
ihse@29788 85 else
ihse@29788 86 # None found, pick an arbitrary SPEC for which to generate a file
ihse@29788 87 SPEC := $(firstword $(all_spec_files))
ihse@29788 88 endif
ihse@29788 89 endif
ihse@29788 90
ihse@29788 91 ifneq ($(wildcard $(SPEC)), )
ihse@29788 92 $(eval $(call DefineMainTargets, LAZY, $(SPEC)))
ihse@29788 93 else
ihse@29788 94 # If we have no configurations we can not provide any main targets.
ihse@29788 95 ALL_MAIN_TARGETS :=
ihse@29788 96 endif
ihse@29788 97
ihse@29788 98 ALL_TARGETS := $(sort $(ALL_GLOBAL_TARGETS) $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS))
ihse@29788 99
ihse@29788 100 # Just list all our targets.
ihse@29788 101 $(ALL_TARGETS):
ihse@29788 102
ihse@29788 103 .PHONY: $(ALL_TARGETS)
ihse@29788 104
ihse@29788 105 else
ihse@29788 106 ############################################################################
ihse@29788 107 # This is the normal case, we have been called from the command line by the
ihse@29788 108 # user and we need to call ourself back with a proper SPEC.
ihse@29788 109 # We have at least one non-global target, so we need to find a spec file.
ihse@29788 110 ############################################################################
ihse@29788 111
ihse@29788 112 # Basic checks on environment and command line.
ihse@29788 113 $(eval $(call CheckControlVariables))
ihse@29788 114 $(eval $(call CheckDeprecatedEnvironment))
ihse@29788 115 $(eval $(call CheckInvalidMakeFlags))
ihse@29788 116
ihse@29788 117 # Check that CONF_CHECK is valid.
ihse@29788 118 $(eval $(call ParseConfCheckOption))
ihse@29788 119
asemenyuk@44465 120 # Check that the LOG given is valid, and set LOG_LEVEL, LOG_NOFILE, MAKE_LOG_VARS and MAKE_LOG_FLAGS.
ihse@29788 121 $(eval $(call ParseLogLevel))
ihse@29788 122
ihse@29788 123 # After this SPECS contain 1..N spec files (otherwise ParseConfAndSpec fails).
ihse@29662 124 $(eval $(call ParseConfAndSpec))
ohair@9618 125
ihse@29788 126 # Extract main targets from Main.gmk using the spec(s) provided. In theory,
ihse@29788 127 # with multiple specs, we should find the intersection of targets provided
ihse@29788 128 # by all specs, but we approximate this by an arbitrary spec from the list.
ihse@29788 129 # This will setup ALL_MAIN_TARGETS.
ihse@29788 130 $(eval $(call DefineMainTargets, FORCE, $(firstword $(SPECS))))
ihse@29788 131
ihse@29788 132 # Separate called targets depending on type.
ihse@29662 133 INIT_TARGETS := $(filter $(ALL_INIT_TARGETS), $(CALLED_SPEC_TARGETS))
ihse@29788 134 MAIN_TARGETS := $(filter $(ALL_MAIN_TARGETS), $(CALLED_SPEC_TARGETS))
ihse@29788 135 SEQUENTIAL_TARGETS := $(filter dist-clean clean%, $(MAIN_TARGETS))
ihse@29788 136 PARALLEL_TARGETS := $(filter-out $(SEQUENTIAL_TARGETS), $(MAIN_TARGETS))
ohair@9618 137
ihse@29662 138 # The spec files depend on the autoconf source code. This check makes sure
ihse@29662 139 # the configuration is up to date after changes to configure.
ihse@47313 140 $(SPECS): $(wildcard $(topdir)/make/autoconf/*) \
ihse@47313 141 $(if $(CUSTOM_CONFIG_DIR), $(wildcard $(CUSTOM_CONFIG_DIR)/*))
ihse@29662 142 ifeq ($(CONF_CHECK), fail)
ihse@47313 143 @echo Error: The configuration is not up to date for \
ihse@47313 144 "'$(lastword $(subst /, , $(dir $@)))'."
ihse@29662 145 $(call PrintConfCheckFailed)
ihse@29662 146 @exit 2
ihse@29662 147 else ifeq ($(CONF_CHECK), auto)
ihse@47313 148 @echo Note: The configuration is not up to date for \
ihse@47313 149 "'$(lastword $(subst /, , $(dir $@)))'."
ihse@29662 150 @( cd $(topdir) && \
ihse@29788 151 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \
ihse@29788 152 SPEC=$@ HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \
ihse@29662 153 reconfigure )
ihse@29662 154 else ifeq ($(CONF_CHECK), ignore)
ihse@29662 155 # Do nothing
ihse@29662 156 endif
chegar@25854 157
ihse@36050 158 # Do not let make delete spec files even if aborted while doing a reconfigure
ihse@36050 159 .PRECIOUS: $(SPECS)
ihse@36050 160
ihse@42300 161 # Unless reconfigure is explicitly called, let all main targets depend on
ihse@29788 162 # the spec files to be up to date.
ihse@29788 163 ifeq ($(findstring reconfigure, $(INIT_TARGETS)), )
ihse@29788 164 $(MAIN_TARGETS): $(SPECS)
chegar@25854 165 endif
chegar@25854 166
ihse@29788 167 make-info:
ihse@29788 168 ifneq ($(findstring $(LOG_LEVEL),info debug trace),)
ihse@29788 169 $(info Running make as '$(strip $(MAKE) $(MFLAGS) \
ihse@29788 170 $(COMMAND_LINE_VARIABLES) $(MAKECMDGOALS))')
ihse@29788 171 endif
ihse@29788 172
ihse@32715 173 MAKE_INIT_WITH_SPEC_ARGUMENTS := ACTUAL_TOPDIR=$(topdir) \
ihse@32715 174 USER_MAKE_VARS="$(USER_MAKE_VARS)" MAKE_LOG_FLAGS=$(MAKE_LOG_FLAGS) \
asemenyuk@44465 175 $(MAKE_LOG_VARS) \
ihse@32715 176 INIT_TARGETS="$(INIT_TARGETS)" \
ihse@32715 177 SEQUENTIAL_TARGETS="$(SEQUENTIAL_TARGETS)" \
ihse@32715 178 PARALLEL_TARGETS="$(PARALLEL_TARGETS)"
ihse@32715 179
ihse@29788 180 # Now the init and main targets will be called, once for each SPEC. The
ihse@29788 181 # recipe will be run once for every target specified, but we only want to
ihse@29788 182 # execute the recipe a single time, hence the TARGET_DONE with a dummy
ihse@29788 183 # command if true.
ihse@32715 184 # The COMPARE_BUILD part implements special support for makefile development.
ihse@29788 185 $(ALL_INIT_TARGETS) $(ALL_MAIN_TARGETS): make-info
ihse@29662 186 @$(if $(TARGET_DONE), \
ihse@29662 187 true \
ihse@29662 188 , \
ihse@32715 189 ( cd $(topdir) && \
ihse@29662 190 $(foreach spec, $(SPECS), \
ihse@29788 191 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \
ihse@32715 192 SPEC=$(spec) HAS_SPEC=true $(MAKE_INIT_WITH_SPEC_ARGUMENTS) \
ihse@32715 193 main && \
ihse@32715 194 $(if $(and $(COMPARE_BUILD), $(PARALLEL_TARGETS)), \
ihse@32715 195 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \
ihse@32715 196 SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \
ihse@32715 197 COMPARE_BUILD="$(COMPARE_BUILD)" pre-compare-build && \
ihse@32715 198 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \
ihse@32715 199 SPEC=$(spec) HAS_SPEC=true $(MAKE_INIT_WITH_SPEC_ARGUMENTS) \
ihse@32715 200 COMPARE_BUILD="$(COMPARE_BUILD)" main && \
ihse@32715 201 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \
ihse@32715 202 SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \
ihse@32715 203 COMPARE_BUILD="$(COMPARE_BUILD)" post-compare-build && \
ihse@32715 204 ) \
ihse@32715 205 ) true ) \
ihse@29662 206 $(eval TARGET_DONE=true) \
ihse@29662 207 )
erikj@26398 208
ihse@29662 209 .PHONY: $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS)
ihse@29662 210
ihse@29788 211 endif # $(ONLY_GLOBAL_TARGETS)!=true
ihse@29662 212
ihse@29662 213 else # HAS_SPEC=true
ihse@29662 214
ihse@29662 215 ##############################################################################
ihse@29662 216 # Now we have a spec. This part provides the "main" target that acts as a
ihse@29662 217 # trampoline to call the Main.gmk with the value of $(MAKE) found in the spec
ihse@29662 218 # file.
ihse@29662 219 ##############################################################################
ihse@29662 220
ihse@29788 221 include $(SPEC)
ihse@29788 222
ihse@29788 223 # Our helper functions.
ihse@29788 224 include $(TOPDIR)/make/InitSupport.gmk
ihse@29788 225
ihse@32715 226 # Parse COMPARE_BUILD (for makefile development)
ihse@32715 227 $(eval $(call ParseCompareBuild))
ihse@32715 228
ihse@49568 229 # If no LOG= was given on command line, but we have a non-standard default
ihse@49568 230 # value, use that instead and re-parse log level.
ihse@49568 231 ifeq ($(LOG), )
ihse@49568 232 ifneq ($(DEFAULT_LOG), )
ihse@49568 233 override LOG := $(DEFAULT_LOG)
ihse@49568 234 $(eval $(call ParseLogLevel))
ihse@49568 235 endif
ihse@49568 236 endif
ihse@49568 237
ihse@29662 238 ifeq ($(LOG_NOFILE), true)
erikj@35008 239 # Disable build log if LOG=[level,]nofile was given
erikj@35008 240 override BUILD_LOG_PIPE :=
ihse@29662 241 endif
ihse@29662 242
ihse@51715 243 ifeq ($(filter dist-clean, $(SEQUENTIAL_TARGETS)), dist-clean)
ihse@51715 244 # We can't have a log file if we're about to remove it.
ihse@51715 245 override BUILD_LOG_PIPE :=
ihse@51715 246 endif
ihse@51715 247
ihse@29662 248 ifeq ($(OUTPUT_SYNC_SUPPORTED), true)
ihse@29662 249 OUTPUT_SYNC_FLAG := -O$(OUTPUT_SYNC)
ihse@29662 250 endif
ihse@29662 251
ihse@29788 252 ##############################################################################
ihse@29788 253 # Init targets
ihse@29788 254 ##############################################################################
ihse@29788 255
ihse@29788 256 print-modules:
ihse@29788 257 ( cd $(TOPDIR) && \
ihse@29788 258 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
ihse@29788 259 NO_RECIPES=true print-modules )
ihse@29788 260
ihse@29788 261 print-targets:
ihse@29788 262 ( cd $(TOPDIR) && \
ihse@29788 263 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
ihse@29788 264 NO_RECIPES=true print-targets )
ihse@29662 265
ihse@44027 266 print-tests:
ihse@44027 267 ( cd $(TOPDIR) && \
ihse@44027 268 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
ihse@44027 269 NO_RECIPES=true print-tests )
ihse@44027 270
ihse@32461 271 print-configuration:
ihse@32461 272 $(ECHO) $(CONFIGURE_COMMAND_LINE)
ihse@32461 273
ihse@29662 274 reconfigure:
ihse@29662 275 ifneq ($(CONFIGURE_COMMAND_LINE), )
ihse@29662 276 $(ECHO) "Re-running configure using arguments '$(CONFIGURE_COMMAND_LINE)'"
ihse@29662 277 else
ihse@29662 278 $(ECHO) "Re-running configure using default settings"
ihse@29662 279 endif
ihse@47253 280 ( cd $(OUTPUTDIR) && PATH="$(ORIGINAL_PATH)" \
ihse@47346 281 CUSTOM_ROOT="$(CUSTOM_ROOT)" \
ihse@47313 282 CUSTOM_CONFIG_DIR="$(CUSTOM_CONFIG_DIR)" \
ihse@47346 283 $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) )
ihse@29662 284
ihse@29788 285 ##############################################################################
ihse@29788 286 # The main target, for delegating into Main.gmk
ihse@29788 287 ##############################################################################
ihse@29662 288
ihse@32715 289 MAIN_TARGETS := $(SEQUENTIAL_TARGETS) $(PARALLEL_TARGETS) $(COMPARE_BUILD_MAKE)
erikj@37649 290 # If building the default target, add what they are to the description.
erikj@37649 291 DESCRIPTION_TARGETS := $(strip $(MAIN_TARGETS))
erikj@37649 292 ifeq ($(DESCRIPTION_TARGETS), default)
erikj@37649 293 DESCRIPTION_TARGETS += ($(DEFAULT_MAKE_TARGET))
erikj@37649 294 endif
ihse@29788 295 TARGET_DESCRIPTION := target$(if $(word 2, $(MAIN_TARGETS)),s) \
erikj@37649 296 '$(strip $(DESCRIPTION_TARGETS))' in configuration '$(CONF_NAME)'
ihse@29662 297
ihse@29662 298 # MAKEOVERRIDES is automatically set and propagated by Make to sub-Make calls.
ihse@29662 299 # We need to clear it of the init-specific variables. The user-specified
ihse@42300 300 # variables are explicitly propagated using $(USER_MAKE_VARS).
ihse@29662 301 main: MAKEOVERRIDES :=
ihse@29662 302
ihse@29788 303 main: $(INIT_TARGETS)
ihse@29788 304 ifneq ($(SEQUENTIAL_TARGETS)$(PARALLEL_TARGETS), )
ihse@29788 305 $(call RotateLogFiles)
erikj@35008 306 $(PRINTF) "Building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE)
ihse@29788 307 ifneq ($(SEQUENTIAL_TARGETS), )
ihse@29788 308 # Don't touch build output dir since we might be cleaning. That
erikj@35008 309 # means no log pipe.
ihse@29788 310 ( cd $(TOPDIR) && \
ihse@29788 311 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
ihse@29788 312 $(SEQUENTIAL_TARGETS) )
ihse@29788 313 endif
ihse@29788 314 ifneq ($(PARALLEL_TARGETS), )
ihse@50562 315 $(call PrepareFailureLogs)
ihse@29788 316 $(call StartGlobalTimer)
ihse@29788 317 $(call PrepareSmartJavac)
sgehwolf@49841 318 # JOBS will only be empty for a bootcycle-images recursive call
sgehwolf@49841 319 # or if specified via a make argument directly. In those cases
sgehwolf@49841 320 # treat it as NOT using jobs at all.
ihse@29788 321 ( cd $(TOPDIR) && \
erikj@35008 322 $(NICE) $(MAKE) $(MAKE_ARGS) $(OUTPUT_SYNC_FLAG) \
sgehwolf@49841 323 $(if $(JOBS), -j $(JOBS)) \
sgehwolf@49841 324 -f make/Main.gmk $(USER_MAKE_VARS) \
erikj@35008 325 $(PARALLEL_TARGETS) $(COMPARE_BUILD_MAKE) $(BUILD_LOG_PIPE) || \
erikj@35008 326 ( exitcode=$$? && \
erikj@35008 327 $(PRINTF) "\nERROR: Build failed for $(TARGET_DESCRIPTION) (exit code $$exitcode) \n" \
erikj@35008 328 $(BUILD_LOG_PIPE) && \
ihse@32344 329 cd $(TOPDIR) && $(MAKE) $(MAKE_ARGS) -j 1 -f make/Init.gmk \
ihse@32344 330 HAS_SPEC=true on-failure ; \
ihse@32344 331 exit $$exitcode ) )
ihse@29788 332 $(call CleanupSmartJavac)
ihse@29788 333 $(call StopGlobalTimer)
ihse@29788 334 $(call ReportBuildTimes)
ihse@29788 335 endif
ihse@44027 336 if test -f $(MAKESUPPORT_OUTPUTDIR)/exit-with-error ; then \
ihse@44027 337 exit 1 ; \
ihse@44027 338 fi
erikj@35008 339 $(PRINTF) "Finished building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE)
asemenyuk@44465 340 $(call ReportProfileTimes)
erikj@26398 341 endif
chegar@25854 342
ihse@32344 343 on-failure:
erikj@40621 344 $(call CleanupSmartJavac)
erikj@40621 345 $(call StopGlobalTimer)
erikj@40621 346 $(call ReportBuildTimes)
ihse@33572 347 $(call PrintFailureReports)
ihse@33572 348 $(call PrintBuildLogFailures)
asemenyuk@44465 349 $(call ReportProfileTimes)
ihse@47928 350 $(PRINTF) "Hint: See doc/building.html#troubleshooting for assistance.\n\n"
ihse@33572 351 ifneq ($(COMPARE_BUILD), )
ihse@33572 352 $(call CleanupCompareBuild)
ihse@32344 353 endif
ihse@32344 354
ihse@32715 355 # Support targets for COMPARE_BUILD, used for makefile development
ihse@32715 356 pre-compare-build:
ihse@35370 357 $(call WaitForSmartJavacFinish)
ihse@33572 358 $(call PrepareCompareBuild)
ihse@32715 359
ihse@32715 360 post-compare-build:
erikj@35744 361 $(call WaitForSmartJavacFinish)
ihse@33572 362 $(call CleanupCompareBuild)
ihse@33572 363 $(call CompareBuildDoComparison)
ihse@32715 364
ihse@32344 365 .PHONY: print-targets print-modules reconfigure main on-failure
ohair@874 366 endif