MakeBase.gmk revision 1443:e101d3d68578
1139804Simp# 243819Sken# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. 339229Sgibbs# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 439229Sgibbs# 539229Sgibbs# This code is free software; you can redistribute it and/or modify it 639229Sgibbs# under the terms of the GNU General Public License version 2 only, as 739229Sgibbs# published by the Free Software Foundation. Oracle designates this 839229Sgibbs# particular file as subject to the "Classpath" exception as provided 939229Sgibbs# by Oracle in the LICENSE file that accompanied this code. 1039229Sgibbs# 1139229Sgibbs# This code is distributed in the hope that it will be useful, but WITHOUT 1239229Sgibbs# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1339229Sgibbs# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1439229Sgibbs# version 2 for more details (a copy is included in the LICENSE file that 1539229Sgibbs# accompanied this code). 1639229Sgibbs# 1739229Sgibbs# You should have received a copy of the GNU General Public License version 1839229Sgibbs# 2 along with this work; if not, write to the Free Software Foundation, 1939229Sgibbs# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2039229Sgibbs# 2139229Sgibbs# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2239229Sgibbs# or visit www.oracle.com if you need additional information or have any 2339229Sgibbs# questions. 2439229Sgibbs# 2539229Sgibbs 2639229Sgibbs################################################################ 2739229Sgibbs# 2839229Sgibbs# Setup common utility functions. 29116182Sobrien# 30116182Sobrien################################################################ 31116182Sobrien 32238366Sgnnifndef _MAKEBASE_GMK 33238366Sgnn_MAKEBASE_GMK := 1 3439229Sgibbs 3539229Sgibbsifeq ($(wildcard $(SPEC)),) 3639229Sgibbs $(error MakeBase.gmk needs SPEC set to a proper spec.gmk) 3760041Sphkendif 38112368Sphk 39260813Savg# By defining this pseudo target, make will automatically remove targets 4039229Sgibbs# if their recipe fails so that a rebuild is automatically triggered on the 41112001Sphk# next make invocation. 42112368Sphk.DELETE_ON_ERROR: 43112368Sphk 44112001Sphk############################## 45112001Sphk# Functions 46112001Sphk############################## 4739229Sgibbs 48112368Sphk 4939229Sgibbs### Functions for timers 50260813Savg 51238366Sgnn# Store the build times in this directory. 52260817SavgBUILDTIMESDIR=$(OUTPUT_ROOT)/make-support/build-times 53260817Savg 54260817Savg# Record starting time for build of a sub repository. 55260813Savgdefine RecordStartTime 56260817Savg $(MKDIR) -p $(BUILDTIMESDIR) 57260813Savg $(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_start_$(strip $1) 58238366Sgnn $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$(strip $1)_human_readable 59260813Savgendef 60260813Savg 61260813Savg# Record ending time and calculate the difference and store it in a 62260813Savg# easy to read format. Handles builds that cross midnight. Expects 63260817Savg# that a build will never take 24 hours or more. 64260817Savgdefine RecordEndTime 65238366Sgnn $(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_end_$(strip $1) 6639229Sgibbs $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)_human_readable 67119028Sphk $(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$(strip $1)` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$(strip $1)` $1 | \ 6839229Sgibbs $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \ 6939229Sgibbs M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \ 70112368Sphk > $(BUILDTIMESDIR)/build_time_diff_$(strip $1) 71223061Sgibbsendef 7239229Sgibbs 73223061Sgibbs# Hook to be called when starting to execute a top-level target 74112001Sphkdefine TargetEnter 75112001Sphk $(PRINTF) "## Starting $(patsubst %-only,%,$@)\n" 76112365Sphk $(call RecordStartTime,$(patsubst %-only,%,$@)) 77209390Sedendef 78112007Sphk 79112007Sphk# Hook to be called when finish executing a top-level target 80112007Sphkdefine TargetExit 8139229Sgibbs $(call RecordEndTime,$(patsubst %-only,%,$@)) 8239229Sgibbs $(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \ 83112001Sphk "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`" 84112001Sphkendef 85112001Sphk 86112365Sphk################################################################################ 87209390Sed# This macro translates $ into \$ to protect the $ from expansion in the shell. 88112001Sphk# To make this macro resilient against already escaped strings, first remove 89112001Sphk# any present escapes before escaping so that no double escapes are added. 90112001SphkEscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1))) 91112001Sphk 92112001Sphk################################################################################ 93112001Sphk# This macro translates $ into $$ to protect the string from make itself. 94112368SphkDoubleDollar = $(subst $$,$$$$,$(strip $1)) 95112368Sphk 96112001Sphk################################################################################ 97112368Sphk 98112369Sphk# If the variable that you want to send to stdout for piping into a file or otherwise, 99260385Sscottl# is potentially long, for example the a list of file paths, eg a list of all package directories. 100112369Sphk# Then you need to use ListPathsSafely, which optimistically splits the output into several shell 101112369Sphk# calls as well as use compression on recurrent file paths segments, to get around the potential 102112369Sphk# command line length problem that exists in cygwin and other shells. 103112369Sphkcompress_pre:=$(strip $(shell $(CAT) $(SRC_ROOT)/make/common/support/ListPathsSafely-pre-compress.incl)) 104112369Sphkcompress_post:=$(strip $(shell $(CAT) $(SRC_ROOT)/make/common/support/ListPathsSafely-post-compress.incl)) 105112369Sphkcompress_paths=$(compress_pre)\ 106112369Sphk$(subst $(SRC_ROOT),X97,\ 107112368Sphk$(subst $(OUTPUT_ROOT),X98,\ 108112001Sphk$(subst X,X00,\ 109112001Sphk$(subst $(SPACE),\n,$(strip $1)))))\ 110112001Sphk$(compress_post) 111112001Sphk 11239229Sgibbsdecompress_paths=$(SED) -f $(SRC_ROOT)/make/common/support/ListPathsSafely-uncompress.sed -e 's|X99|\\n|g' \ 11339229Sgibbs -e 's|X98|$(OUTPUT_ROOT)|g' -e 's|X97|$(SRC_ROOT)|g' \ 11439229Sgibbs -e 's|X00|X|g' | tr '\n' '$2' 115112007Sphk 116112365Sphkdefine ListPathsSafely_If 117209390Sed $(if $(word $3,$($1)),$(eval $1_LPS$3:=$(call compress_paths,$(wordlist $3,$4,$($1))))) 11839229Sgibbsendef 11943819Sken 12043819Skendefine ListPathsSafely_Printf 12139229Sgibbs $(if $(strip $($1_LPS$4)),$(if $(findstring $(LOG_LEVEL),trace),,@)printf \ 12239229Sgibbs -- "$(strip $(call EscapeDollar, $($1_LPS$4)))\n" | $(decompress_paths) $3) 12343819Skenendef 12439229Sgibbs 125112368Sphk# Receipt example: 12639229Sgibbs# rm -f thepaths 12739229Sgibbs# $(call ListPathsSafely,THEPATHS,\n, >> thepaths) 12839229Sgibbs# The \n argument means translate spaces into \n 12939229Sgibbs# if instead , , (a space) is supplied, then spaces remain spaces. 13043819Skendefine ListPathsSafely 13143819Sken $(if $(word 16001,$($1)),$(error Cannot list safely more than 16000 paths. $1 has $(words $($1)) paths!)) 13243819Sken $(ECHO) $(LOG_DEBUG) Writing $(words $($1)) paths to '$3' 13343819Sken $(call ListPathsSafely_If,$1,$2,1,250) 13443819Sken $(call ListPathsSafely_If,$1,$2,251,500) 13543819Sken $(call ListPathsSafely_If,$1,$2,501,750) 13643819Sken $(call ListPathsSafely_If,$1,$2,751,1000) 13743819Sken 13843819Sken $(call ListPathsSafely_If,$1,$2,1001,1250) 13943819Sken $(call ListPathsSafely_If,$1,$2,1251,1500) 14043819Sken $(call ListPathsSafely_If,$1,$2,1501,1750) 14143819Sken $(call ListPathsSafely_If,$1,$2,1751,2000) 14272012Sphk 14343819Sken $(call ListPathsSafely_If,$1,$2,2001,2250) 14439229Sgibbs $(call ListPathsSafely_If,$1,$2,2251,2500) 14543819Sken $(call ListPathsSafely_If,$1,$2,2501,2750) 14643819Sken $(call ListPathsSafely_If,$1,$2,2751,3000) 14743819Sken 14843819Sken $(call ListPathsSafely_If,$1,$2,3001,3250) 14943819Sken $(call ListPathsSafely_If,$1,$2,3251,3500) 15043819Sken $(call ListPathsSafely_If,$1,$2,3501,3750) 15143819Sken $(call ListPathsSafely_If,$1,$2,3751,4000) 15243819Sken 15343819Sken $(call ListPathsSafely_If,$1,$2,4001,4250) 15443819Sken $(call ListPathsSafely_If,$1,$2,4251,4500) 15543819Sken $(call ListPathsSafely_If,$1,$2,4501,4750) 15643819Sken $(call ListPathsSafely_If,$1,$2,4751,5000) 15743819Sken 15843819Sken $(call ListPathsSafely_If,$1,$2,5001,5250) 15943819Sken $(call ListPathsSafely_If,$1,$2,5251,5500) 16043819Sken $(call ListPathsSafely_If,$1,$2,5501,5750) 16143819Sken $(call ListPathsSafely_If,$1,$2,5751,6000) 16243819Sken 16343819Sken $(call ListPathsSafely_If,$1,$2,6001,6250) 16443819Sken $(call ListPathsSafely_If,$1,$2,6251,6500) 16543819Sken $(call ListPathsSafely_If,$1,$2,6501,6750) 16643819Sken $(call ListPathsSafely_If,$1,$2,6751,7000) 16743819Sken 16843819Sken $(call ListPathsSafely_If,$1,$2,7001,7250) 16943819Sken $(call ListPathsSafely_If,$1,$2,7251,7500) 17043819Sken $(call ListPathsSafely_If,$1,$2,7501,7750) 17143819Sken $(call ListPathsSafely_If,$1,$2,7751,8000) 17243819Sken 17343819Sken $(call ListPathsSafely_If,$1,$2,8001,8250) 174112365Sphk $(call ListPathsSafely_If,$1,$2,8251,8500) 175112365Sphk $(call ListPathsSafely_If,$1,$2,8501,8750) 17643819Sken $(call ListPathsSafely_If,$1,$2,8751,9000) 17743819Sken 17843819Sken $(call ListPathsSafely_If,$1,$2,9001,9250) 17943819Sken $(call ListPathsSafely_If,$1,$2,9251,9500) 18043819Sken $(call ListPathsSafely_If,$1,$2,9501,9750) 18143819Sken $(call ListPathsSafely_If,$1,$2,9751,10000) 18239229Sgibbs 18339229Sgibbs $(call ListPathsSafely_If,$1,$2,10001,10250) 184105354Srobert $(call ListPathsSafely_If,$1,$2,10251,10500) 18539229Sgibbs $(call ListPathsSafely_If,$1,$2,10501,10750) 18639229Sgibbs $(call ListPathsSafely_If,$1,$2,10751,11000) 18739229Sgibbs 18843819Sken $(call ListPathsSafely_If,$1,$2,11001,11250) 189112288Sphk $(call ListPathsSafely_If,$1,$2,11251,11500) 190112368Sphk $(call ListPathsSafely_If,$1,$2,11501,11750) 19139229Sgibbs $(call ListPathsSafely_If,$1,$2,11751,12000) 19239229Sgibbs 19339229Sgibbs $(call ListPathsSafely_If,$1,$2,12001,12250) 19439229Sgibbs $(call ListPathsSafely_If,$1,$2,12251,12500) 19539229Sgibbs $(call ListPathsSafely_If,$1,$2,12501,12750) 19639229Sgibbs $(call ListPathsSafely_If,$1,$2,12751,13000) 19739229Sgibbs 19839229Sgibbs $(call ListPathsSafely_If,$1,$2,13001,13250) 19939229Sgibbs $(call ListPathsSafely_If,$1,$2,13251,13500) 20039229Sgibbs $(call ListPathsSafely_If,$1,$2,13501,13750) 201112368Sphk $(call ListPathsSafely_If,$1,$2,13751,14000) 20239229Sgibbs 20339229Sgibbs $(call ListPathsSafely_If,$1,$2,14001,14250) 20439229Sgibbs $(call ListPathsSafely_If,$1,$2,14251,14500) 205112368Sphk $(call ListPathsSafely_If,$1,$2,14501,14750) 20639229Sgibbs $(call ListPathsSafely_If,$1,$2,14751,15000) 20739229Sgibbs 20839229Sgibbs $(call ListPathsSafely_If,$1,$2,15001,15250) 20939229Sgibbs $(call ListPathsSafely_If,$1,$2,15251,15500) 210112368Sphk $(call ListPathsSafely_If,$1,$2,15501,15750) 211260385Sscottl $(call ListPathsSafely_If,$1,$2,15751,16000) 212112369Sphk 213112369Sphk $(call ListPathsSafely_Printf,$1,$2,$3,1) 214112369Sphk $(call ListPathsSafely_Printf,$1,$2,$3,251) 215112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,501) 216112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,751) 217112368Sphk 21839229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,1001) 21939229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,1251) 22039229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,1501) 22139229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,1751) 222112288Sphk 223112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,2001) 224112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,2251) 22539229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,2501) 22639229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,2751) 227112288Sphk 22839229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,3001) 229112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,3251) 230112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,3501) 231112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,3751) 23239229Sgibbs 23339229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,4001) 23439229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,4251) 23539229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,4501) 236112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,4751) 23739229Sgibbs 23839229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,5001) 23939229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,5251) 24039229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,5501) 24139229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,5751) 242112288Sphk 243112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,6001) 244112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,6251) 245112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,6501) 246112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,6751) 247112288Sphk 248112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,7001) 249112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,7251) 250238366Sgnn $(call ListPathsSafely_Printf,$1,$2,$3,7501) 25139229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,7751) 25239229Sgibbs 253112258Sphk $(call ListPathsSafely_Printf,$1,$2,$3,8001) 254112258Sphk $(call ListPathsSafely_Printf,$1,$2,$3,8251) 255112258Sphk $(call ListPathsSafely_Printf,$1,$2,$3,8501) 256112258Sphk $(call ListPathsSafely_Printf,$1,$2,$3,8751) 257112368Sphk 258112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,9001) 259112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,9251) 260112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,9501) 261112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,9751) 262112368Sphk 263112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,10001) 264112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,10251) 265238366Sgnn $(call ListPathsSafely_Printf,$1,$2,$3,10501) 266112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,10751) 267112288Sphk 26839229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,11001) 26939229Sgibbs $(call ListPathsSafely_Printf,$1,$2,$3,11251) 270112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,11501) 271112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,11751) 272112288Sphk 273112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,12001) 274112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,12251) 275112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,12501) 276112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,12751) 277112288Sphk 278112288Sphk $(call ListPathsSafely_Printf,$1,$2,$3,13001) 279112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,13251) 280112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,13501) 281112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,13751) 282112368Sphk 283112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,14001) 284112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,14251) 285112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,14501) 286112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,14751) 287112368Sphk 288112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,15001) 289112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,15251) 290112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,15501) 291112368Sphk $(call ListPathsSafely_Printf,$1,$2,$3,15751) 292112368Sphkendef 29339229Sgibbs 29439229Sgibbsdefine ListPathsSafelyNow_IfPrintf 295209390Sed ifneq (,$$(word $4,$$($1))) 296112288Sphk $$(eval $1_LPS$4:=$$(call compress_paths,$$(wordlist $4,$5,$$($1)))) 297112288Sphk $$(shell printf -- "$$(strip $$($1_LPS$4))\n" | $(decompress_paths) $3) 29839229Sgibbs endif 299112288Sphkendef 30039229Sgibbs 30139229Sgibbs# And an non-receipt version: 30239229Sgibbsdefine ListPathsSafelyNow 30339229Sgibbs ifneq (,$$(word 10001,$$($1))) 30439229Sgibbs $$(error Cannot list safely more than 10000 paths. $1 has $$(words $$($1)) paths!) 305112288Sphk endif 306112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1,250) 307112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,251,500) 308112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,501,750) 30939229Sgibbs $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,751,1000) 310112368Sphk 311112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1001,1250) 312112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1251,1500) 313112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1501,1750) 31439229Sgibbs $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1751,2000) 31539229Sgibbs 31639229Sgibbs $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2001,2250) 31739229Sgibbs $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2251,2500) 31851397Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2501,2750) 31951375Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2751,3000) 32039229Sgibbs 32139229Sgibbs $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3001,3250) 322112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3251,3500) 323112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3501,3750) 324112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3751,4000) 325112288Sphk 326112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4001,4250) 327112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4251,4500) 32839229Sgibbs $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4501,4750) 329112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4751,5000) 330112288Sphk 331112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5001,5250) 332112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5251,5500) 333112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5501,5750) 334112288Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5751,6000) 335112288Sphk 336112368Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6001,6250) 337238366Sgnn $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6251,6500) 33839229Sgibbs $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6501,6750) 33939229Sgibbs $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6751,7000) 34051375Sphk 34158942Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7001,7250) 34258942Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7251,7500) 343260385Sscottl $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7501,7750) 344260385Sscottl $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7751,8000) 345260385Sscottl 346260385Sscottl $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8001,8250) 347260385Sscottl $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8251,8500) 348260385Sscottl $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8501,8750) 349260385Sscottl $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8751,9000) 350260385Sscottl 35158942Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9001,9250) 35258942Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9251,9500) 353112368Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9501,9750) 354112368Sphk $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9751,10000) 355112368Sphk 356112368Sphkendef 35758942Sphk 35858942Sphk# The source tips can come from the Mercurial repository, or in the files 35958942Sphk# $(HGTIP_FILENAME) which contains the tip but is also positioned in the same 36058942Sphk# directory as the original $(HGDIR) directory. 361112368Sphk# These should not be := assignments, only used from the root Makefile. 36258942SphkHG_VERSION = $(shell $(HG) version 2> /dev/null) 363112368SphkHG_DIRECTORY=.hg 364112368SphkHGTIP_FILENAME=.hgtip 36558942SphkHG_SEARCH = ./REPO ./*/REPO ./*/*/REPO ./*/*/*/REPO 36658942SphkREPO_LIST = $(patsubst ./%,%,$(patsubst %/,%,$(sort $(dir \ 367260385Sscottl $(shell $(CD) $(SRC_ROOT) ; ( $(LS) -d $(HG_SEARCH:%/REPO=%/$(HG_DIRECTORY)) ; \ 368238366Sgnn $(LS) $(HG_SEARCH:%/REPO=%/$(HGTIP_FILENAME)) ) \ 36958942Sphk 2> /dev/null))))) 37058942Sphk 37139229Sgibbs# Emit the repo:tip pairs to $@ 37239229Sgibbsdefine GetSourceTips 37339229Sgibbs $(CD) $(SRC_ROOT) ; \ 37439229Sgibbs for i in $(REPO_LIST) IGNORE ; do \ 37539229Sgibbs if [ "$${i}" = "IGNORE" ] ; then \ 37639229Sgibbs continue; \ 377112368Sphk elif [ -d $${i}/$(HG_DIRECTORY) -a "$(HG_VERSION)" != "" ] ; then \ 378112368Sphk $(PRINTF) " %s:%s" \ 379112368Sphk "$${i}" `$(HG) tip --repository $${i} --template '{node|short}\n'` ; \ 38039229Sgibbs elif [ -f $${i}/$(HGTIP_FILENAME) ] ; then \ 38139229Sgibbs $(PRINTF) " %s:%s" \ 38262573Sphk "$${i}" `$(CAT) $${i}/$(HGTIP_FILENAME)` ; \ 38339229Sgibbs fi; \ 384112368Sphk done >> $@ 385113599Sharti $(PRINTF) "\n" >> $@ 38639229Sgibbsendef 38739229Sgibbs 388112368Sphk# Create the HGTIP_FILENAME file. Called from jdk/make/closed/bundles.gmk 389112368Sphkdefine CreateHgTip 39039229Sgibbs $(HG) tip --repository $1 --template '{node|short}\n' > $1/$(HGTIP_FILENAME); \ 391112368Sphk $(ECHO) $1/$(HGTIP_FILENAME) 392112368Sphkendef 393112368Sphk 394112368Sphkdefine SetupLogging 395112368Sphk ifeq ($$(LOG_LEVEL), trace) 396112368Sphk # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make 39739229Sgibbs # For each target executed, will print 398112368Sphk # Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer) 39939229Sgibbs # but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much 400112368Sphk # (and causing a crash on Cygwin). 401112368Sphk # Default shell seems to always be /bin/sh. Must override with bash to get this to work on Solaris. 402119028Sphk # Only use time if it's GNU time which supports format and output file. 403119028Sphk WRAPPER_SHELL := $$(BASH) $$(SRC_ROOT)/common/bin/shell-tracer.sh $$(if $$(findstring yes,$$(IS_GNU_TIME)),$$(TIME),-) $$(OUTPUT_ROOT)/build-trace-time.log $$(SHELL) 404119028Sphk SHELL := $$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(WRAPPER_SHELL) 405112368Sphk endif 406112368Sphk # Never remove warning messages; this is just for completeness 407112368Sphk LOG_WARN := 408112368Sphk ifneq ($$(findstring $$(LOG_LEVEL), info debug trace),) 409112368Sphk LOG_INFO := 410112368Sphk else 411112368Sphk LOG_INFO := > /dev/null 412112368Sphk endif 413112368Sphk ifneq ($$(findstring $$(LOG_LEVEL), debug trace),) 414112368Sphk LOG_DEBUG := 415112368Sphk else 416112368Sphk LOG_DEBUG := > /dev/null 417112368Sphk endif 41839229Sgibbs ifneq ($$(findstring $$(LOG_LEVEL), trace),) 419112368Sphk LOG_TRACE := 420112368Sphk else 421112368Sphk LOG_TRACE := > /dev/null 422112368Sphk endif 423112368Sphkendef 424112368Sphk 425112368Sphk# Make sure logging is setup for everyone that includes MakeBase.gmk. 426112368Sphk$(eval $(call SetupLogging)) 427112368Sphk 428112368Sphk################################################################################ 429112368Sphk# Creates a sequence of increasing numbers (inclusive). 43039229Sgibbs# Param 1 - starting number 43139229Sgibbs# Param 2 - ending number 43239229Sgibbssequence = \ 43339229Sgibbs $(wordlist $1, $2, $(strip \ 43439229Sgibbs $(eval SEQUENCE_COUNT :=) \ 43539229Sgibbs $(call _sequence-do,$(strip $2)))) 43639229Sgibbs 437227309Sed_sequence-do = \ 438227309Sed $(if $(word $1, $(SEQUENCE_COUNT)),, \ 43939229Sgibbs $(eval SEQUENCE_COUNT += .) \ 44039229Sgibbs $(words $(SEQUENCE_COUNT)) \ 441188063Simp $(call _sequence-do,$1)) 44239229Sgibbs 44339229Sgibbs################################################################################ 44439229Sgibbs 44539229SgibbsMAX_PARAMS := 30 44646381SbillfPARAM_SEQUENCE := $(call sequence, 2, $(MAX_PARAMS)) 44746381Sbillf 448113599Sharti# Template for creating a macro taking named parameters. To use it, assign the 44962622Sjhb# template to a variable with the name you want for your macro, using '=' 45046381Sbillf# assignment. Then define a macro body with the suffix "Body". The Body macro 45146381Sbillf# should take 1 parameter which should be a unique string for that invocation 452112001Sphk# of the macro. 453112368Sphk# Ex: 454112368Sphk# SetupFoo = $(NamedParamsMacroTemplate) 455112368Sphk# define SetupFooBody 456112368Sphk# # do something 457112368Sphk# # access parameters as $$($1_BAR) 458112368Sphk# endef 459112001Sphk# Call it like this 460112001Sphk# $(eval $(call SetupFoo, BUILD_SOMETHING, \ 461112001Sphk# BAR := some parameter value, \ 462112001Sphk# )) 463112001Sphkdefine NamedParamsMacroTemplate 464126080Sphk $(if $($(MAX_PARAMS)),$(error Internal makefile error: \ 465112001Sphk Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk)) 466112001Sphk # Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix 467112001Sphk $(foreach i,$(PARAM_SEQUENCE), $(if $(strip $($i)),\ 468112001Sphk $(strip $1)_$(strip $($i)))$(NEWLINE)) 469112001Sphk # Debug print all named parameter names and values 470112001Sphk $(if $(findstring $(LOG_LEVEL),debug trace), \ 471112001Sphk $(info $0 $(strip $1) $(foreach i,$(PARAM_SEQUENCE), \ 472112001Sphk $(if $(strip $($i)),$(NEWLINE) $(strip [$i] $(if $(filter $(LOG_LEVEL), trace), \ 473112001Sphk $($i), $(wordlist 1, 20, $($(i))) $(if $(word 21, $($(i))), ...))))))) 474112001Sphk 475112001Sphk $(if $(DEBUG_$(strip $1)), 476112001Sphk $(info -------- <<< Begin expansion of $(strip $1)) \ 477112001Sphk $(info $(call $(0)Body,$(strip $1))) \ 478112001Sphk $(info -------- >>> End expansion of $(strip $1)) \ 479201223Srnoland ) 480201223Srnoland 481112001Sphk $(call $(0)Body,$(strip $1)) 482112001Sphkendef 483112001Sphk 484112001Sphk################################################################################ 485112001Sphk# Make directory without forking mkdir if not needed 486264546SemaxMakeDir = \ 487112001Sphk $(strip $(if $(subst $(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),,$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)),\ 488112001Sphk $(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9))) 489112001Sphk 490264546Semax################################################################################ 491112001Sphk 492112001Sphkifeq ($(OPENJDK_TARGET_OS),solaris) 493112001Sphk # On Solaris, if the target is a symlink and exists, cp won't overwrite. 494112001Sphk # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the 495264546Semax # name of the target file differs from the source file, rename after copy. 496112001Sphk # If the source and target parent directories are the same, recursive copy doesn't work 497112001Sphk # so we fall back on regular copy, which isn't preserving symlinks. 498112001Sphk define install-file 499112001Sphk $(MKDIR) -p '$(@D)' 500112001Sphk $(RM) '$@' 501112001Sphk if [ "$(@D)" != "$(<D)" ]; then \ 502112001Sphk $(CP) -f -r -P '$<' '$(@D)'; \ 503197309Sattilio if [ "$(@F)" != "$(<F)" ]; then \ 504112001Sphk $(MV) '$(@D)/$(<F)' '$@'; \ 505112001Sphk fi; \ 506112001Sphk else \ 507112368Sphk if [ -L '$<' ]; then \ 508223062Sken $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \ 509223062Sken exit 1; \ 510264546Semax fi; \ 511223062Sken $(CP) -f '$<' '$@'; \ 512223062Sken fi 513112001Sphk endef 514197309Sattilioelse ifeq ($(OPENJDK_TARGET_OS),macosx) 515112368Sphk # On mac, extended attributes sometimes creep into the source files, which may later 516112368Sphk # cause the creation of ._* files which confuses testing. Clear these with xattr if 517112368Sphk # set. Some files get their write permissions removed after being copied to the 518112368Sphk # output dir. When these are copied again to images, xattr would fail. By only clearing 519112368Sphk # attributes when they are present, failing on this is avoided. 520112368Sphk define install-file 521112368Sphk $(MKDIR) -p '$(@D)' 522112001Sphk $(CP) -fRP '$<' '$@' 523197309Sattilio if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi 524197309Sattilio endef 525197309Sattilioelse 526197309Sattilio # Running mkdir and cp in the same shell speeds up copy intensive tasks in Cygwin 527197309Sattilio # significantly. 528112368Sphk define install-file 529197309Sattilio $(MKDIR) -p '$(@D)' && $(CP) -fP '$<' '$@' 530197309Sattilio endef 531112368Sphkendif 532112368Sphk 533197309Sattilio################################################################################ 534197309Sattilio# Convenience functions for working around make's limitations with $(filter ). 535197309Sattiliocontaining = \ 536197309Sattilio $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),$v))) 537197309Sattilionot-containing = \ 538197309Sattilio $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v))) 539197309Sattilio 540197309Sattilio# Filter out duplicate sub strings while preserving order. Keeps the first occurance. 541197309Sattiliouniq = \ 542197309Sattilio $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) 543197309Sattilio 544197309Sattilio# Return a list of all string elements that are duplicated in $1. 545197309Sattiliodups = \ 546197309Sattilio $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \ 547112001Sphk $(words $(filter $v, $1))), $v))) 548112001Sphk 549112001Sphk# String equals 550112001Sphkequals = \ 551112001Sphk $(and $(findstring $(strip $1),$(strip $2)),\ 552112001Sphk $(findstring $(strip $2),$(strip $1))) 553112001Sphk 554112001Sphk################################################################################ 555112001Sphk 556112368Sphkifneq ($(DISABLE_CACHE_FIND), true) 557197309Sattilio # In Cygwin, finds are very costly, both because of expensive forks and because 558197309Sattilio # of bad file system caching. Find is used extensively in $(shell) commands to 559197309Sattilio # find source files. This makes rerunning make with no or few changes rather 560197309Sattilio # expensive. To speed this up, these two macros are used to cache the results 561112001Sphk # of simple find commands for reuse. 562112001Sphk # 563112001Sphk # Runs a find and stores both the directories where it was run and the results. 564112001Sphk # This macro can be called multiple times to add to the cache. Only finds files 565112001Sphk # with no filters. 566112001Sphk # 567112001Sphk # Needs to be called with $(eval ) 568112001Sphk # 569112368Sphk # Even if the performance benifit is negligible on other platforms, keep the 570112001Sphk # functionality active unless explicitly disabled to exercise it more. 571112001Sphk # 572112001Sphk # Initialize FIND_CACHE_DIRS with := to make it a non recursively-expanded variable 573112001Sphk FIND_CACHE_DIRS := 574112001Sphk # Param 1 - Dirs to find in 575112001Sphk # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. 576112001Sphk define FillCacheFind 577112001Sphk # Filter out already cached dirs. The - is needed when FIND_CACHE_DIRS is empty 578112288Sphk # since filter out will then return empty. 579112288Sphk FIND_CACHE_NEW_DIRS := $$(filter-out $$(addsuffix /%,\ 580188063Simp - $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS), $1) 581 ifneq ($$(FIND_CACHE_NEW_DIRS), ) 582 # Remove any trailing slash from dirs in the cache dir list 583 FIND_CACHE_DIRS += $$(patsubst %/,%, $$(FIND_CACHE_NEW_DIRS)) 584 FIND_CACHE := $$(sort $$(FIND_CACHE) $$(shell $(FIND) $$(FIND_CACHE_NEW_DIRS) \( -type f -o -type l \) $2)) 585 endif 586 endef 587 588 # Mimics find by looking in the cache if all of the directories have been cached. 589 # Otherwise reverts to shell find. This is safe to call on all platforms, even if 590 # cache is deactivated. 591 # 592 # $1 can be either a directory or a file. If it's a directory, make 593 # sure we have exactly one trailing slash before the wildcard. 594 # The extra - is needed when FIND_CACHE_DIRS is empty but should be harmless. 595 # 596 # Param 1 - Dirs to find in 597 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. 598 define CacheFind 599 $(if $(filter-out $(addsuffix /%,- $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS),$1), \ 600 $(shell $(FIND) $1 \( -type f -o -type l \) $2), \ 601 $(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(FIND_CACHE))) 602 endef 603 604else 605 # If CacheFind is disabled, just run the find command. 606 # Param 1 - Dirs to find in 607 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. 608 define CacheFind 609 $(shell $(FIND) $1 \( -type f -o -type l \) $2) 610 endef 611endif 612 613################################################################################ 614 615define AddFileToCopy 616 # Helper macro for SetupCopyFiles 617 # 1 : Source file 618 # 2 : Dest file 619 # 3 : Variable to add targets to 620 # 4 : Macro to call for copy operation 621 $2: $1 622 $(ECHO) $(LOG_INFO) Copying $$(patsubst $(OUTPUT_ROOT)/%,%,$$@) 623 $$($$(strip $4)) 624 625 $3 += $2 626endef 627 628# Setup make rules for copying files, with an option to do more complex 629# processing instead of copying. 630# 631# Parameter 1 is the name of the rule. This name is used as variable prefix, 632# and the targets generated are listed in a variable by that name. 633# 634# Remaining parameters are named arguments. These include: 635# SRC : Source root dir (defaults to dir of first file) 636# DEST : Dest root dir 637# FILES : List of files to copy with absolute paths, or path relative to SRC. 638# Must be in SRC. 639# FLATTEN : Set to flatten the directory structure in the DEST dir. 640# MACRO : Optionally override the default macro used for making the copy. 641# Default is 'install-file' 642SetupCopyFiles = $(NamedParamsMacroTemplate) 643define SetupCopyFilesBody 644 645 ifeq ($$($1_MACRO), ) 646 $1_MACRO := install-file 647 endif 648 649 # Default SRC to the dir of the first file. 650 ifeq ($$($1_SRC), ) 651 $1_SRC := $$(dir $$(firstword $$($1_FILES))) 652 endif 653 654 # Remove any trailing slash from SRC 655 $1_SRC := $$(patsubst %/,%,$$($1_SRC)) 656 657 $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \ 658 $$(eval $$(call AddFileToCopy, $$($1_SRC)/$$f, \ 659 $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO)))) 660 661endef 662 663################################################################################ 664# ShellQuote 665# 666# Quotes a string with single quotes and replaces single quotes with '\'' so 667# that the contents survives being given to the shell. 668 669ShellQuote = \ 670 $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE) 671 672################################################################################ 673# Write to and read from file 674 675# Param 1 - File to read 676ReadFile = \ 677 $(shell $(CAT) $1) 678 679# Param 1 - Text to write 680# Param 2 - File to write to 681# Use printf to get consistent behavior on all platforms. 682WriteFile = \ 683 $(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2) 684 685################################################################################ 686# DependOnVariable 687# 688# This macro takes a variable name and puts the value in a file only if the 689# value has changed since last. The name of the file is returned. This can be 690# used to create rule dependencies on make variable values. The following 691# example would get rebuilt if the value of SOME_VAR was changed: 692# 693# path/to/some-file: $(call DependOnVariable, SOME_VAR) 694# echo $(SOME_VAR) > $@ 695# 696# Note that leading and trailing white space in the value is ignored. 697# 698 699# Defines the sub directory structure to store variable value file in 700DependOnVariableDirName = \ 701 $(strip $(subst $(SRC_ROOT)/,,\ 702 $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \ 703 $(firstword $(MAKEFILE_LIST)), \ 704 $(CURDIR)/$(firstword $(MAKEFILE_LIST))))) 705 706# Defines the name of the file to store variable value in. Generates a name 707# unless parameter 2 is given. 708# Param 1 - Name of variable 709# Param 2 - (optional) name of file to store value in 710DependOnVariableFileName = \ 711 $(strip $(if $(strip $2), $2, \ 712 $(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps)) 713 714# Does the actual work with parameters stripped. 715# If the file exists AND the contents is the same as the variable, do nothing 716# else print a new file. 717# Always returns the name of the file where the value was printed. 718# Param 1 - Name of variable 719# Param 2 - (optional) name of file to store value in 720DependOnVariableHelper = \ 721 $(strip $(if $(and $(wildcard $(call DependOnVariableFileName, $1, $2)),\ 722 $(call equals, $(strip $($1)), \ 723 $(call ReadFile, $(call DependOnVariableFileName, $1, $2)))),,\ 724 $(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \ 725 $(if $(findstring $(LOG_LEVEL), trace), \ 726 $(info Variable $1: >$(strip $($1))<) \ 727 $(info File: >$(call ReadFile, $(call DependOnVariableFileName, $1, $2))<)) \ 728 $(call WriteFile, $($1), $(call DependOnVariableFileName, $1, $2))) \ 729 $(call DependOnVariableFileName, $1, $2)) 730 731# Main macro 732# Param 1 - Name of variable 733# Param 2 - (optional) name of file to store value in 734DependOnVariable = \ 735 $(call DependOnVariableHelper,$(strip $1),$(strip $2)) 736 737################################################################################ 738 739# Hook to include the corresponding custom file, if present. 740$(eval $(call IncludeCustomExtension, , common/MakeBase.gmk)) 741 742endif # _MAKEBASE_GMK 743