Mon, 23 Jul 2012 12:37:58 -0700
Added tag jdk8-b48 for changeset 3f6c72d1c2a6
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 ifeq (,$(findstring 3.81,$(MAKE_VERSION)))
37 ifeq (,$(findstring 3.82,$(MAKE_VERSION)))
38 $(error This version of GNU Make is too low ($(MAKE_VERSION)). Please upgrade to 3.81 or newer.)
39 endif
40 endif
42 ifneq (,$(CYGPATH))
43 # Cygwin styff, if needed but most is going to be
44 # done in configure!
45 ifeq (yes,$(CHECK_FOR_VCINSTALLDIR))
46 ifeq (,$(VCINSTALLDIR))
47 $(info Could not find compiler paths!)
48 $(info You probably configured the build from within a)
49 $(info VS command prompt, but you are not using such a)
50 $(info prompt right now.)
51 $(info If you instead run configure from a plain cygwin shell, it)
52 $(info will attempt to setup VS for you! Please try that.)
53 $(error Giving up for now.)
54 endif
55 endif
56 endif
58 # The build times report is turned off by setting REPORT_BUILD_TIMES to nothing.
59 # This is necessary for the target clean which will erase the
60 # directories where the buildtimes are stored.
61 REPORT_BUILD_TIMES=1
62 # Store the build times in this directory.
63 BUILDTIMESDIR=$(OUTPUT_ROOT)/tmp/buildtimes
65 # Record starting time for build of a sub repository.
66 define RecordStartTime
67 $(MKDIR) -p $(BUILDTIMESDIR)
68 $(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_start_$1
69 $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$1_human_readable
70 endef
72 # Indicate that we started to build a sub repository and record starting time.
73 define MakeStart
74 $(call RecordStartTime,$1)
75 $(BUILD_LOG_WRAPPER) $(PRINTF) "\n\n%s\n%s\n##### %-60.60s #####\n%s\n\n" \
76 "########################################################################" \
77 "########################################################################" \
78 "Entering $1 for target(s) $2" \
79 "########################################################################"
80 endef
82 # Record ending time and calculate the difference and store it in a
83 # easy to read format. Handles builds that cross midnight. Expects
84 # that a build will never take 24 hours or more.
85 define RecordEndTime
86 $(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_end_$1
87 $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$1_human_readable
88 $(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$1` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$1` $1 | \
89 $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \
90 M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \
91 > $(BUILDTIMESDIR)/build_time_diff_$1
92 endef
94 # Check if the current target is the final target, as specified by
95 # the user on the command line. If so, call PrintEndMessage.
96 define CheckIfFinished
97 $(if $(filter $@,$(MAKECMDGOALS)),$(call PrintEndMessage))
98 # If no taget is given, "all" is default. Check for that, too.
99 # At most one of the tests can be true.
100 $(if $(MAKECMDGOALS),,$(if $(filter $@,all),$(call PrintEndMessage)))
101 endef
103 # Indicate that we are done.
104 # Record ending time and print out the total time it took to build.
105 define MakeFinish
106 $(if $(REPORT_BUILD_TIMES),$(call RecordEndTime,$1),)
107 $(BUILD_LOG_WRAPPER) $(PRINTF) "%s\n##### %-60.60s #####\n%s\n##### %-60.60s #####\n%s\n\n" \
108 "########################################################################" \
109 "Leaving $1 for target(s) $2" \
110 "########################################################################" \
111 $(if $(REPORT_BUILD_TIMES),"Build time `$(CAT) $(BUILDTIMESDIR)/build_time_diff_$1` for target(s) $2","") \
112 "########################################################################"
113 $(call CheckIfFinished)
114 endef
116 # Find all build_time_* files and print their contents in a list sorted
117 # on the name of the sub repository.
118 define ReportBuildTimes
119 $(BUILD_LOG_WRAPPER) $(PRINTF) -- "-- Build times ----------\nTarget %s\nStart %s\nEnd %s\n%s\n%s\n-------------------------\n" \
120 "$1" \
121 "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
122 "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
123 "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | $(XARGS) $(CAT) | $(SORT) -k 2`" \
124 "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`"
125 endef
127 define ResetTimers
128 $$(shell $(MKDIR) -p $(BUILDTIMESDIR) && $(RM) $(BUILDTIMESDIR)/build_time_*)
129 endef
131 define StartTimer
132 $(call RecordStartTime,TOTAL)
133 endef
135 define StopTimer
136 $(if $(REPORT_BUILD_TIMES),$(call RecordEndTime,TOTAL) && $(call ReportBuildTimes,$1),)
137 endef
139 # Hook to be called as the very first thing when running a normal build
140 define AtRootMakeStart
141 $(if $(findstring -j,$(MAKEFLAGS)), $(error make -j is not supported, use make JOBS=n))
142 $(call PrintStartMessage)
143 $(call StartTimer)
144 endef
146 # Hook to be called as the very last thing for targets that are "top level" targets
147 define AtRootMakeEnd
148 $(call StopTimer)
149 $(call CheckIfFinished)
150 endef
152 # If the variable that you want to send to stdout for piping into a file or otherwise,
153 # is potentially long, for example the a list of file paths, eg a list of all package directories.
154 # Then you need to use ListPathsSafely, which optimistically splits the output into several shell
155 # calls as well as use compression on recurrent file paths segments, to get around the potential
156 # command line length problem that exists in cygwin and other shells.
157 compress_pre:=$(strip $(shell cat $(SRC_ROOT)/common/makefiles/compress.pre))
158 compress_post:=$(strip $(shell cat $(SRC_ROOT)/common/makefiles/compress.post))
159 compress_paths=$(compress_pre)\
160 $(subst $(SRC_ROOT),X97,\
161 $(subst $(OUTPUT_ROOT),X98,\
162 $(subst X,X00,\
163 $(subst $(SPACE),\n,$(strip $1)))))\
164 $(compress_post)
166 decompress_paths=sed -f $(SRC_ROOT)/common/makefiles/uncompress.sed -e 's|X99|\\n|g' \
167 -e 's|X98|$(OUTPUT_ROOT)|g' -e 's|X97|$(SRC_ROOT)|g' \
168 -e 's|X00|X|g' | tr '\n' '$2'
170 define ListPathsSafely_If
171 $(if $(word $3,$($1)),$(eval $1_LPS$3:=$(call compress_paths,$(wordlist $3,$4,$($1)))))
172 endef
174 define ListPathsSafely_Printf
175 $(if $(strip $($1_LPS$4)),printf -- "$(strip $($1_LPS$4))\n" | $(decompress_paths) $3)
176 endef
178 # Receipt example:
179 # rm -f thepaths
180 # $(call ListPathsSafely,THEPATHS,\n, >> thepaths)
181 # The \n argument means translate spaces into \n
182 # if instead , , (a space) is supplied, then spaces remain spaces.
183 define ListPathsSafely
184 $(if $(word 10001,$($1)),$(error Cannot list safely more than 10000 paths. $1 has $(words $($1)) paths!))
185 $(call ListPathsSafely_If,$1,$2,1,250)
186 $(call ListPathsSafely_If,$1,$2,251,500)
187 $(call ListPathsSafely_If,$1,$2,501,750)
188 $(call ListPathsSafely_If,$1,$2,751,1000)
190 $(call ListPathsSafely_If,$1,$2,1001,1250)
191 $(call ListPathsSafely_If,$1,$2,1251,1500)
192 $(call ListPathsSafely_If,$1,$2,1501,1750)
193 $(call ListPathsSafely_If,$1,$2,1751,2000)
195 $(call ListPathsSafely_If,$1,$2,2001,2250)
196 $(call ListPathsSafely_If,$1,$2,2251,2500)
197 $(call ListPathsSafely_If,$1,$2,2501,2750)
198 $(call ListPathsSafely_If,$1,$2,2751,3000)
200 $(call ListPathsSafely_If,$1,$2,3001,3250)
201 $(call ListPathsSafely_If,$1,$2,3251,3500)
202 $(call ListPathsSafely_If,$1,$2,3501,3750)
203 $(call ListPathsSafely_If,$1,$2,3751,4000)
205 $(call ListPathsSafely_If,$1,$2,4001,4250)
206 $(call ListPathsSafely_If,$1,$2,4251,4500)
207 $(call ListPathsSafely_If,$1,$2,4501,4750)
208 $(call ListPathsSafely_If,$1,$2,4751,5000)
210 $(call ListPathsSafely_If,$1,$2,5001,5250)
211 $(call ListPathsSafely_If,$1,$2,5251,5500)
212 $(call ListPathsSafely_If,$1,$2,5501,5750)
213 $(call ListPathsSafely_If,$1,$2,5751,6000)
215 $(call ListPathsSafely_If,$1,$2,6001,6250)
216 $(call ListPathsSafely_If,$1,$2,6251,6500)
217 $(call ListPathsSafely_If,$1,$2,6501,6750)
218 $(call ListPathsSafely_If,$1,$2,6751,7000)
220 $(call ListPathsSafely_If,$1,$2,7001,7250)
221 $(call ListPathsSafely_If,$1,$2,7251,7500)
222 $(call ListPathsSafely_If,$1,$2,7501,7750)
223 $(call ListPathsSafely_If,$1,$2,7751,8000)
225 $(call ListPathsSafely_If,$1,$2,8001,8250)
226 $(call ListPathsSafely_If,$1,$2,8251,8500)
227 $(call ListPathsSafely_If,$1,$2,8501,8750)
228 $(call ListPathsSafely_If,$1,$2,8751,9000)
230 $(call ListPathsSafely_If,$1,$2,9001,9250)
231 $(call ListPathsSafely_If,$1,$2,9251,9500)
232 $(call ListPathsSafely_If,$1,$2,9501,9750)
233 $(call ListPathsSafely_If,$1,$2,9751,10000)
235 $(call ListPathsSafely_Printf,$1,$2,$3,1)
236 $(call ListPathsSafely_Printf,$1,$2,$3,251)
237 $(call ListPathsSafely_Printf,$1,$2,$3,501)
238 $(call ListPathsSafely_Printf,$1,$2,$3,751)
240 $(call ListPathsSafely_Printf,$1,$2,$3,1001)
241 $(call ListPathsSafely_Printf,$1,$2,$3,1251)
242 $(call ListPathsSafely_Printf,$1,$2,$3,1501)
243 $(call ListPathsSafely_Printf,$1,$2,$3,1751)
245 $(call ListPathsSafely_Printf,$1,$2,$3,2001)
246 $(call ListPathsSafely_Printf,$1,$2,$3,2251)
247 $(call ListPathsSafely_Printf,$1,$2,$3,2501)
248 $(call ListPathsSafely_Printf,$1,$2,$3,2751)
250 $(call ListPathsSafely_Printf,$1,$2,$3,3001)
251 $(call ListPathsSafely_Printf,$1,$2,$3,3251)
252 $(call ListPathsSafely_Printf,$1,$2,$3,3501)
253 $(call ListPathsSafely_Printf,$1,$2,$3,3751)
255 $(call ListPathsSafely_Printf,$1,$2,$3,4001)
256 $(call ListPathsSafely_Printf,$1,$2,$3,4251)
257 $(call ListPathsSafely_Printf,$1,$2,$3,4501)
258 $(call ListPathsSafely_Printf,$1,$2,$3,4751)
260 $(call ListPathsSafely_Printf,$1,$2,$3,5001)
261 $(call ListPathsSafely_Printf,$1,$2,$3,5251)
262 $(call ListPathsSafely_Printf,$1,$2,$3,5501)
263 $(call ListPathsSafely_Printf,$1,$2,$3,5751)
265 $(call ListPathsSafely_Printf,$1,$2,$3,6001)
266 $(call ListPathsSafely_Printf,$1,$2,$3,6251)
267 $(call ListPathsSafely_Printf,$1,$2,$3,6501)
268 $(call ListPathsSafely_Printf,$1,$2,$3,6751)
270 $(call ListPathsSafely_Printf,$1,$2,$3,7001)
271 $(call ListPathsSafely_Printf,$1,$2,$3,7251)
272 $(call ListPathsSafely_Printf,$1,$2,$3,7501)
273 $(call ListPathsSafely_Printf,$1,$2,$3,7751)
275 $(call ListPathsSafely_Printf,$1,$2,$3,8001)
276 $(call ListPathsSafely_Printf,$1,$2,$3,8251)
277 $(call ListPathsSafely_Printf,$1,$2,$3,8501)
278 $(call ListPathsSafely_Printf,$1,$2,$3,8751)
280 $(call ListPathsSafely_Printf,$1,$2,$3,9001)
281 $(call ListPathsSafely_Printf,$1,$2,$3,9251)
282 $(call ListPathsSafely_Printf,$1,$2,$3,9501)
283 $(call ListPathsSafely_Printf,$1,$2,$3,9751)
284 endef
286 define ListPathsSafelyNow_IfPrintf
287 ifneq (,$$(word $4,$$($1)))
288 $$(eval $1_LPS$4:=$$(call compress_paths,$$(wordlist $4,$5,$$($1))))
289 $$(shell printf -- "$$(strip $$($1_LPS$4))\n" | $(decompress_paths) $3)
290 endif
291 endef
293 # And an non-receipt version:
294 define ListPathsSafelyNow
295 ifneq (,$$(word 10001,$$($1)))
296 $$(error Cannot list safely more than 10000 paths. $1 has $$(words $$($1)) paths!)
297 endif
298 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1,250)
299 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,251,500)
300 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,501,750)
301 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,751,1000)
303 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1001,1250)
304 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1251,1500)
305 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1501,1750)
306 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1751,2000)
308 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2001,2250)
309 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2251,2500)
310 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2501,2750)
311 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2751,3000)
313 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3001,3250)
314 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3251,3500)
315 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3501,3750)
316 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3751,4000)
318 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4001,4250)
319 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4251,4500)
320 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4501,4750)
321 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4751,5000)
323 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5001,5250)
324 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5251,5500)
325 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5501,5750)
326 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5751,6000)
328 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6001,6250)
329 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6251,6500)
330 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6501,6750)
331 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6751,7000)
333 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7001,7250)
334 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7251,7500)
335 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7501,7750)
336 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7751,8000)
338 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8001,8250)
339 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8251,8500)
340 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8501,8750)
341 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8751,9000)
343 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9001,9250)
344 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9251,9500)
345 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9501,9750)
346 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9751,10000)
348 endef
350 # The source tips can come from the Mercurial repository, or in the files
351 # $(HGTIP_FILENAME) which contains the tip but is also positioned in the same
352 # directory as the original $(HGDIR) directory.
353 # These should not be := assignments, only used from the root Makefile.
354 HG_VERSION = $(shell $(HG) version 2> /dev/null)
355 HG_DIRECTORY=.hg
356 HGTIP_FILENAME=.hgtip
357 HG_SEARCH = ./REPO ./*/REPO ./*/*/REPO ./*/*/*/REPO
358 REPO_LIST = $(patsubst ./%,%,$(patsubst %/,%,$(sort $(dir \
359 $(shell $(CD) $(SRC_ROOT) ; ( $(LS) -d $(HG_SEARCH:%/REPO=%/$(HG_DIRECTORY)) ; \
360 $(LS) $(HG_SEARCH:%/REPO=%/$(HGTIP_FILENAME)) ) \
361 2> /dev/null)))))
363 # Emit the repo:tip pairs to $@
364 define GetSourceTips
365 $(CD) $(SRC_ROOT) ; \
366 for i in $(REPO_LIST) IGNORE ; do \
367 if [ "$${i}" = "IGNORE" ] ; then \
368 continue; \
369 elif [ -d $${i}/$(HG_DIRECTORY) -a "$(HG_VERSION)" != "" ] ; then \
370 $(PRINTF) " %s:%s" \
371 "$${i}" `$(HG) tip --repository $${i} --template '{node|short}\n'` ; \
372 elif [ -f $${i}/$(HGTIP_FILENAME) ] ; then \
373 $(PRINTF) " %s:%s" \
374 "$${i}" `$(CAT) $${i}/$(HGTIP_FILENAME)` ; \
375 fi; \
376 done >> $@
377 $(PRINTF) "\n" >> $@
378 endef
380 # Create the HGTIP_FILENAME file. Called from jdk/make/closed/bundles.gmk
381 define CreateHgTip
382 $(HG) tip --repository $1 --template '{node|short}\n' > $1/$(HGTIP_FILENAME);\
383 $(ECHO) $1/$(HGTIP_FILENAME)
384 endef
386 define SetupLogging
387 ifneq ($(findstring $(LOG),debug trace),)
388 # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
389 OLD_SHELL:=$$(SHELL)
390 SHELL = $$(warning Building $$@$$(if $$<, (from $$<))$(if $$?, ($$? newer)))$$(OLD_SHELL) -x
391 endif
392 endef
394 # Make sure logging is setup for everyone that includes MakeBase.gmk.
395 $(eval $(call SetupLogging))
397 endif # _MAKEBASE_GMK