Tue, 18 Sep 2012 11:29:16 -0700
7197849: Update new build-infra makefiles
Reviewed-by: ihse, erikj, ohrstrom, tbell
erikj@459 | 1 | # |
erikj@459 | 2 | # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
erikj@459 | 3 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
erikj@459 | 4 | # |
erikj@459 | 5 | # This code is free software; you can redistribute it and/or modify it |
erikj@459 | 6 | # under the terms of the GNU General Public License version 2 only, as |
erikj@459 | 7 | # published by the Free Software Foundation. Oracle designates this |
erikj@459 | 8 | # particular file as subject to the "Classpath" exception as provided |
erikj@459 | 9 | # by Oracle in the LICENSE file that accompanied this code. |
erikj@459 | 10 | # |
erikj@459 | 11 | # This code is distributed in the hope that it will be useful, but WITHOUT |
erikj@459 | 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
erikj@459 | 13 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
erikj@459 | 14 | # version 2 for more details (a copy is included in the LICENSE file that |
erikj@459 | 15 | # accompanied this code). |
erikj@459 | 16 | # |
erikj@459 | 17 | # You should have received a copy of the GNU General Public License version |
erikj@459 | 18 | # 2 along with this work; if not, write to the Free Software Foundation, |
erikj@459 | 19 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
erikj@459 | 20 | # |
erikj@459 | 21 | # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
erikj@459 | 22 | # or visit www.oracle.com if you need additional information or have any |
erikj@459 | 23 | # questions. |
erikj@459 | 24 | # |
erikj@459 | 25 | |
erikj@459 | 26 | ################################################################ |
erikj@459 | 27 | # |
erikj@459 | 28 | # This file contains helper functions for the top-level Makefile that does |
erikj@459 | 29 | # not depend on the spec.gmk file having been read. (The purpose of this |
erikj@459 | 30 | # file is ju to avoid cluttering the top-level Makefile.) |
erikj@459 | 31 | # |
erikj@459 | 32 | ################################################################ |
erikj@459 | 33 | |
erikj@459 | 34 | ifndef _MAKEHELPERS_GMK |
erikj@459 | 35 | _MAKEHELPERS_GMK := 1 |
erikj@459 | 36 | |
erikj@459 | 37 | ############################## |
erikj@459 | 38 | # Stuff to run at include time |
erikj@459 | 39 | ############################## |
erikj@459 | 40 | |
erikj@459 | 41 | # Find out which variables were passed explicitely on the make command line. These |
erikj@459 | 42 | # will be passed on to sub-makes, overriding spec.gmk settings. |
erikj@459 | 43 | MAKE_ARGS=$(foreach var,$(subst =command,,$(filter %=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))),$(var)=$($(var))) |
erikj@459 | 44 | |
erikj@459 | 45 | list_alt_overrides_with_origins=$(filter ALT_%=environment ALT_%=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var))))) |
erikj@459 | 46 | list_alt_overrides=$(subst =command,,$(subst =environment,,$(list_alt_overrides_with_origins))) |
erikj@459 | 47 | |
erikj@459 | 48 | ############################## |
erikj@459 | 49 | # Functions |
erikj@459 | 50 | ############################## |
erikj@459 | 51 | |
erikj@459 | 52 | define fatal-error |
erikj@459 | 53 | # If the user specificed a "global" target (e.g. 'help'), do not exit but continue running |
erikj@459 | 54 | $$(if $$(findstring help,$$(MAKECMDGOALS)),,$$(error Cannot continue)) |
erikj@459 | 55 | endef |
erikj@459 | 56 | |
erikj@459 | 57 | define ParseLogLevel |
erikj@459 | 58 | ifeq ($$(origin VERBOSE),undefined) |
erikj@459 | 59 | # Setup logging according to LOG (but only if VERBOSE is not given) |
ohair@478 | 60 | |
ohair@478 | 61 | # If the "nofile" argument is given, act on it and strip it away |
ohair@478 | 62 | ifneq ($$(findstring nofile,$$(LOG)),) |
ohair@478 | 63 | # Reset the build log wrapper, regardless of other values |
ohair@478 | 64 | override BUILD_LOG_WRAPPER= |
ohair@478 | 65 | # COMMA is defined in spec.gmk, but that is not included yet |
ohair@478 | 66 | COMMA=, |
ohair@478 | 67 | # First try to remove ",nofile" if it exists |
ohair@478 | 68 | LOG_STRIPPED1=$$(subst $$(COMMA)nofile,,$$(LOG)) |
ohair@478 | 69 | # Otherwise just remove "nofile" |
ohair@478 | 70 | LOG_STRIPPED2=$$(subst nofile,,$$(LOG_STRIPPED1)) |
ohair@478 | 71 | # We might have ended up with a leading comma. Remove it |
ohair@478 | 72 | LOG_STRIPPED3=$$(strip $$(patsubst $$(COMMA)%,%,$$(LOG_STRIPPED2))) |
ohair@478 | 73 | override LOG:=$$(LOG_STRIPPED3) |
ohair@478 | 74 | endif |
ohair@478 | 75 | |
erikj@459 | 76 | ifeq ($$(LOG),) |
erikj@459 | 77 | # Set LOG to "warn" as default if not set (and no VERBOSE given) |
ohair@478 | 78 | override LOG=warn |
erikj@459 | 79 | endif |
erikj@459 | 80 | ifeq ($$(LOG),warn) |
erikj@459 | 81 | VERBOSE=-s |
erikj@459 | 82 | else ifeq ($$(LOG),info) |
erikj@459 | 83 | VERBOSE= |
erikj@459 | 84 | else ifeq ($$(LOG),debug) |
erikj@459 | 85 | VERBOSE= |
erikj@459 | 86 | else ifeq ($$(LOG),trace) |
erikj@459 | 87 | VERBOSE=-d -p |
erikj@459 | 88 | else |
erikj@459 | 89 | $$(info Error: LOG must be one of: warn, info, debug or trace.) |
erikj@459 | 90 | $$(eval $$(call fatal-error)) |
erikj@459 | 91 | endif |
erikj@459 | 92 | else |
erikj@459 | 93 | ifneq ($$(LOG),) |
erikj@459 | 94 | # We have both a VERBOSE and a LOG argument. This is OK only if this is a repeated call by ourselves, |
erikj@459 | 95 | # but complain if this is the top-level make call. |
erikj@459 | 96 | ifeq ($$(MAKELEVEL),0) |
erikj@459 | 97 | $$(info Cannot use LOG=$$(LOG) and VERBOSE=$$(VERBOSE) at the same time. Choose one.) |
erikj@459 | 98 | $$(eval $$(call fatal-error)) |
erikj@459 | 99 | endif |
erikj@459 | 100 | endif |
erikj@459 | 101 | endif |
erikj@459 | 102 | endef |
erikj@459 | 103 | |
erikj@459 | 104 | # TODO: Fix duplication in MakeBase.gmk |
erikj@459 | 105 | define SetupLogging |
erikj@459 | 106 | ifneq ($(findstring $(LOG),debug trace),) |
erikj@459 | 107 | # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make |
erikj@459 | 108 | OLD_SHELL:=$$(SHELL) |
erikj@459 | 109 | SHELL = $$(warning Building $$@$$(if $$<, (from $$<))$(if $$?, ($$? newer)))$$(OLD_SHELL) -x |
erikj@459 | 110 | endif |
erikj@459 | 111 | endef |
erikj@459 | 112 | |
erikj@459 | 113 | define ParseConfAndSpec |
erikj@459 | 114 | ifneq ($$(origin SPEC),undefined) |
erikj@459 | 115 | # We have been given a SPEC, check that it works out properly |
erikj@459 | 116 | ifeq ($$(wildcard $$(SPEC)),) |
erikj@459 | 117 | $$(info Cannot locate spec.gmk, given by SPEC=$$(SPEC)) |
erikj@459 | 118 | $$(eval $$(call fatal-error)) |
erikj@459 | 119 | endif |
erikj@459 | 120 | ifneq ($$(origin CONF),undefined) |
erikj@459 | 121 | # We also have a CONF argument. This is OK only if this is a repeated call by ourselves, |
erikj@459 | 122 | # but complain if this is the top-level make call. |
erikj@459 | 123 | ifeq ($$(MAKELEVEL),0) |
erikj@459 | 124 | $$(info Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.) |
erikj@459 | 125 | $$(eval $$(call fatal-error)) |
erikj@459 | 126 | endif |
erikj@459 | 127 | endif |
erikj@459 | 128 | # ... OK, we're satisfied, we'll use this SPEC later on |
erikj@459 | 129 | else |
erikj@459 | 130 | # Find all spec.gmk files in the build output directory |
erikj@459 | 131 | output_dir=$$(root_dir)/build |
erikj@459 | 132 | all_spec_files=$$(wildcard $$(output_dir)/*/spec.gmk) |
erikj@459 | 133 | ifeq ($$(all_spec_files),) |
erikj@459 | 134 | $$(info No configurations found for $$(root_dir)! Please run configure to create a configuration.) |
erikj@459 | 135 | $$(eval $$(call fatal-error)) |
erikj@459 | 136 | endif |
erikj@459 | 137 | # Extract the configuration names from the path |
erikj@459 | 138 | all_confs=$$(patsubst %/spec.gmk,%,$$(patsubst $$(output_dir)/%,%,$$(all_spec_files))) |
erikj@459 | 139 | |
erikj@459 | 140 | ifneq ($$(origin CONF),undefined) |
erikj@459 | 141 | # User have given a CONF= argument. |
erikj@459 | 142 | ifeq ($$(CONF),) |
erikj@459 | 143 | # If given CONF=, match all configurations |
erikj@459 | 144 | matching_confs=$$(strip $$(all_confs)) |
erikj@459 | 145 | else |
erikj@459 | 146 | # Otherwise select those that contain the given CONF string |
erikj@459 | 147 | matching_confs=$$(strip $$(foreach var,$$(all_confs),$$(if $$(findstring $$(CONF),$$(var)),$$(var)))) |
erikj@459 | 148 | endif |
erikj@459 | 149 | ifeq ($$(matching_confs),) |
erikj@459 | 150 | $$(info No configurations found matching CONF=$$(CONF)) |
erikj@459 | 151 | $$(info Available configurations:) |
erikj@459 | 152 | $$(foreach var,$$(all_confs),$$(info * $$(var))) |
erikj@459 | 153 | $$(eval $$(call fatal-error)) |
erikj@459 | 154 | else |
erikj@459 | 155 | ifeq ($$(words $$(matching_confs)),1) |
erikj@459 | 156 | $$(info Building '$$(matching_confs)' (matching CONF=$$(CONF))) |
erikj@459 | 157 | else |
erikj@459 | 158 | $$(info Building the following configurations (matching CONF=$$(CONF)):) |
erikj@459 | 159 | $$(foreach var,$$(matching_confs),$$(info * $$(var))) |
erikj@459 | 160 | endif |
erikj@459 | 161 | endif |
erikj@459 | 162 | |
erikj@459 | 163 | # Create a SPEC definition. This will contain the path to one or more spec.gmk files. |
erikj@459 | 164 | SPEC=$$(addsuffix /spec.gmk,$$(addprefix $$(output_dir)/,$$(matching_confs))) |
erikj@459 | 165 | else |
erikj@459 | 166 | # No CONF or SPEC given, check the available configurations |
erikj@459 | 167 | ifneq ($$(words $$(all_spec_files)),1) |
erikj@459 | 168 | $$(info No CONF or SPEC given, but more than one spec.gmk found in $$(output_dir).) |
erikj@459 | 169 | $$(info Available configurations:) |
erikj@459 | 170 | $$(foreach var,$$(all_confs),$$(info * $$(var))) |
erikj@459 | 171 | $$(info Please retry building with CONF=<config> or SPEC=<specfile>) |
erikj@459 | 172 | $$(eval $$(call fatal-error)) |
erikj@459 | 173 | endif |
erikj@459 | 174 | |
erikj@459 | 175 | # We found exactly one configuration, use it |
erikj@459 | 176 | SPEC=$$(strip $$(all_spec_files)) |
erikj@459 | 177 | endif |
erikj@459 | 178 | endif |
erikj@459 | 179 | endef |
erikj@459 | 180 | |
erikj@459 | 181 | define CheckEnvironment |
erikj@459 | 182 | # Find all environment or command line variables that begin with ALT. |
erikj@459 | 183 | $(if $(list_alt_overrides), |
erikj@459 | 184 | @$(PRINTF) "\nWARNING: You have the following ALT_ variables set:\n" |
erikj@459 | 185 | @$(PRINTF) "$(foreach var,$(list_alt_overrides),$(var)=$$$(var))\n" |
erikj@459 | 186 | @$(PRINTF) "ALT_ variables are deprecated and will be ignored. Please clean your environment.\n\n" |
erikj@459 | 187 | ) |
erikj@459 | 188 | endef |
erikj@459 | 189 | |
erikj@459 | 190 | define PrintStartMessage |
erikj@459 | 191 | $(if $(VERBOSE),,@$(ECHO) Running make as $(MAKE) $(MFLAGS) $(MAKE_ARGS)) |
erikj@459 | 192 | $(call CheckEnvironment) |
erikj@459 | 193 | @$(ECHO) "Building OpenJDK for target $(if $(MAKECMDGOALS),'$(MAKECMDGOALS)','all') in configuration '$(CONF_NAME)'" |
erikj@459 | 194 | endef |
erikj@459 | 195 | |
erikj@459 | 196 | define PrintEndMessage |
erikj@459 | 197 | @$(ECHO) "Finished building OpenJDK for target '$@'" |
erikj@459 | 198 | $(call CheckEnvironment) |
erikj@459 | 199 | endef |
erikj@459 | 200 | |
ohair@478 | 201 | # Cleans the component given as $1 |
ohair@478 | 202 | define CleanComponent |
ohair@478 | 203 | @$(PRINTF) "Cleaning $1 build artifacts ..." |
ohair@478 | 204 | @($(CD) $(OUTPUT_ROOT) && $(RM) -r $1) |
ohair@478 | 205 | @$(PRINTF) " done\n" |
ohair@478 | 206 | endef |
ohair@478 | 207 | |
erikj@459 | 208 | endif # _MAKEHELPERS_GMK |