|
1 # |
|
2 # Copyright (c) 2011, 2012, 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 # |
|
28 # This file contains helper functions for the top-level Makefile that does |
|
29 # not depend on the spec.gmk file having been read. (The purpose of this |
|
30 # file is ju to avoid cluttering the top-level Makefile.) |
|
31 # |
|
32 ################################################################ |
|
33 |
|
34 ifndef _MAKEHELPERS_GMK |
|
35 _MAKEHELPERS_GMK := 1 |
|
36 |
|
37 ############################## |
|
38 # Stuff to run at include time |
|
39 ############################## |
|
40 |
|
41 # Find out which variables were passed explicitely on the make command line. These |
|
42 # will be passed on to sub-makes, overriding spec.gmk settings. |
|
43 MAKE_ARGS=$(foreach var,$(subst =command,,$(filter %=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var)))))),$(var)=$($(var))) |
|
44 |
|
45 list_alt_overrides_with_origins=$(filter ALT_%=environment ALT_%=command,$(foreach var,$(.VARIABLES),$(var)=$(firstword $(origin $(var))))) |
|
46 list_alt_overrides=$(subst =command,,$(subst =environment,,$(list_alt_overrides_with_origins))) |
|
47 |
|
48 ############################## |
|
49 # Functions |
|
50 ############################## |
|
51 |
|
52 define fatal-error |
|
53 # If the user specificed a "global" target (e.g. 'help'), do not exit but continue running |
|
54 $$(if $$(findstring help,$$(MAKECMDGOALS)),,$$(error Cannot continue)) |
|
55 endef |
|
56 |
|
57 define ParseLogLevel |
|
58 ifeq ($$(origin VERBOSE),undefined) |
|
59 # Setup logging according to LOG (but only if VERBOSE is not given) |
|
60 ifeq ($$(LOG),) |
|
61 # Set LOG to "warn" as default if not set (and no VERBOSE given) |
|
62 LOG=warn |
|
63 endif |
|
64 ifeq ($$(LOG),warn) |
|
65 VERBOSE=-s |
|
66 else ifeq ($$(LOG),info) |
|
67 VERBOSE= |
|
68 else ifeq ($$(LOG),debug) |
|
69 VERBOSE= |
|
70 else ifeq ($$(LOG),trace) |
|
71 VERBOSE=-d -p |
|
72 else |
|
73 $$(info Error: LOG must be one of: warn, info, debug or trace.) |
|
74 $$(eval $$(call fatal-error)) |
|
75 endif |
|
76 else |
|
77 ifneq ($$(LOG),) |
|
78 # We have both a VERBOSE and a LOG argument. This is OK only if this is a repeated call by ourselves, |
|
79 # but complain if this is the top-level make call. |
|
80 ifeq ($$(MAKELEVEL),0) |
|
81 $$(info Cannot use LOG=$$(LOG) and VERBOSE=$$(VERBOSE) at the same time. Choose one.) |
|
82 $$(eval $$(call fatal-error)) |
|
83 endif |
|
84 endif |
|
85 endif |
|
86 endef |
|
87 |
|
88 # TODO: Fix duplication in MakeBase.gmk |
|
89 define SetupLogging |
|
90 ifneq ($(findstring $(LOG),debug trace),) |
|
91 # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make |
|
92 OLD_SHELL:=$$(SHELL) |
|
93 SHELL = $$(warning Building $$@$$(if $$<, (from $$<))$(if $$?, ($$? newer)))$$(OLD_SHELL) -x |
|
94 endif |
|
95 endef |
|
96 |
|
97 define ParseConfAndSpec |
|
98 ifneq ($$(origin SPEC),undefined) |
|
99 # We have been given a SPEC, check that it works out properly |
|
100 ifeq ($$(wildcard $$(SPEC)),) |
|
101 $$(info Cannot locate spec.gmk, given by SPEC=$$(SPEC)) |
|
102 $$(eval $$(call fatal-error)) |
|
103 endif |
|
104 ifneq ($$(origin CONF),undefined) |
|
105 # We also have a CONF argument. This is OK only if this is a repeated call by ourselves, |
|
106 # but complain if this is the top-level make call. |
|
107 ifeq ($$(MAKELEVEL),0) |
|
108 $$(info Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.) |
|
109 $$(eval $$(call fatal-error)) |
|
110 endif |
|
111 endif |
|
112 # ... OK, we're satisfied, we'll use this SPEC later on |
|
113 else |
|
114 # Find all spec.gmk files in the build output directory |
|
115 output_dir=$$(root_dir)/build |
|
116 all_spec_files=$$(wildcard $$(output_dir)/*/spec.gmk) |
|
117 ifeq ($$(all_spec_files),) |
|
118 $$(info No configurations found for $$(root_dir)! Please run configure to create a configuration.) |
|
119 $$(eval $$(call fatal-error)) |
|
120 endif |
|
121 # Extract the configuration names from the path |
|
122 all_confs=$$(patsubst %/spec.gmk,%,$$(patsubst $$(output_dir)/%,%,$$(all_spec_files))) |
|
123 |
|
124 ifneq ($$(origin CONF),undefined) |
|
125 # User have given a CONF= argument. |
|
126 ifeq ($$(CONF),) |
|
127 # If given CONF=, match all configurations |
|
128 matching_confs=$$(strip $$(all_confs)) |
|
129 else |
|
130 # Otherwise select those that contain the given CONF string |
|
131 matching_confs=$$(strip $$(foreach var,$$(all_confs),$$(if $$(findstring $$(CONF),$$(var)),$$(var)))) |
|
132 endif |
|
133 ifeq ($$(matching_confs),) |
|
134 $$(info No configurations found matching CONF=$$(CONF)) |
|
135 $$(info Available configurations:) |
|
136 $$(foreach var,$$(all_confs),$$(info * $$(var))) |
|
137 $$(eval $$(call fatal-error)) |
|
138 else |
|
139 ifeq ($$(words $$(matching_confs)),1) |
|
140 $$(info Building '$$(matching_confs)' (matching CONF=$$(CONF))) |
|
141 else |
|
142 $$(info Building the following configurations (matching CONF=$$(CONF)):) |
|
143 $$(foreach var,$$(matching_confs),$$(info * $$(var))) |
|
144 endif |
|
145 endif |
|
146 |
|
147 # Create a SPEC definition. This will contain the path to one or more spec.gmk files. |
|
148 SPEC=$$(addsuffix /spec.gmk,$$(addprefix $$(output_dir)/,$$(matching_confs))) |
|
149 else |
|
150 # No CONF or SPEC given, check the available configurations |
|
151 ifneq ($$(words $$(all_spec_files)),1) |
|
152 $$(info No CONF or SPEC given, but more than one spec.gmk found in $$(output_dir).) |
|
153 $$(info Available configurations:) |
|
154 $$(foreach var,$$(all_confs),$$(info * $$(var))) |
|
155 $$(info Please retry building with CONF=<config> or SPEC=<specfile>) |
|
156 $$(eval $$(call fatal-error)) |
|
157 endif |
|
158 |
|
159 # We found exactly one configuration, use it |
|
160 SPEC=$$(strip $$(all_spec_files)) |
|
161 endif |
|
162 endif |
|
163 endef |
|
164 |
|
165 define CheckEnvironment |
|
166 # Find all environment or command line variables that begin with ALT. |
|
167 $(if $(list_alt_overrides), |
|
168 @$(PRINTF) "\nWARNING: You have the following ALT_ variables set:\n" |
|
169 @$(PRINTF) "$(foreach var,$(list_alt_overrides),$(var)=$$$(var))\n" |
|
170 @$(PRINTF) "ALT_ variables are deprecated and will be ignored. Please clean your environment.\n\n" |
|
171 ) |
|
172 endef |
|
173 |
|
174 define PrintStartMessage |
|
175 $(if $(VERBOSE),,@$(ECHO) Running make as $(MAKE) $(MFLAGS) $(MAKE_ARGS)) |
|
176 $(call CheckEnvironment) |
|
177 @$(ECHO) "Building OpenJDK for target $(if $(MAKECMDGOALS),'$(MAKECMDGOALS)','all') in configuration '$(CONF_NAME)'" |
|
178 endef |
|
179 |
|
180 define PrintEndMessage |
|
181 @$(ECHO) "Finished building OpenJDK for target '$@'" |
|
182 $(call CheckEnvironment) |
|
183 endef |
|
184 |
|
185 endif # _MAKEHELPERS_GMK |