Fri, 26 Oct 2012 14:29:57 -0700
8000992: Update new build-infra makefiles
Summary: Build-infra project integration. Multiple authors on this work: erikj and ihse primarily, also changes from ohair, tbell, and dholmes. Special credit to ohstrom for his smartjavac work.
Reviewed-by: erikj, ihse, dholmes, tbell
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 #
26 ################################################################
27 #
28 # Check that GNU make and cygwin are recent enough.
29 # Setup common utility functions.
30 #
31 ################################################################
33 ifndef _MAKEBASE_GMK
34 _MAKEBASE_GMK := 1
36 # If the variable that you want to send to stdout for piping into a file or otherwise,
37 # is potentially long, for example the a list of file paths, eg a list of all package directories.
38 # Then you need to use ListPathsSafely, which optimistically splits the output into several shell
39 # calls as well as use compression on recurrent file paths segments, to get around the potential
40 # command line length problem that exists in cygwin and other shells.
41 compress_pre:=$(strip $(shell $(CAT) $(SRC_ROOT)/common/makefiles/support/ListPathsSafely-pre-compress.incl))
42 compress_post:=$(strip $(shell $(CAT) $(SRC_ROOT)/common/makefiles/support/ListPathsSafely-post-compress.incl))
43 compress_paths=$(compress_pre)\
44 $(subst $(SRC_ROOT),X97,\
45 $(subst $(OUTPUT_ROOT),X98,\
46 $(subst X,X00,\
47 $(subst $(SPACE),\n,$(strip $1)))))\
48 $(compress_post)
50 decompress_paths=$(SED) -f $(SRC_ROOT)/common/makefiles/support/ListPathsSafely-uncompress.sed -e 's|X99|\\n|g' \
51 -e 's|X98|$(OUTPUT_ROOT)|g' -e 's|X97|$(SRC_ROOT)|g' \
52 -e 's|X00|X|g' | tr '\n' '$2'
54 define ListPathsSafely_If
55 $(if $(word $3,$($1)),$(eval $1_LPS$3:=$(call compress_paths,$(wordlist $3,$4,$($1)))))
56 endef
58 define ListPathsSafely_Printf
59 $(if $(strip $($1_LPS$4)),printf -- "$(strip $($1_LPS$4))\n" | $(decompress_paths) $3)
60 endef
62 # Receipt example:
63 # rm -f thepaths
64 # $(call ListPathsSafely,THEPATHS,\n, >> thepaths)
65 # The \n argument means translate spaces into \n
66 # if instead , , (a space) is supplied, then spaces remain spaces.
67 define ListPathsSafely
68 $(if $(word 10001,$($1)),$(error Cannot list safely more than 10000 paths. $1 has $(words $($1)) paths!))
69 $(call ListPathsSafely_If,$1,$2,1,250)
70 $(call ListPathsSafely_If,$1,$2,251,500)
71 $(call ListPathsSafely_If,$1,$2,501,750)
72 $(call ListPathsSafely_If,$1,$2,751,1000)
74 $(call ListPathsSafely_If,$1,$2,1001,1250)
75 $(call ListPathsSafely_If,$1,$2,1251,1500)
76 $(call ListPathsSafely_If,$1,$2,1501,1750)
77 $(call ListPathsSafely_If,$1,$2,1751,2000)
79 $(call ListPathsSafely_If,$1,$2,2001,2250)
80 $(call ListPathsSafely_If,$1,$2,2251,2500)
81 $(call ListPathsSafely_If,$1,$2,2501,2750)
82 $(call ListPathsSafely_If,$1,$2,2751,3000)
84 $(call ListPathsSafely_If,$1,$2,3001,3250)
85 $(call ListPathsSafely_If,$1,$2,3251,3500)
86 $(call ListPathsSafely_If,$1,$2,3501,3750)
87 $(call ListPathsSafely_If,$1,$2,3751,4000)
89 $(call ListPathsSafely_If,$1,$2,4001,4250)
90 $(call ListPathsSafely_If,$1,$2,4251,4500)
91 $(call ListPathsSafely_If,$1,$2,4501,4750)
92 $(call ListPathsSafely_If,$1,$2,4751,5000)
94 $(call ListPathsSafely_If,$1,$2,5001,5250)
95 $(call ListPathsSafely_If,$1,$2,5251,5500)
96 $(call ListPathsSafely_If,$1,$2,5501,5750)
97 $(call ListPathsSafely_If,$1,$2,5751,6000)
99 $(call ListPathsSafely_If,$1,$2,6001,6250)
100 $(call ListPathsSafely_If,$1,$2,6251,6500)
101 $(call ListPathsSafely_If,$1,$2,6501,6750)
102 $(call ListPathsSafely_If,$1,$2,6751,7000)
104 $(call ListPathsSafely_If,$1,$2,7001,7250)
105 $(call ListPathsSafely_If,$1,$2,7251,7500)
106 $(call ListPathsSafely_If,$1,$2,7501,7750)
107 $(call ListPathsSafely_If,$1,$2,7751,8000)
109 $(call ListPathsSafely_If,$1,$2,8001,8250)
110 $(call ListPathsSafely_If,$1,$2,8251,8500)
111 $(call ListPathsSafely_If,$1,$2,8501,8750)
112 $(call ListPathsSafely_If,$1,$2,8751,9000)
114 $(call ListPathsSafely_If,$1,$2,9001,9250)
115 $(call ListPathsSafely_If,$1,$2,9251,9500)
116 $(call ListPathsSafely_If,$1,$2,9501,9750)
117 $(call ListPathsSafely_If,$1,$2,9751,10000)
119 $(call ListPathsSafely_Printf,$1,$2,$3,1)
120 $(call ListPathsSafely_Printf,$1,$2,$3,251)
121 $(call ListPathsSafely_Printf,$1,$2,$3,501)
122 $(call ListPathsSafely_Printf,$1,$2,$3,751)
124 $(call ListPathsSafely_Printf,$1,$2,$3,1001)
125 $(call ListPathsSafely_Printf,$1,$2,$3,1251)
126 $(call ListPathsSafely_Printf,$1,$2,$3,1501)
127 $(call ListPathsSafely_Printf,$1,$2,$3,1751)
129 $(call ListPathsSafely_Printf,$1,$2,$3,2001)
130 $(call ListPathsSafely_Printf,$1,$2,$3,2251)
131 $(call ListPathsSafely_Printf,$1,$2,$3,2501)
132 $(call ListPathsSafely_Printf,$1,$2,$3,2751)
134 $(call ListPathsSafely_Printf,$1,$2,$3,3001)
135 $(call ListPathsSafely_Printf,$1,$2,$3,3251)
136 $(call ListPathsSafely_Printf,$1,$2,$3,3501)
137 $(call ListPathsSafely_Printf,$1,$2,$3,3751)
139 $(call ListPathsSafely_Printf,$1,$2,$3,4001)
140 $(call ListPathsSafely_Printf,$1,$2,$3,4251)
141 $(call ListPathsSafely_Printf,$1,$2,$3,4501)
142 $(call ListPathsSafely_Printf,$1,$2,$3,4751)
144 $(call ListPathsSafely_Printf,$1,$2,$3,5001)
145 $(call ListPathsSafely_Printf,$1,$2,$3,5251)
146 $(call ListPathsSafely_Printf,$1,$2,$3,5501)
147 $(call ListPathsSafely_Printf,$1,$2,$3,5751)
149 $(call ListPathsSafely_Printf,$1,$2,$3,6001)
150 $(call ListPathsSafely_Printf,$1,$2,$3,6251)
151 $(call ListPathsSafely_Printf,$1,$2,$3,6501)
152 $(call ListPathsSafely_Printf,$1,$2,$3,6751)
154 $(call ListPathsSafely_Printf,$1,$2,$3,7001)
155 $(call ListPathsSafely_Printf,$1,$2,$3,7251)
156 $(call ListPathsSafely_Printf,$1,$2,$3,7501)
157 $(call ListPathsSafely_Printf,$1,$2,$3,7751)
159 $(call ListPathsSafely_Printf,$1,$2,$3,8001)
160 $(call ListPathsSafely_Printf,$1,$2,$3,8251)
161 $(call ListPathsSafely_Printf,$1,$2,$3,8501)
162 $(call ListPathsSafely_Printf,$1,$2,$3,8751)
164 $(call ListPathsSafely_Printf,$1,$2,$3,9001)
165 $(call ListPathsSafely_Printf,$1,$2,$3,9251)
166 $(call ListPathsSafely_Printf,$1,$2,$3,9501)
167 $(call ListPathsSafely_Printf,$1,$2,$3,9751)
168 endef
170 define ListPathsSafelyNow_IfPrintf
171 ifneq (,$$(word $4,$$($1)))
172 $$(eval $1_LPS$4:=$$(call compress_paths,$$(wordlist $4,$5,$$($1))))
173 $$(shell printf -- "$$(strip $$($1_LPS$4))\n" | $(decompress_paths) $3)
174 endif
175 endef
177 # And an non-receipt version:
178 define ListPathsSafelyNow
179 ifneq (,$$(word 10001,$$($1)))
180 $$(error Cannot list safely more than 10000 paths. $1 has $$(words $$($1)) paths!)
181 endif
182 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1,250)
183 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,251,500)
184 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,501,750)
185 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,751,1000)
187 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1001,1250)
188 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1251,1500)
189 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1501,1750)
190 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1751,2000)
192 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2001,2250)
193 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2251,2500)
194 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2501,2750)
195 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2751,3000)
197 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3001,3250)
198 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3251,3500)
199 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3501,3750)
200 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3751,4000)
202 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4001,4250)
203 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4251,4500)
204 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4501,4750)
205 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4751,5000)
207 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5001,5250)
208 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5251,5500)
209 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5501,5750)
210 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5751,6000)
212 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6001,6250)
213 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6251,6500)
214 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6501,6750)
215 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6751,7000)
217 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7001,7250)
218 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7251,7500)
219 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7501,7750)
220 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7751,8000)
222 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8001,8250)
223 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8251,8500)
224 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8501,8750)
225 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8751,9000)
227 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9001,9250)
228 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9251,9500)
229 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9501,9750)
230 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9751,10000)
232 endef
234 # The source tips can come from the Mercurial repository, or in the files
235 # $(HGTIP_FILENAME) which contains the tip but is also positioned in the same
236 # directory as the original $(HGDIR) directory.
237 # These should not be := assignments, only used from the root Makefile.
238 HG_VERSION = $(shell $(HG) version 2> /dev/null)
239 HG_DIRECTORY=.hg
240 HGTIP_FILENAME=.hgtip
241 HG_SEARCH = ./REPO ./*/REPO ./*/*/REPO ./*/*/*/REPO
242 REPO_LIST = $(patsubst ./%,%,$(patsubst %/,%,$(sort $(dir \
243 $(shell $(CD) $(SRC_ROOT) ; ( $(LS) -d $(HG_SEARCH:%/REPO=%/$(HG_DIRECTORY)) ; \
244 $(LS) $(HG_SEARCH:%/REPO=%/$(HGTIP_FILENAME)) ) \
245 2> /dev/null)))))
247 # Emit the repo:tip pairs to $@
248 define GetSourceTips
249 $(CD) $(SRC_ROOT) ; \
250 for i in $(REPO_LIST) IGNORE ; do \
251 if [ "$${i}" = "IGNORE" ] ; then \
252 continue; \
253 elif [ -d $${i}/$(HG_DIRECTORY) -a "$(HG_VERSION)" != "" ] ; then \
254 $(PRINTF) " %s:%s" \
255 "$${i}" `$(HG) tip --repository $${i} --template '{node|short}\n'` ; \
256 elif [ -f $${i}/$(HGTIP_FILENAME) ] ; then \
257 $(PRINTF) " %s:%s" \
258 "$${i}" `$(CAT) $${i}/$(HGTIP_FILENAME)` ; \
259 fi; \
260 done >> $@
261 $(PRINTF) "\n" >> $@
262 endef
264 # Create the HGTIP_FILENAME file. Called from jdk/make/closed/bundles.gmk
265 define CreateHgTip
266 $(HG) tip --repository $1 --template '{node|short}\n' > $1/$(HGTIP_FILENAME);\
267 $(ECHO) $1/$(HGTIP_FILENAME)
268 endef
270 define SetupLogging
271 ifeq ($$(LOG), trace)
272 # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
273 # For each target executed, will print
274 # Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer)
275 # but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much (and causing a crash on Cygwin).
276 OLD_SHELL:=$$(SHELL)
277 WRAPPER_SHELL:=$$(OLD_SHELL) $$(SRC_ROOT)/common/bin/shell-tracer.sh $$(if $$(TIME),$$(TIME),-) $$(OUTPUT_ROOT)/build-trace-time.log $$(OLD_SHELL)
278 SHELL=$$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(WRAPPER_SHELL)
279 endif
280 # Never remove warning messages; this is just for completeness
281 LOG_WARN=
282 ifneq ($$(findstring $$(LOG),info debug trace),)
283 LOG_INFO=
284 else
285 LOG_INFO=> /dev/null
286 endif
287 ifneq ($$(findstring $$(LOG),debug trace),)
288 LOG_DEBUG=
289 else
290 LOG_DEBUG=> /dev/null
291 endif
292 ifneq ($$(findstring $$(LOG),trace),)
293 LOG_TRACE=
294 else
295 LOG_TRACE=> /dev/null
296 endif
297 endef
299 # Make sure logging is setup for everyone that includes MakeBase.gmk.
300 $(eval $(call SetupLogging))
302 # This is to be called by all SetupFoo macros
303 define LogSetupMacroEntry
304 $(if $(26),$(error Internal makefile error: Too many arguments to LogSetupMacroEntry, please update MakeBase.gmk))
305 $(if $(findstring $(LOG),debug trace), $(info $1 $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25,$(if $($i),$(NEWLINE) $(strip [$i] $($i))))))
306 endef
308 # Make directory without forking mkdir if not needed
309 define MakeDir
310 ifneq ($$(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),$$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9))
311 $$(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9)
312 endif
313 endef
315 ifeq ($(OPENJDK_TARGET_OS),solaris)
316 # On Solaris, if the target is a symlink and exists, cp won't overwrite.
317 define install-file
318 $(MKDIR) -p $(@D)
319 $(RM) '$@'
320 $(CP) -f -r -P '$<' '$(@D)'
321 endef
322 else ifeq ($(OPENJDK_TARGET_OS),macosx)
323 define install-file
324 $(MKDIR) -p $(@D)
325 $(CP) -fpRP '$<' '$@'
326 endef
327 else
328 define install-file
329 $(MKDIR) -p $(@D)
330 $(CP) -fP '$<' '$@'
331 endef
332 endif
334 endif # _MAKEBASE_GMK