Init.gmk revision 1410:e805c9330c7a
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 40# If included from the top-level Makefile then topdir is set, but not when 41# recursively calling ourself with a spec. 42ifeq ($(topdir),) 43 topdir := $(strip $(patsubst %/make/, %, $(dir $(lastword $(MAKEFILE_LIST))))) 44endif 45 46# Our helper functions. Will include $(SPEC) if $(HAS_SPEC) is true. 47include $(topdir)/make/InitSupport.gmk 48 49# Here are "global" targets, i.e. targets that can be executed without having a configuration. 50# This will define ALL_GLOBAL_TARGETS. 51include $(topdir)/make/Help.gmk 52 53# Extract main targets from Main.gmk. 54ifneq ($(any_spec_file), ) 55 ifeq ($(wildcard $(dir $(any_spec_file))/make-support),) 56 # If make-support does not exist, we need to build the genmodules java tool first. 57 $(info Creating data for first make execution in new configuration...) 58 ignore_output := $(shell $(MAKE) -r -R -f $(topdir)/make/Main.gmk \ 59 -I $(topdir)/make/common SPEC=$(any_spec_file) NO_RECIPES=true FRC) 60 $(info Done) 61 endif 62 ALL_MAIN_TARGETS := $(shell $(MAKE) -r -R -f $(topdir)/make/Main.gmk \ 63 -I $(topdir)/make/common SPEC=$(any_spec_file) NO_RECIPES=true print-targets) 64else 65 # Without at least a single valid configuration, we cannot extract any real 66 # targets. To provide a helpful error message about the missing configuration 67 # later on, accept whatever targets the user has provided for now. 68 ALL_MAIN_TARGETS := $(if $(MAKECMDGOALS), $(MAKECMDGOALS), default) 69endif 70 71# Targets provided by this file. 72ALL_INIT_TARGETS := reconfigure 73 74ALL_TARGETS := $(sort $(ALL_GLOBAL_TARGETS) $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS)) 75 76ifneq ($(findstring qp, $(MAKEFLAGS)),) 77 ############################################################################## 78 # When called with -qp, assume an external part (e.g. bash completion) is trying 79 # to understand our targets. Just list our targets and do no more checking. 80 ############################################################################## 81 82 $(ALL_TARGETS): 83 84 .PHONY: $(ALL_TARGETS) 85 86else ifeq ($(HAS_SPEC),) 87 88 ############################################################################## 89 # This is the normal case, we have been called from the command line by the 90 # user and we need to call ourself back with a proper SPEC. 91 ############################################################################## 92 93 $(eval $(call CheckControlVariables)) 94 $(eval $(call CheckDeprecatedEnvironment)) 95 $(eval $(call CheckInvalidMakeFlags)) 96 97 $(eval $(call ParseConfCheckOption)) 98 99 # Check that the LOG given is valid, and set LOG_LEVEL, LOG_NOFILE and MAKE_LOG_FLAGS. 100 $(eval $(call ParseLogLevel)) 101 102 ifneq ($(findstring $(LOG_LEVEL),info debug trace),) 103 $(info Running make as '$(strip $(MAKE) $(MFLAGS) $(COMMAND_LINE_VARIABLES) $(MAKECMDGOALS))') 104 endif 105 106 # CALLED_TARGETS is the list of targets that the user provided, 107 # or "default" if unspecified. 108 CALLED_TARGETS := $(if $(MAKECMDGOALS), $(MAKECMDGOALS), default) 109 CALLED_SPEC_TARGETS := $(filter $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS), $(CALLED_TARGETS)) 110 ifneq ($(CALLED_SPEC_TARGETS),) 111 # We have at least one non-global target, which need a SPEC 112 $(eval $(call ParseConfAndSpec)) 113 # Now SPECS contain 1..N spec files (otherwise ParseConfAndSpec fails) 114 115 INIT_TARGETS := $(filter $(ALL_INIT_TARGETS), $(CALLED_SPEC_TARGETS)) 116 SEQUENTIAL_TARGETS := $(filter dist-clean clean%, $(CALLED_SPEC_TARGETS)) 117 PARALLEL_TARGETS := $(filter-out $(INIT_TARGETS) $(SEQUENTIAL_TARGETS), $(CALLED_SPEC_TARGETS)) 118 119 # The spec files depend on the autoconf source code. This check makes sure 120 # the configuration is up to date after changes to configure. 121 $(SPECS): $(wildcard $(topdir)/common/autoconf/*) 122 ifeq ($(CONF_CHECK), fail) 123 @echo "Error: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'." 124 $(call PrintConfCheckFailed) 125 @exit 2 126 else ifeq ($(CONF_CHECK), auto) 127 @echo "Note: The configuration is not up to date for '$(lastword $(subst /, , $(dir $@)))'." 128 @( cd $(topdir) && \ 129 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -f $(topdir)/make/Init.gmk SPEC=$@ HAS_SPEC=true \ 130 reconfigure ) 131 else ifeq ($(CONF_CHECK), ignore) 132 # Do nothing 133 endif 134 135 # Unless reconfigure is explicitely called, let all targets depend on the spec files to be up to date. 136 ifeq ($(findstring reconfigure, $(CALLED_SPEC_TARGETS)), ) 137 $(CALLED_SPEC_TARGETS): $(SPECS) 138 endif 139 140 # The recipe will be run once for every target specified, but we only want to execute the 141 # recipe a single time, hence the TARGET_DONE with a dummy command if true. 142 $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS): 143 @$(if $(TARGET_DONE), \ 144 true \ 145 , \ 146 $(foreach spec, $(SPECS), \ 147 ( cd $(topdir) && \ 148 $(MAKE) $(MFLAGS) $(MAKE_LOG_FLAGS) -j 1 -f $(topdir)/make/Init.gmk \ 149 SPEC=$(spec) HAS_SPEC=true \ 150 USER_MAKE_VARS="$(USER_MAKE_VARS)" MAKE_LOG_FLAGS=$(MAKE_LOG_FLAGS) \ 151 LOG_LEVEL=$(LOG_LEVEL) LOG_NOFILE=$(LOG_NOFILE) \ 152 INIT_TARGETS="$(INIT_TARGETS)" SEQUENTIAL_TARGETS="$(SEQUENTIAL_TARGETS)" \ 153 PARALLEL_TARGETS="$(PARALLEL_TARGETS)" \ 154 main ) && \ 155 ) true \ 156 $(eval TARGET_DONE=true) \ 157 ) 158 159 .PHONY: $(ALL_MAIN_TARGETS) $(ALL_INIT_TARGETS) 160 161 endif # has $(CALLED_SPEC_TARGETS) 162 163else # HAS_SPEC=true 164 165 ############################################################################## 166 # Now we have a spec. This part provides the "main" target that acts as a 167 # trampoline to call the Main.gmk with the value of $(MAKE) found in the spec 168 # file. 169 ############################################################################## 170 171 ifeq ($(LOG_NOFILE), true) 172 # Disable log wrapper if LOG=[level,]nofile was given 173 override BUILD_LOG_WRAPPER := 174 endif 175 176 ifeq ($(OUTPUT_SYNC_SUPPORTED), true) 177 OUTPUT_SYNC_FLAG := -O$(OUTPUT_SYNC) 178 endif 179 180 $(eval $(call CheckSpecSanity)) 181 182 reconfigure: 183 ifneq ($(CONFIGURE_COMMAND_LINE), ) 184 $(ECHO) "Re-running configure using arguments '$(CONFIGURE_COMMAND_LINE)'" 185 else 186 $(ECHO) "Re-running configure using default settings" 187 endif 188 ( cd $(OUTPUT_ROOT) && PATH="$(ORIGINAL_PATH)" \ 189 $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) ) 190 191 main-init: 192 $(call RotateLogFiles) 193 $(BUILD_LOG_WRAPPER) $(PRINTF) "Building target(s) '$(strip \ 194 $(INIT_TARGETS) $(SEQUENTIAL_TARGETS) $(PARALLEL_TARGETS) \ 195 )' in configuration '$(CONF_NAME)'\n" 196 197 198 # MAKEOVERRIDES is automatically set and propagated by Make to sub-Make calls. 199 # We need to clear it of the init-specific variables. The user-specified 200 # variables are explicitely propagated using $(USER_MAKE_VARS). 201 main: MAKEOVERRIDES := 202 203 main: $(INIT_TARGETS) main-init 204 ifneq ($(SEQUENTIAL_TARGETS), ) 205 # Don't touch build output dir since we might be cleaning. That means 206 # no log wrapper. 207 ( cd $(TOPDIR) && \ 208 $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \ 209 $(SEQUENTIAL_TARGETS) \ 210 ) 211 endif 212 ifneq ($(PARALLEL_TARGETS), ) 213 $(call StartGlobalTimer) 214 $(call PrepareSmartJavac) 215 ( cd $(TOPDIR) && \ 216 $(BUILD_LOG_WRAPPER) $(MAKE) $(MAKE_ARGS) $(OUTPUT_SYNC_FLAG) \ 217 -j $(JOBS) -f make/Main.gmk $(USER_MAKE_VARS) \ 218 $(PARALLEL_TARGETS) \ 219 ) 220 $(call CleanupSmartJavac) 221 $(call StopGlobalTimer) 222 $(call ReportBuildTimes) 223 endif 224 $(BUILD_LOG_WRAPPER) $(PRINTF) "Finished building target(s) '$(strip \ 225 $(INIT_TARGETS) $(SEQUENTIAL_TARGETS) $(PARALLEL_TARGETS) \ 226 )' in configuration '$(CONF_NAME)'\n" 227 228 .PHONY: reconfigure main-init main 229endif 230