annotate make/Init.gmk @ 1427:f658baecb743

8076465: New Init.gmk needs improvements Reviewed-by: erikj, tbell
author ihse
date Tue, 07 Apr 2015 09:06:24 +0200
parents f077ae77feb1
children cfd05cc6c27b
rev   line source
duke@0 1 #
ihse@1410 2 # Copyright (c) 2012, 2015, 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@180 7 # published by the Free Software Foundation. Oracle designates this
duke@0 8 # particular file as subject to the "Classpath" exception as provided
ohair@180 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@180 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@180 22 # or visit www.oracle.com if you need additional information or have any
ohair@180 23 # questions.
duke@0 24 #
duke@0 25
ihse@1410 26 ################################################################################
ihse@1410 27 # This is the bootstrapping part of the build. This file is included from the
ihse@1410 28 # top level Makefile, and is responsible for launching the Main.gmk file with
ihse@1410 29 # the proper make and the proper make arguments.
ihse@1410 30 ################################################################################
ihse@1410 31
ihse@910 32 # This must be the first rule
ihse@910 33 default:
ihse@1410 34 .PHONY: default
ohair@476 35
ihse@910 36 # Inclusion of this pseudo-target will cause make to execute this file
ihse@1410 37 # serially, regardless of -j.
ihse@910 38 .NOTPARALLEL:
ihse@910 39
ihse@1427 40 ifeq ($(HAS_SPEC),)
ihse@1410 41 ##############################################################################
ihse@1427 42 # This is the default mode. We have not been recursively called with a SPEC.
ihse@1410 43 ##############################################################################
ohair@476 44
ihse@1427 45 # Include our helper functions.
ihse@1427 46 include $(topdir)/make/InitSupport.gmk
ohair@476 47
ihse@1427 48 # Here are "global" targets, i.e. targets that can be executed without having
ihse@1427 49 # a configuration. This will define ALL_GLOBAL_TARGETS.
ihse@1427 50 include $(topdir)/make/Help.gmk
ohair@476 51
ihse@1427 52 # Targets provided by Init.gmk.
ihse@1427 53 ALL_INIT_TARGETS := print-modules print-targets reconfigure
ohair@5 54
ihse@1410 55 # CALLED_TARGETS is the list of targets that the user provided,
ihse@1410 56 # or "default" if unspecified.
ihse@1410 57 CALLED_TARGETS := $(if $(MAKECMDGOALS), $(MAKECMDGOALS), default)
ihse@1427 58
ihse@1427 59 # Extract non-global targets that require a spec file.
ihse@1427 60 CALLED_SPEC_TARGETS := $(filter-out $(ALL_GLOBAL_TARGETS), $(CALLED_TARGETS))
ihse@1427 61
ihse@1427 62 # If we have only global targets, or if we are called with -qp (assuming an
ihse@1427 63 # external part, e.g. bash completion, is trying to understand our targets),
ihse@1427 64 # we will skip SPEC location and the sanity checks.
ihse@1427 65 ifeq ($(CALLED_SPEC_TARGETS), )
ihse@1427 66 ONLY_GLOBAL_TARGETS := true
ihse@1427 67 endif
ihse@1427 68 ifneq ($(findstring qp, $(MAKEFLAGS)),)
ihse@1427 69 ONLY_GLOBAL_TARGETS := true
ihse@1427 70 endif
ihse@1427 71
ihse@1427 72 ifeq ($(ONLY_GLOBAL_TARGETS), true)
ihse@1427 73 ############################################################################
ihse@1427 74 # We have only global targets, or are called with -pq.
ihse@1427 75 ############################################################################
ihse@1427 76
ihse@1427 77 ifeq ($(wildcard $(SPEC)), )
ihse@1427 78 # If we have no SPEC provided, we will just make a "best effort" target list.
ihse@1427 79 # First try to grab any available pre-existing main-targets.gmk.
ihse@1427 80 main_targets_file := $(firstword $(wildcard $(build_dir)/*/make-support/main-targets.gmk))
ihse@1427 81 ifneq ($(main_targets_file), )
ihse@1427 82 # Extract the SPEC that corresponds to this main-targets.gmk file.
ihse@1427 83 SPEC := $(patsubst %/make-support/main-targets.gmk, %/spec.gmk, $(main_targets_file))
ihse@1427 84 else
ihse@1427 85 # None found, pick an arbitrary SPEC for which to generate a file
ihse@1427 86 SPEC := $(firstword $(all_spec_files))
ihse@1427 87 endif
ihse@1427 88 endif
ihse@1427 89
ihse@1427 90 ifneq ($(wildcard $(SPEC)), )
ihse@1427 91 $(eval $(call DefineMainTargets, LAZY, $(SPEC)))
ihse@1427 92 else
ihse@1427 93 # If we have no configurations we can not provide any main targets.
ihse@1427 94 ALL_MAIN_TARGETS :=
ihse@1427 95 endif
ihse@1427 96
ihse@1427 97 ALL_TARGETS := $(sort $(ALL_GLOBAL_TARGETS) $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS))
ihse@1427 98
ihse@1427 99 # Just list all our targets.
ihse@1427 100 $(ALL_TARGETS):
ihse@1427 101
ihse@1427 102 .PHONY: $(ALL_TARGETS)
ihse@1427 103
ihse@1427 104 else
ihse@1427 105 ############################################################################
ihse@1427 106 # This is the normal case, we have been called from the command line by the
ihse@1427 107 # user and we need to call ourself back with a proper SPEC.
ihse@1427 108 # We have at least one non-global target, so we need to find a spec file.
ihse@1427 109 ############################################################################
ihse@1427 110
ihse@1427 111 # Basic checks on environment and command line.
ihse@1427 112 $(eval $(call CheckControlVariables))
ihse@1427 113 $(eval $(call CheckDeprecatedEnvironment))
ihse@1427 114 $(eval $(call CheckInvalidMakeFlags))
ihse@1427 115
ihse@1427 116 # Check that CONF_CHECK is valid.
ihse@1427 117 $(eval $(call ParseConfCheckOption))
ihse@1427 118
ihse@1427 119 # Check that the LOG given is valid, and set LOG_LEVEL, LOG_NOFILE and MAKE_LOG_FLAGS.
ihse@1427 120 $(eval $(call ParseLogLevel))
ihse@1427 121
ihse@1427 122 # After this SPECS contain 1..N spec files (otherwise ParseConfAndSpec fails).
ihse@1410 123 $(eval $(call ParseConfAndSpec))
ohair@338 124
ihse@1427 125 # Extract main targets from Main.gmk using the spec(s) provided. In theory,
ihse@1427 126 # with multiple specs, we should find the intersection of targets provided
ihse@1427 127 # by all specs, but we approximate this by an arbitrary spec from the list.
ihse@1427 128 # This will setup ALL_MAIN_TARGETS.
ihse@1427 129 $(eval $(call DefineMainTargets, FORCE, $(firstword $(SPECS))))
ihse@1427 130
ihse@1427 131 # Separate called targets depending on type.
ihse@1410 132 INIT_TARGETS := $(filter $(ALL_INIT_TARGETS), $(CALLED_SPEC_TARGETS))
ihse@1427 133 MAIN_TARGETS := $(filter $(ALL_MAIN_TARGETS), $(CALLED_SPEC_TARGETS))
ihse@1427 134 SEQUENTIAL_TARGETS := $(filter dist-clean clean%, $(MAIN_TARGETS))
ihse@1427 135 PARALLEL_TARGETS := $(filter-out $(SEQUENTIAL_TARGETS), $(MAIN_TARGETS))
ohair@338 136
ihse@1410 137 # The spec files depend on the autoconf source code. This check makes sure
ihse@1410 138 # the configuration is up to date after changes to configure.
ihse@1410 139 $(SPECS): $(wildcard $(topdir)/common/autoconf/*)
ihse@1410 140 ifeq ($(CONF_CHECK), fail)
ihse@1410 141 @echo "Error: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'."
ihse@1410 142 $(call PrintConfCheckFailed)
ihse@1410 143 @exit 2
ihse@1410 144 else ifeq ($(CONF_CHECK), auto)
ihse@1410 145 @echo "Note: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'."
ihse@1410 146 @( cd $(topdir) && \
ihse@1427 147 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -f $(topdir)/make/Init.gmk \
ihse@1427 148 SPEC=$@ HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \
ihse@1410 149 reconfigure )
ihse@1410 150 else ifeq ($(CONF_CHECK), ignore)
ihse@1410 151 # Do nothing
ihse@1410 152 endif
chegar@1122 153
ihse@1427 154 # Unless reconfigure is explicitely called, let all main targets depend on
ihse@1427 155 # the spec files to be up to date.
ihse@1427 156 ifeq ($(findstring reconfigure, $(INIT_TARGETS)), )
ihse@1427 157 $(MAIN_TARGETS): $(SPECS)
chegar@1122 158 endif
chegar@1122 159
ihse@1427 160 make-info:
ihse@1427 161 ifneq ($(findstring $(LOG_LEVEL),info debug trace),)
ihse@1427 162 $(info Running make as '$(strip $(MAKE) $(MFLAGS) \
ihse@1427 163 $(COMMAND_LINE_VARIABLES) $(MAKECMDGOALS))')
ihse@1427 164 endif
ihse@1427 165
ihse@1427 166 # Now the init and main targets will be called, once for each SPEC. The
ihse@1427 167 # recipe will be run once for every target specified, but we only want to
ihse@1427 168 # execute the recipe a single time, hence the TARGET_DONE with a dummy
ihse@1427 169 # command if true.
ihse@1427 170 $(ALL_INIT_TARGETS) $(ALL_MAIN_TARGETS): make-info
ihse@1410 171 @$(if $(TARGET_DONE), \
ihse@1410 172 true \
ihse@1410 173 , \
ihse@1410 174 $(foreach spec, $(SPECS), \
ihse@1410 175 ( cd $(topdir) && \
ihse@1427 176 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -r -R -j 1 -f $(topdir)/make/Init.gmk \
ihse@1427 177 SPEC=$(spec) HAS_SPEC=true ACTUAL_TOPDIR=$(topdir) \
ihse@1410 178 USER_MAKE_VARS="$(USER_MAKE_VARS)" MAKE_LOG_FLAGS=$(MAKE_LOG_FLAGS) \
ihse@1410 179 LOG_LEVEL=$(LOG_LEVEL) LOG_NOFILE=$(LOG_NOFILE) \
ihse@1427 180 INIT_TARGETS="$(INIT_TARGETS)" \
ihse@1427 181 SEQUENTIAL_TARGETS="$(SEQUENTIAL_TARGETS)" \
ihse@1410 182 PARALLEL_TARGETS="$(PARALLEL_TARGETS)" \
ihse@1410 183 main ) && \
ihse@1410 184 ) true \
ihse@1410 185 $(eval TARGET_DONE=true) \
ihse@1410 186 )
erikj@1149 187
ihse@1410 188 .PHONY: $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS)
ihse@1410 189
ihse@1427 190 endif # $(ONLY_GLOBAL_TARGETS)!=true
ihse@1410 191
ihse@1410 192 else # HAS_SPEC=true
ihse@1410 193
ihse@1410 194 ##############################################################################
ihse@1410 195 # Now we have a spec. This part provides the "main" target that acts as a
ihse@1410 196 # trampoline to call the Main.gmk with the value of $(MAKE) found in the spec
ihse@1410 197 # file.
ihse@1410 198 ##############################################################################
ihse@1410 199
ihse@1427 200 include $(SPEC)
ihse@1427 201
ihse@1427 202 # Our helper functions.
ihse@1427 203 include $(TOPDIR)/make/InitSupport.gmk
ihse@1427 204
ihse@1427 205 # Verify that the spec file we included seems okay.
ihse@1427 206 $(eval $(call CheckSpecSanity))
ihse@1427 207
ihse@1410 208 ifeq ($(LOG_NOFILE), true)
ihse@1410 209 # Disable log wrapper if LOG=[level,]nofile was given
ihse@1410 210 override BUILD_LOG_WRAPPER :=
ihse@1410 211 endif
ihse@1410 212
ihse@1410 213 ifeq ($(OUTPUT_SYNC_SUPPORTED), true)
ihse@1410 214 OUTPUT_SYNC_FLAG := -O$(OUTPUT_SYNC)
ihse@1410 215 endif
ihse@1410 216
ihse@1427 217 ##############################################################################
ihse@1427 218 # Init targets
ihse@1427 219 ##############################################################################
ihse@1427 220
ihse@1427 221 print-modules:
ihse@1427 222 ( cd $(TOPDIR) && \
ihse@1427 223 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
ihse@1427 224 NO_RECIPES=true print-modules )
ihse@1427 225
ihse@1427 226 print-targets:
ihse@1427 227 ( cd $(TOPDIR) && \
ihse@1427 228 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
ihse@1427 229 NO_RECIPES=true print-targets )
ihse@1410 230
ihse@1410 231 reconfigure:
ihse@1410 232 ifneq ($(CONFIGURE_COMMAND_LINE), )
ihse@1410 233 $(ECHO) "Re-running configure using arguments '$(CONFIGURE_COMMAND_LINE)'"
ihse@1410 234 else
ihse@1410 235 $(ECHO) "Re-running configure using default settings"
ihse@1410 236 endif
ihse@1410 237 ( cd $(OUTPUT_ROOT) && PATH="$(ORIGINAL_PATH)" \
ihse@1410 238 $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) )
ihse@1410 239
ihse@1427 240 ##############################################################################
ihse@1427 241 # The main target, for delegating into Main.gmk
ihse@1427 242 ##############################################################################
ihse@1410 243
ihse@1427 244 MAIN_TARGETS := $(SEQUENTIAL_TARGETS) $(PARALLEL_TARGETS)
ihse@1427 245 TARGET_DESCRIPTION := target$(if $(word 2, $(MAIN_TARGETS)),s) \
ihse@1427 246 '$(strip $(MAIN_TARGETS))' in configuration '$(CONF_NAME)'
ihse@1410 247
ihse@1410 248 # MAKEOVERRIDES is automatically set and propagated by Make to sub-Make calls.
ihse@1410 249 # We need to clear it of the init-specific variables. The user-specified
ihse@1410 250 # variables are explicitely propagated using $(USER_MAKE_VARS).
ihse@1410 251 main: MAKEOVERRIDES :=
ihse@1410 252
ihse@1427 253 main: $(INIT_TARGETS)
ihse@1427 254 ifneq ($(SEQUENTIAL_TARGETS)$(PARALLEL_TARGETS), )
ihse@1427 255 $(call RotateLogFiles)
ihse@1427 256 $(BUILD_LOG_WRAPPER) $(PRINTF) "Building $(TARGET_DESCRIPTION)\n"
ihse@1427 257 ifneq ($(SEQUENTIAL_TARGETS), )
ihse@1427 258 # Don't touch build output dir since we might be cleaning. That
ihse@1427 259 # means no log wrapper.
ihse@1427 260 ( cd $(TOPDIR) && \
ihse@1427 261 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
ihse@1427 262 $(SEQUENTIAL_TARGETS) )
ihse@1427 263 endif
ihse@1427 264 ifneq ($(PARALLEL_TARGETS), )
ihse@1427 265 $(call StartGlobalTimer)
ihse@1427 266 $(call PrepareSmartJavac)
ihse@1427 267 ( cd $(TOPDIR) && \
ihse@1427 268 $(BUILD_LOG_WRAPPER) $(MAKE) $(MAKE_ARGS) $(OUTPUT_SYNC_FLAG) \
ihse@1427 269 -j $(JOBS) -f make/Main.gmk $(USER_MAKE_VARS) \
ihse@1427 270 $(PARALLEL_TARGETS) )
ihse@1427 271 $(call CleanupSmartJavac)
ihse@1427 272 $(call StopGlobalTimer)
ihse@1427 273 $(call ReportBuildTimes)
ihse@1427 274 endif
ihse@1427 275 $(BUILD_LOG_WRAPPER) $(PRINTF) "Finished building $(TARGET_DESCRIPTION)\n"
erikj@1149 276 endif
chegar@1122 277
ihse@1427 278 .PHONY: print-targets print-modules reconfigure main
ohair@27 279 endif