MakeBase.gmk revision 2264:278f9a9e9329
1214571Sdim# 2214571Sdim# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. 3214571Sdim# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4214571Sdim# 5214571Sdim# This code is free software; you can redistribute it and/or modify it 6214571Sdim# under the terms of the GNU General Public License version 2 only, as 7214571Sdim# published by the Free Software Foundation. Oracle designates this 8214571Sdim# particular file as subject to the "Classpath" exception as provided 9214571Sdim# by Oracle in the LICENSE file that accompanied this code. 10214571Sdim# 11214571Sdim# This code is distributed in the hope that it will be useful, but WITHOUT 12214571Sdim# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13214571Sdim# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14214571Sdim# version 2 for more details (a copy is included in the LICENSE file that 15214571Sdim# accompanied this code). 16214571Sdim# 17214571Sdim# You should have received a copy of the GNU General Public License version 18214571Sdim# 2 along with this work; if not, write to the Free Software Foundation, 19214571Sdim# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20214571Sdim# 21214571Sdim# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22214571Sdim# or visit www.oracle.com if you need additional information or have any 23214571Sdim# questions. 24214571Sdim# 25214571Sdim 26214571Sdim################################################################ 27214571Sdim# 28214571Sdim# Setup common utility functions. 29214571Sdim# 30214571Sdim################################################################ 31214571Sdim 32214571Sdimifndef _MAKEBASE_GMK 33214571Sdim_MAKEBASE_GMK := 1 34214571Sdim 35214571Sdimifeq ($(wildcard $(SPEC)),) 36214571Sdim $(error MakeBase.gmk needs SPEC set to a proper spec.gmk) 37214571Sdimendif 38214571Sdim 39214571Sdim# By defining this pseudo target, make will automatically remove targets 40214571Sdim# if their recipe fails so that a rebuild is automatically triggered on the 41214571Sdim# next make invocation. 42214571Sdim.DELETE_ON_ERROR: 43214571Sdim 44214571Sdim################################################################################ 45214571Sdim# Definitions for special characters 46214571Sdim################################################################################ 47214571Sdim 48214571Sdim# When calling macros, the spaces between arguments are 49214571Sdim# often semantically important! Sometimes we need to subst 50214571Sdim# spaces and commas, therefore we need the following macros. 51214571SdimX:= 52214571SdimSPACE:=$(X) $(X) 53214571SdimCOMMA:=, 54214571SdimDOLLAR:=$$ 55214571SdimHASH:=\# 56214571SdimLEFT_PAREN:=( 57214571SdimRIGHT_PAREN:=) 58214571SdimSQUOTE:=' 59214571Sdim#' 60214571SdimDQUOTE:=" 61214571Sdim#" 62214571Sdimdefine NEWLINE 63214571Sdim 64214571Sdim 65214571Sdimendef 66214571Sdim 67214571Sdim# In GNU Make 4.0 and higher, there is a file function for writing to files. 68214571Sdimifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION)))) 69214571Sdim HAS_FILE_FUNCTION := true 70214571Sdimendif 71214571Sdim 72214571Sdim############################## 73214571Sdim# Functions 74214571Sdim############################## 75214571Sdim 76214571Sdim### Debug functions 77214571Sdim 78214571Sdim# Prints the name and value of a variable 79214571SdimPrintVar = \ 80214571Sdim $(info $(strip $1) >$($(strip $1))<) 81214571Sdim 82214571Sdim### Functions for timers 83214571Sdim 84214571Sdim# Store the build times in this directory. 85214571SdimBUILDTIMESDIR=$(OUTPUT_ROOT)/make-support/build-times 86214571Sdim 87214571Sdim# Record starting time for build of a sub repository. 88214571Sdimdefine RecordStartTime 89214571Sdim $(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) && \ 90214571Sdim $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$(strip $1)_human_readable 91214571Sdimendef 92214571Sdim 93214571Sdim# Record ending time and calculate the difference and store it in a 94214571Sdim# easy to read format. Handles builds that cross midnight. Expects 95214571Sdim# that a build will never take 24 hours or more. 96214571Sdimdefine RecordEndTime 97214571Sdim $(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) 98214571Sdim $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)_human_readable 99214571Sdim $(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$(strip $1)` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$(strip $1)` $1 | \ 100214571Sdim $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \ 101214571Sdim M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \ 102214571Sdim > $(BUILDTIMESDIR)/build_time_diff_$(strip $1) 103214571Sdimendef 104214571Sdim 105214571Sdim# Hook to be called when starting to execute a top-level target 106214571Sdimdefine TargetEnter 107214571Sdim $(PRINTF) "## Starting $(patsubst %-only,%,$@)\n" 108214571Sdim $(call RecordStartTime,$(patsubst %-only,%,$@)) 109214571Sdimendef 110214571Sdim 111214571Sdim# Hook to be called when finish executing a top-level target 112214571Sdimdefine TargetExit 113214571Sdim $(call RecordEndTime,$(patsubst %-only,%,$@)) 114214571Sdim $(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \ 115214571Sdim "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`" 116214571Sdimendef 117214571Sdim 118214571Sdim################################################################################ 119214571Sdim# This macro translates $ into \$ to protect the $ from expansion in the shell. 120214571Sdim# To make this macro resilient against already escaped strings, first remove 121214571Sdim# any present escapes before escaping so that no double escapes are added. 122214571SdimEscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1))) 123214571Sdim 124214571Sdim################################################################################ 125214571Sdim# This macro translates $ into $$ to protect the string from make itself. 126214571SdimDoubleDollar = $(subst $$,$$$$,$(strip $1)) 127214571Sdim 128214571Sdim################################################################################ 129214571Sdim# ListPathsSafely can be used to print command parameters to a file. This is 130214571Sdim# typically done if the command line lenght risk being too long for the 131214571Sdim# OS/shell. In later make versions, the file function can be used for this 132214571Sdim# purpose. For earlier versions, a more complex implementation is provided. 133214571Sdim# 134214571Sdim# The function ListPathsSafely can be called either directly or, more commonly 135214571Sdim# from a recipe line. If called from a recipe, it will be executed in the 136214571Sdim# evaluation phase of that recipe, which means that it will write to the file 137214571Sdim# before any other line in the recipe has been run. 138214571Sdimifeq ($(HAS_FILE_FUNCTION), true) 139214571Sdim # Param 1 - Name of variable containing paths/arguments to output 140214571Sdim # Param 2 - File to print to 141214571Sdim # Param 3 - Set to true to append to file instead of overwriting 142214571Sdim define ListPathsSafely 143214571Sdim $$(call MakeDir, $$(dir $$(strip $2))) 144214571Sdim $$(file $$(if $$(filter true, $$(strip $3)),>>,>) \ 145214571Sdim $$(strip $2),$$(subst $$(SPACE),$$(NEWLINE),$$(strip $$($$(strip $1))))) 146214571Sdim endef 147214571Sdim 148214571Sdimelse # HAS_FILE_FUNCTION = false 149214571Sdim 150214571Sdim $(eval compress_paths = \ 151214571Sdim $(strip $(shell $(CAT) $(SRC_ROOT)/make/common/support/ListPathsSafely-pre-compress.incl))) 152214571Sdim compress_paths += \ 153214571Sdim $(subst $(SRC_ROOT),X97, \ 154214571Sdim $(subst $(OUTPUT_ROOT),X98, \ 155214571Sdim $(subst X,X00, \ 156214571Sdim $(subst $(SPACE),\n,$(strip $1))))) 157214571Sdim $(eval compress_paths += \ 158214571Sdim $(strip $(shell $(CAT) $(SRC_ROOT)/make/common/support/ListPathsSafely-post-compress.incl))) 159214571Sdim 160214571Sdim decompress_paths=$(SED) -f $(SRC_ROOT)/make/common/support/ListPathsSafely-uncompress.sed \ 161214571Sdim -e 's|X99|\\n|g' \ 162214571Sdim -e 's|X98|$(OUTPUT_ROOT)|g' -e 's|X97|$(SRC_ROOT)|g' \ 163214571Sdim -e 's|X00|X|g' 164214571Sdim 165214571Sdim ListPathsSafely_IfPrintf = \ 166214571Sdim $(if $(word $3,$($(strip $1))), \ 167214571Sdim $(shell $(PRINTF) -- "$(strip $(call EscapeDollar, \ 168214571Sdim $(call compress_paths, $(wordlist $3,$4,$($(strip $1))))))\n" \ 169214571Sdim | $(decompress_paths) >> $2)) 170214571Sdim 171214571Sdim # Param 1 - Name of variable containing paths/arguments to output 172214571Sdim # Param 2 - File to print to 173214571Sdim # Param 3 - Set to true to append to file instead of overwriting 174214571Sdim define ListPathsSafely 175214571Sdim ifneq (,$$(word 30001,$$($$(strip $1)))) 176214571Sdim $$(error Cannot list safely more than 30000 paths. $1 has $$(words $$($$(strip $1))) paths!) 177214571Sdim endif 178214571Sdim $$(call MakeDir, $$(dir $2)) 179214571Sdim ifneq ($$(strip $3), true) 180214571Sdim $$(shell $(RM) $$(strip $2)) 181214571Sdim endif 182214571Sdim 183214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,1,250) 184214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,251,500) 185214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,501,750) 186214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,751,1000) 187214571Sdim 188214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,1001,1250) 189214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,1251,1500) 190214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,1501,1750) 191214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,1751,2000) 192214571Sdim 193214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,2001,2250) 194214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,2251,2500) 195214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,2501,2750) 196214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,2751,3000) 197214571Sdim 198214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,3001,3250) 199214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,3251,3500) 200214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,3501,3750) 201214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,3751,4000) 202214571Sdim 203214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,4001,4250) 204214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,4251,4500) 205214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,4501,4750) 206214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,4751,5000) 207214571Sdim 208214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,5001,5250) 209214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,5251,5500) 210214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,5501,5750) 211214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,5751,6000) 212214571Sdim 213214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,6001,6250) 214214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,6251,6500) 215214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,6501,6750) 216214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,6751,7000) 217214571Sdim 218214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,7001,7250) 219214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,7251,7500) 220214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,7501,7750) 221214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,7751,8000) 222214571Sdim 223214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,8001,8250) 224214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,8251,8500) 225214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,8501,8750) 226214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,8751,9000) 227214571Sdim 228214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,9001,9250) 229214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,9251,9500) 230214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,9501,9750) 231214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,9751,10000) 232214571Sdim 233214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,10001,10250) 234214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,10251,10500) 235214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,10501,10750) 236214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,10751,11000) 237214571Sdim 238214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,11001,11250) 239214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,11251,11500) 240214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,11501,11750) 241214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,11751,12000) 242214571Sdim 243214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,12001,12250) 244214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,12251,12500) 245214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,12501,12750) 246214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,12751,13000) 247214571Sdim 248214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,13001,13250) 249214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,13251,13500) 250214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,13501,13750) 251214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,13751,14000) 252214571Sdim 253214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,14001,14250) 254214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,14251,14500) 255214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,14501,14750) 256214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,14751,15000) 257214571Sdim 258214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,15001,15250) 259214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,15251,15500) 260214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,15501,15750) 261214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,15751,16000) 262214571Sdim 263214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,16001,16250) 264214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,16251,16500) 265214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,16501,16750) 266214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,16751,17000) 267214571Sdim 268214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,17001,17250) 269214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,17251,17500) 270214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,17501,17750) 271214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,17751,18000) 272214571Sdim 273214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,18001,18250) 274214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,18251,18500) 275214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,18501,18750) 276214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,18751,19000) 277214571Sdim 278214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,19001,19250) 279214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,19251,19500) 280214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,19501,19750) 281214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,19751,20000) 282214571Sdim 283214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,20001,20250) 284214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,20251,20500) 285214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,20501,20750) 286214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,20751,21000) 287214571Sdim 288214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,21001,21250) 289214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,21251,21500) 290214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,21501,21750) 291214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,21751,22000) 292214571Sdim 293214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,22001,22250) 294214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,22251,22500) 295214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,22501,22750) 296214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,22751,23000) 297214571Sdim 298214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,23001,23250) 299214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,23251,23500) 300214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,23501,23750) 301214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,23751,24000) 302214571Sdim 303214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,24001,24250) 304214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,24251,24500) 305214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,24501,24750) 306214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,24751,25000) 307214571Sdim 308214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,25001,25250) 309214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,25251,25500) 310214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,25501,25750) 311214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,25751,26000) 312214571Sdim 313214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,26001,26250) 314214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,26251,26500) 315214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,26501,26750) 316214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,26751,27000) 317214571Sdim 318214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,27001,27250) 319214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,27251,27500) 320214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,27501,27750) 321214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,27751,28000) 322214571Sdim 323214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,28001,28250) 324214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,28251,28500) 325214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,28501,28750) 326214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,28751,29000) 327214571Sdim 328214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,29001,29250) 329214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,29251,29500) 330214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,29501,29750) 331214571Sdim $$(call ListPathsSafely_IfPrintf,$1,$2,29751,30000) 332214571Sdim endef 333214571Sdimendif # HAS_FILE_FUNCTION 334214571Sdim 335214571Sdim################################################################################ 336214571Sdim# The source tips can come from the Mercurial repository, or in the files 337214571Sdim# $(HGTIP_FILENAME) which contains the tip but is also positioned in the same 338214571Sdim# directory as the original .hg directory. The hgtip files are created in 339214571Sdim# CreateHgtipFiles.gmk. 340214571SdimHGTIP_FILENAME := .hgtip 341214571SdimFindAllReposAbs = \ 342214571Sdim $(strip $(sort $(dir $(filter-out $(SRC_ROOT)/build/%, $(wildcard \ 343214571Sdim $(addprefix $(SRC_ROOT)/, \ 344214571Sdim .hg */.hg */*/.hg */*/.hg */*/*/.hg \ 345214571Sdim .hgtip */.hgtip */*/.hgtip */*/.hgtip */*/*/.hgtip \ 346214571Sdim ) \ 347214571Sdim ))))) 348214571Sdim 349214571SdimFindAllReposRel = \ 350214571Sdim $(strip $(subst $(SRC_ROOT)/,.,$(patsubst $(SRC_ROOT)/%/, %, $(FindAllReposAbs)))) 351214571Sdim 352214571Sdim# Emit the repo:tip pairs to $@, but only if they changed since last time 353214571Sdimdefine GetSourceTips 354214571Sdim $(CD) $(SRC_ROOT) ; \ 355214571Sdim for i in $(FindAllReposRel) IGNORE ; do \ 356214571Sdim if [ "$${i}" = "IGNORE" ] ; then \ 357214571Sdim continue; \ 358214571Sdim elif [ -d $${i}/.hg -a "$(HG)" != "" ] ; then \ 359214571Sdim $(PRINTF) " %s:%s" \ 360214571Sdim "$${i}" `$(HG) tip --repository $${i} --template '{node|short}\n'` ; \ 361214571Sdim elif [ -f $${i}/$(HGTIP_FILENAME) ] ; then \ 362214571Sdim $(PRINTF) " %s:%s" \ 363214571Sdim "$${i}" `$(CAT) $${i}/$(HGTIP_FILENAME)` ; \ 364214571Sdim fi; \ 365214571Sdim done > $@.tmp 366214571Sdim $(PRINTF) "\n" >> $@.tmp 367214571Sdim if [ ! -f $@ ] || [ "`$(CAT) $@`" != "`$(CAT) $@.tmp`" ]; then \ 368214571Sdim $(MV) $@.tmp $@ ; \ 369214571Sdim else \ 370214571Sdim $(RM) $@.tmp ; \ 371214571Sdim fi 372214571Sdimendef 373214571Sdim 374214571Sdim################################################################################ 375214571Sdim 376214571Sdimdefine SetupLogging 377214571Sdim ifeq ($$(LOG_LEVEL), trace) 378214571Sdim # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make 379214571Sdim # For each target executed, will print 380214571Sdim # Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer) 381214571Sdim # but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much 382214571Sdim # (and causing a crash on Cygwin). 383214571Sdim # Default shell seems to always be /bin/sh. Must override with bash to get this to work on Solaris. 384214571Sdim # Only use time if it's GNU time which supports format and output file. 385214571Sdim WRAPPER_SHELL := $$(BASH) $$(SRC_ROOT)/common/bin/shell-tracer.sh $$(if $$(findstring yes,$$(IS_GNU_TIME)),$$(TIME),-) $$(OUTPUT_ROOT)/build-trace-time.log $$(SHELL) 386214571Sdim SHELL = $$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(WRAPPER_SHELL) 387214571Sdim endif 388214571Sdim # The warn level can never be turned off 389214571Sdim LogWarn = $$(info $$(strip $$1)) 390214571Sdim LOG_WARN := 391214571Sdim ifneq ($$(findstring $$(LOG_LEVEL), info debug trace),) 392214571Sdim LogInfo = $$(info $$(strip $$1)) 393214571Sdim LOG_INFO := 394214571Sdim else 395214571Sdim LogInfo = 396214571Sdim LOG_INFO := > /dev/null 397214571Sdim endif 398214571Sdim ifneq ($$(findstring $$(LOG_LEVEL), debug trace),) 399214571Sdim LogDebug = $$(info $$(strip $$1)) 400214571Sdim LOG_DEBUG := 401214571Sdim else 402214571Sdim LogDebug = 403214571Sdim LOG_DEBUG := > /dev/null 404214571Sdim endif 405214571Sdim ifneq ($$(findstring $$(LOG_LEVEL), trace),) 406214571Sdim LogTrace = $$(info $$(strip $$1)) 407214571Sdim LOG_TRACE := 408214571Sdim else 409214571Sdim LogTrace = 410214571Sdim LOG_TRACE := > /dev/null 411214571Sdim endif 412214571Sdimendef 413214571Sdim 414214571Sdim# Make sure logging is setup for everyone that includes MakeBase.gmk. 415214571Sdim$(eval $(call SetupLogging)) 416214571Sdim 417214571Sdim################################################################################ 418214571Sdim# Creates a sequence of increasing numbers (inclusive). 419214571Sdim# Param 1 - starting number 420214571Sdim# Param 2 - ending number 421214571Sdimsequence = \ 422214571Sdim $(wordlist $1, $2, $(strip \ 423214571Sdim $(eval SEQUENCE_COUNT :=) \ 424214571Sdim $(call _sequence-do,$(strip $2)))) 425214571Sdim 426214571Sdim_sequence-do = \ 427214571Sdim $(if $(word $1, $(SEQUENCE_COUNT)),, \ 428214571Sdim $(eval SEQUENCE_COUNT += .) \ 429214571Sdim $(words $(SEQUENCE_COUNT)) \ 430214571Sdim $(call _sequence-do,$1)) 431214571Sdim 432214571Sdim################################################################################ 433214571Sdim 434214571SdimMAX_PARAMS := 35 435214571SdimPARAM_SEQUENCE := $(call sequence, 2, $(MAX_PARAMS)) 436214571Sdim 437214571Sdim# Template for creating a macro taking named parameters. To use it, assign the 438214571Sdim# template to a variable with the name you want for your macro, using '=' 439214571Sdim# assignment. Then define a macro body with the suffix "Body". The Body macro 440214571Sdim# should take 1 parameter which should be a unique string for that invocation 441214571Sdim# of the macro. 442214571Sdim# Ex: 443214571Sdim# SetupFoo = $(NamedParamsMacroTemplate) 444214571Sdim# define SetupFooBody 445214571Sdim# # do something 446214571Sdim# # access parameters as $$($1_BAR) 447214571Sdim# endef 448214571Sdim# Call it like this 449214571Sdim# $(eval $(call SetupFoo, BUILD_SOMETHING, \ 450214571Sdim# BAR := some parameter value, \ 451214571Sdim# )) 452214571Sdimdefine NamedParamsMacroTemplate 453214571Sdim $(if $($(MAX_PARAMS)),$(error Internal makefile error: \ 454214571Sdim Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk)) 455214571Sdim # Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix 456214571Sdim $(foreach i,$(PARAM_SEQUENCE), $(if $(strip $($i)),\ 457214571Sdim $(strip $1)_$(strip $($i)))$(NEWLINE)) 458214571Sdim # Debug print all named parameter names and values 459214571Sdim $(if $(findstring $(LOG_LEVEL),debug trace), \ 460214571Sdim $(info $0 $(strip $1) $(foreach i,$(PARAM_SEQUENCE), \ 461214571Sdim $(if $(strip $($i)),$(NEWLINE) $(strip [$i] $(if $(filter $(LOG_LEVEL), trace), \ 462214571Sdim $($i), $(wordlist 1, 20, $($(i))) $(if $(word 21, $($(i))), ...))))))) 463214571Sdim 464214571Sdim $(if $(DEBUG_$(strip $1)), 465214571Sdim $(info -------- <<< Begin expansion of $(strip $1)) \ 466214571Sdim $(info $(call $(0)Body,$(strip $1))) \ 467214571Sdim $(info -------- >>> End expansion of $(strip $1)) \ 468214571Sdim ) 469214571Sdim 470214571Sdim $(call $(0)Body,$(strip $1)) 471214571Sdimendef 472214571Sdim 473214571Sdim################################################################################ 474214571Sdim# Make directory without forking mkdir if not needed 475214571Sdim# 1: List of directories to create 476214571SdimMakeDir = \ 477214571Sdim $(strip \ 478214571Sdim $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, $(if $(wildcard $d), , $d)))) \ 479214571Sdim $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \ 480214571Sdim ) 481214571Sdim 482214571Sdim################################################################################ 483214571Sdim# Assign a variable only if it is empty 484214571Sdim# Param 1 - Variable to assign 485214571Sdim# Param 2 - Value to assign 486214571SdimSetIfEmpty = \ 487214571Sdim $(if $($(strip $1)),,$(eval $(strip $1) := $2)) 488214571Sdim 489214571Sdim################################################################################ 490214571Sdim 491214571Sdimifeq ($(OPENJDK_TARGET_OS),solaris) 492214571Sdim # On Solaris, if the target is a symlink and exists, cp won't overwrite. 493214571Sdim # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the 494214571Sdim # name of the target file differs from the source file, rename after copy. 495214571Sdim # If the source and target parent directories are the same, recursive copy doesn't work 496214571Sdim # so we fall back on regular copy, which isn't preserving symlinks. 497214571Sdim define install-file 498214571Sdim $(MKDIR) -p '$(@D)' 499214571Sdim $(RM) '$@' 500214571Sdim if [ "$(@D)" != "$(<D)" ]; then \ 501214571Sdim $(CP) -f -r -P '$<' '$(@D)'; \ 502214571Sdim if [ "$(@F)" != "$(<F)" ]; then \ 503214571Sdim $(MV) '$(@D)/$(<F)' '$@'; \ 504214571Sdim fi; \ 505214571Sdim else \ 506214571Sdim if [ -L '$<' ]; then \ 507214571Sdim $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \ 508214571Sdim exit 1; \ 509214571Sdim fi; \ 510214571Sdim $(CP) -f '$<' '$@'; \ 511214571Sdim fi 512214571Sdim endef 513214571Sdimelse ifeq ($(OPENJDK_TARGET_OS),macosx) 514214571Sdim # On mac, extended attributes sometimes creep into the source files, which may later 515214571Sdim # cause the creation of ._* files which confuses testing. Clear these with xattr if 516214571Sdim # set. Some files get their write permissions removed after being copied to the 517214571Sdim # output dir. When these are copied again to images, xattr would fail. By only clearing 518214571Sdim # attributes when they are present, failing on this is avoided. 519214571Sdim # 520214571Sdim # If copying a soft link to a directory, need to delete the target first to avoid 521214571Sdim # weird errors. 522214571Sdim define install-file 523214571Sdim $(MKDIR) -p '$(@D)' 524214571Sdim $(RM) '$@' 525214571Sdim $(CP) -fRP '$<' '$@' 526214571Sdim if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi 527214571Sdim endef 528214571Sdimelse 529214571Sdim # Running mkdir and cp in the same shell speeds up copy intensive tasks in Cygwin 530214571Sdim # significantly. 531214571Sdim define install-file 532214571Sdim $(call MakeDir, $(@D)) 533214571Sdim $(CP) -fP '$<' '$@' 534214571Sdim endef 535214571Sdimendif 536214571Sdim 537214571Sdim################################################################################ 538214571Sdim# Take two paths and return the path of the last common directory. 539214571Sdim# Ex: /foo/bar/baz, /foo/bar/banan -> /foo/bar 540214571Sdim# foo/bar/baz, /foo/bar -> <empty> 541214571Sdim# 542214571Sdim# The x prefix is used to preserve the presence of the initial slash 543214571Sdim# 544214571Sdim# $1 - Path to compare 545214571Sdim# $2 - Other path to compare 546214571SdimFindCommonPathPrefix = \ 547214571Sdim $(patsubst x%,%,$(subst $(SPACE),/,$(strip \ 548214571Sdim $(call FindCommonPathPrefixHelper, \ 549214571Sdim $(subst /,$(SPACE),x$(strip $1)), $(subst /,$(SPACE),x$(strip $2))) \ 550214571Sdim ))) 551214571Sdim 552214571SdimFindCommonPathPrefixHelper = \ 553214571Sdim $(if $(call equals, $(firstword $1), $(firstword $2)), \ 554214571Sdim $(firstword $1) \ 555214571Sdim $(call FindCommonPathPrefixHelper, \ 556214571Sdim $(wordlist 2, $(words $1), $1), $(wordlist 2, $(words $2), $2) \ 557214571Sdim ) \ 558214571Sdim ) 559214571Sdim 560214571Sdim# Convert a partial path into as many directory levels of ../, removing 561214571Sdim# leading and following /. 562214571Sdim# Ex: foo/bar/baz/ -> ../../.. 563214571Sdim# foo/bar -> ../.. 564214571Sdim# /foo -> .. 565214571SdimDirToDotDot = \ 566214571Sdim $(subst $(SPACE),/,$(foreach d, $(subst /,$(SPACE),$1),..)) 567214571Sdim 568214571Sdim# Computes the relative path from a directory to a file 569214571Sdim# $1 - File to compute the relative path to 570214571Sdim# $2 - Directory to compute the relative path from 571214571SdimRelativePath = \ 572214571Sdim $(eval $1_prefix := $(call FindCommonPathPrefix, $1, $2)) \ 573214571Sdim $(eval $1_dotdots := $(call DirToDotDot, $(patsubst $($(strip $1)_prefix)/%, %, $2))) \ 574214571Sdim $(eval $1_suffix := $(patsubst $($(strip $1)_prefix)/%, %, $1)) \ 575214571Sdim $($(strip $1)_dotdots)/$($(strip $1)_suffix) 576214571Sdim 577214571Sdim################################################################################ 578214571Sdim# link-file-* works similarly to install file but creates a symlink instead on 579214571Sdim# platforms that support it. There are two versions, either creating a relative 580214571Sdim# or an absolute link. 581214571Sdimifeq ($(OPENJDK_BUILD_OS), windows) 582214571Sdim link-file-absolute = $(install-file) 583214571Sdim link-file-relative = $(install-file) 584214571Sdimelse 585214571Sdim define link-file-relative 586214571Sdim $(call MakeDir, $(@D)) 587214571Sdim $(RM) $@ 588214571Sdim $(LN) -s $(call RelativePath, $<, $(@D)) $@ 589214571Sdim endef 590214571Sdim 591214571Sdim define link-file-absolute 592214571Sdim $(call MakeDir, $(@D)) 593214571Sdim $(RM) $@ 594214571Sdim $(LN) -s $< $@ 595214571Sdim endef 596214571Sdimendif 597214571Sdim 598214571Sdim################################################################################ 599214571Sdim# Filter out duplicate sub strings while preserving order. Keeps the first occurance. 600214571Sdimuniq = \ 601214571Sdim $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) 602214571Sdim 603214571Sdim# Returns all whitespace-separated words in $2 where at least one of the 604214571Sdim# whitespace-separated words in $1 is a substring. 605214571Sdimcontaining = \ 606214571Sdim $(strip \ 607214571Sdim $(foreach v,$(strip $2),\ 608214571Sdim $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v))))) 609214571Sdim 610214571Sdim# Returns all whitespace-separated words in $2 where none of the 611214571Sdim# whitespace-separated words in $1 is a substring. 612214571Sdimnot-containing = \ 613214571Sdim $(strip $(filter-out $(call containing,$1,$2),$2)) 614214571Sdim 615214571Sdim# Return a list of all string elements that are duplicated in $1. 616214571Sdimdups = \ 617214571Sdim $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \ 618214571Sdim $(words $(filter $v, $1))), $v))) 619214571Sdim 620214571Sdim# String equals 621214571Sdimequals = \ 622214571Sdim $(and $(findstring $(strip $1),$(strip $2)),\ 623214571Sdim $(findstring $(strip $2),$(strip $1))) 624214571Sdim 625214571Sdim# Remove a whole list of prefixes 626214571Sdim# $1 - List of prefixes 627214571Sdim# $2 - List of elements to process 628214571Sdimremove-prefixes = \ 629214571Sdim $(strip $(if $1,$(patsubst $(firstword $1)%,%,\ 630214571Sdim $(call remove-prefixes,$(filter-out $(firstword $1),$1),$2)),$2)) 631214571Sdim 632214571Sdim# Convert the string given to upper case, without any $(shell) 633214571Sdim# Inspired by http://lists.gnu.org/archive/html/help-make/2013-09/msg00009.html 634214571Sdimuppercase_table := a,A b,B c,C d,D e,E f,F g,G h,H i,I j,J k,K l,L m,M n,N o,O \ 635214571Sdim p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z 636214571Sdim 637214571Sdimuppercase_internal = \ 638214571Sdim $(if $(strip $1), $$(subst $(firstword $1), $(call uppercase_internal, \ 639214571Sdim $(wordlist 2, $(words $1), $1), $2)), $2) 640214571Sdim 641214571Sdim# Convert a string to upper case. Works only on a-z. 642214571Sdim# $1 - The string to convert 643214571Sdimuppercase = \ 644214571Sdim $(strip \ 645214571Sdim $(eval uppercase_result := $(call uppercase_internal, $(uppercase_table), $1)) \ 646214571Sdim $(uppercase_result) \ 647214571Sdim ) 648214571Sdim 649214571Sdim################################################################################ 650214571Sdim 651214571Sdimifneq ($(DISABLE_CACHE_FIND), true) 652214571Sdim # In Cygwin, finds are very costly, both because of expensive forks and because 653214571Sdim # of bad file system caching. Find is used extensively in $(shell) commands to 654214571Sdim # find source files. This makes rerunning make with no or few changes rather 655214571Sdim # expensive. To speed this up, these two macros are used to cache the results 656214571Sdim # of simple find commands for reuse. 657214571Sdim # 658214571Sdim # Runs a find and stores both the directories where it was run and the results. 659214571Sdim # This macro can be called multiple times to add to the cache. Only finds files 660214571Sdim # with no filters. 661214571Sdim # 662214571Sdim # Needs to be called with $(eval ) 663214571Sdim # 664214571Sdim # Even if the performance benifit is negligible on other platforms, keep the 665214571Sdim # functionality active unless explicitly disabled to exercise it more. 666214571Sdim # 667214571Sdim # Initialize FIND_CACHE_DIRS with := to make it a non recursively-expanded variable 668214571Sdim FIND_CACHE_DIRS := 669214571Sdim # Param 1 - Dirs to find in 670214571Sdim # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. 671214571Sdim define FillCacheFind 672214571Sdim # Filter out already cached dirs. The - is needed when FIND_CACHE_DIRS is empty 673214571Sdim # since filter out will then return empty. 674214571Sdim FIND_CACHE_NEW_DIRS := $$(filter-out $$(addsuffix /%,\ 675214571Sdim - $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS), $1) 676214571Sdim ifneq ($$(FIND_CACHE_NEW_DIRS), ) 677214571Sdim # Remove any trailing slash from dirs in the cache dir list 678214571Sdim FIND_CACHE_DIRS += $$(patsubst %/,%, $$(FIND_CACHE_NEW_DIRS)) 679214571Sdim FIND_CACHE := $$(sort $$(FIND_CACHE) $$(shell $(FIND) $$(FIND_CACHE_NEW_DIRS) \( -type f -o -type l \) $2)) 680214571Sdim endif 681214571Sdim endef 682214571Sdim 683214571Sdim # Mimics find by looking in the cache if all of the directories have been cached. 684214571Sdim # Otherwise reverts to shell find. This is safe to call on all platforms, even if 685214571Sdim # cache is deactivated. 686214571Sdim # 687214571Sdim # $1 can be either a directory or a file. If it's a directory, make 688214571Sdim # sure we have exactly one trailing slash before the wildcard. 689214571Sdim # The extra - is needed when FIND_CACHE_DIRS is empty but should be harmless. 690214571Sdim # 691214571Sdim # Param 1 - Dirs to find in 692214571Sdim # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. 693214571Sdim define CacheFind 694214571Sdim $(if $(filter-out $(addsuffix /%,- $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS),$1), \ 695214571Sdim $(shell $(FIND) $1 \( -type f -o -type l \) $2), \ 696214571Sdim $(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(FIND_CACHE))) 697214571Sdim endef 698214571Sdim 699214571Sdimelse 700214571Sdim # If CacheFind is disabled, just run the find command. 701214571Sdim # Param 1 - Dirs to find in 702214571Sdim # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. 703214571Sdim define CacheFind 704214571Sdim $(shell $(FIND) $1 \( -type f -o -type l \) $2) 705214571Sdim endef 706214571Sdimendif 707214571Sdim 708214571Sdim################################################################################ 709214571Sdim 710214571Sdimdefine AddFileToCopy 711214571Sdim # Helper macro for SetupCopyFiles 712214571Sdim # 1 : Source file 713214571Sdim # 2 : Dest file 714214571Sdim # 3 : Variable to add targets to 715214571Sdim # 4 : Macro to call for copy operation 716214571Sdim $2: $1 717214571Sdim $$(call LogInfo, Copying $$(patsubst $(OUTPUT_ROOT)/%,%,$$@)) 718214571Sdim $$($$(strip $4)) 719214571Sdim 720214571Sdim $3 += $2 721214571Sdimendef 722214571Sdim 723214571Sdim# Returns the value of the first argument 724214571Sdimidentity = \ 725214571Sdim $(strip $1) 726214571Sdim 727214571Sdim# Setup make rules for copying files, with an option to do more complex 728214571Sdim# processing instead of copying. 729214571Sdim# 730214571Sdim# Parameter 1 is the name of the rule. This name is used as variable prefix, 731214571Sdim# and the targets generated are listed in a variable by that name. 732214571Sdim# 733214571Sdim# Remaining parameters are named arguments. These include: 734214571Sdim# SRC : Source root dir (defaults to dir of first file) 735214571Sdim# DEST : Dest root dir 736214571Sdim# FILES : List of files to copy with absolute paths, or path relative to SRC. 737214571Sdim# Must be in SRC. 738214571Sdim# FLATTEN : Set to flatten the directory structure in the DEST dir. 739214571Sdim# MACRO : Optionally override the default macro used for making the copy. 740214571Sdim# Default is 'install-file' 741214571Sdim# NAME_MACRO : Optionally supply a macro that rewrites the target file name 742214571Sdim# based on the source file name 743214571SdimSetupCopyFiles = $(NamedParamsMacroTemplate) 744214571Sdimdefine SetupCopyFilesBody 745214571Sdim 746214571Sdim ifeq ($$($1_MACRO), ) 747214571Sdim $1_MACRO := install-file 748214571Sdim endif 749214571Sdim 750214571Sdim # Default SRC to the dir of the first file. 751214571Sdim ifeq ($$($1_SRC), ) 752214571Sdim $1_SRC := $$(dir $$(firstword $$($1_FILES))) 753214571Sdim endif 754214571Sdim 755214571Sdim ifeq ($$($1_NAME_MACRO), ) 756214571Sdim $1_NAME_MACRO := identity 757214571Sdim endif 758214571Sdim 759214571Sdim # Remove any trailing slash from SRC and DEST 760214571Sdim $1_SRC := $$(patsubst %/,%,$$($1_SRC)) 761214571Sdim $1_DEST := $$(patsubst %/,%,$$($1_DEST)) 762214571Sdim 763214571Sdim $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \ 764214571Sdim $$(eval $$(call AddFileToCopy, $$($1_SRC)/$$f, \ 765214571Sdim $$($1_DEST)/$$(call $$(strip $$($1_NAME_MACRO)),$$(if $$($1_FLATTEN),$$(notdir $$f),$$f)), \ 766214571Sdim $1, $$($1_MACRO)))) 767214571Sdim 768214571Sdimendef 769214571Sdim 770214571Sdim################################################################################ 771214571Sdim# ShellQuote 772214571Sdim# 773214571Sdim# Quotes a string with single quotes and replaces single quotes with '\'' so 774214571Sdim# that the contents survives being given to the shell. 775214571Sdim 776214571SdimShellQuote = \ 777214571Sdim $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE) 778214571Sdim 779214571Sdim################################################################################ 780214571Sdim# Write to and read from file 781214571Sdim 782214571Sdim# Param 1 - File to read 783214571SdimReadFile = \ 784214571Sdim $(shell $(CAT) $1) 785214571Sdim 786214571Sdim# Param 1 - Text to write 787214571Sdim# Param 2 - File to write to 788214571Sdimifeq ($(HAS_FILE_FUNCTION), true) 789214571Sdim WriteFile = \ 790214571Sdim $(file >$2,$(strip $1)) 791214571Sdimelse 792214571Sdim # Use printf to get consistent behavior on all platforms. 793214571Sdim WriteFile = \ 794214571Sdim $(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2) 795214571Sdimendif 796214571Sdim 797214571Sdim################################################################################ 798214571Sdim# DependOnVariable 799214571Sdim# 800214571Sdim# This macro takes a variable name and puts the value in a file only if the 801214571Sdim# value has changed since last. The name of the file is returned. This can be 802214571Sdim# used to create rule dependencies on make variable values. The following 803214571Sdim# example would get rebuilt if the value of SOME_VAR was changed: 804214571Sdim# 805214571Sdim# path/to/some-file: $(call DependOnVariable, SOME_VAR) 806214571Sdim# echo $(SOME_VAR) > $@ 807214571Sdim# 808214571Sdim# Note that leading and trailing white space in the value is ignored. 809214571Sdim# 810214571Sdim 811214571Sdim# Defines the sub directory structure to store variable value file in 812214571SdimDependOnVariableDirName = \ 813214571Sdim $(strip $(addsuffix $(if $(MODULE),/$(MODULE)), \ 814214571Sdim $(subst $(SRC_ROOT)/,, $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \ 815214571Sdim $(firstword $(MAKEFILE_LIST)), \ 816214571Sdim $(CURDIR)/$(firstword $(MAKEFILE_LIST)))))) 817214571Sdim 818214571Sdim# Defines the name of the file to store variable value in. Generates a name 819214571Sdim# unless parameter 2 is given. 820214571Sdim# Param 1 - Name of variable 821214571Sdim# Param 2 - (optional) name of file to store value in 822214571SdimDependOnVariableFileName = \ 823214571Sdim $(strip $(if $(strip $2), $2, \ 824214571Sdim $(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps)) 825214571Sdim 826214571Sdim# Does the actual work with parameters stripped. 827214571Sdim# If the file exists AND the contents is the same as the variable, do nothing 828214571Sdim# else print a new file. 829214571Sdim# Always returns the name of the file where the value was printed. 830214571Sdim# Param 1 - Name of variable 831214571Sdim# Param 2 - (optional) name of file to store value in 832214571SdimDependOnVariableHelper = \ 833214571Sdim $(strip \ 834214571Sdim $(eval -include $(call DependOnVariableFileName, $1, $2)) \ 835214571Sdim $(if $(call equals, $(strip $($1)), $(strip $($1_old))),,\ 836214571Sdim $(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \ 837214571Sdim $(if $(findstring $(LOG_LEVEL), trace), \ 838214571Sdim $(info NewVariable $1: >$(strip $($1))<) \ 839214571Sdim $(info OldVariable $1: >$(strip $($1_old))<)) \ 840214571Sdim $(call WriteFile, $1_old:=$(call DoubleDollar,$($1)), \ 841214571Sdim $(call DependOnVariableFileName, $1, $2))) \ 842214571Sdim $(call DependOnVariableFileName, $1, $2) \ 843214571Sdim ) 844214571Sdim 845214571Sdim# Main macro 846214571Sdim# Param 1 - Name of variable 847214571Sdim# Param 2 - (optional) name of file to store value in 848214571SdimDependOnVariable = \ 849214571Sdim $(call DependOnVariableHelper,$(strip $1),$(strip $2)) 850214571Sdim 851214571Sdim# LogCmdlines is only intended to be used by ExecuteWithLog 852214571Sdimifeq ($(LOG_CMDLINES), true) 853214571Sdim LogCmdlines = $(info $(strip $1)) 854214571Sdimelse 855214571Sdim LogCmdlines = 856214571Sdimendif 857214571Sdim 858214571Sdim################################################################################ 859214571Sdim# ExecuteWithLog will run a command and log the output appropriately. This is 860214571Sdim# meant to be used by commands that do "real" work, like a compilation. 861214571Sdim# The output is stored in a specified log file, which is displayed at the end 862214571Sdim# of the build in case of failure. The command line itself is stored in a file, 863214571Sdim# and also logged to stdout if the LOG=cmdlines option has been given. 864214571Sdim# 865214571Sdim# NOTE: If the command redirects stdout, the caller needs to wrap it in a 866214571Sdim# subshell (by adding parentheses around it), otherwise the redirect to the 867214571Sdim# subshell tee process will create a race condition where the target file may 868214571Sdim# not be fully written when the make recipe is done. 869214571Sdim# 870214571Sdim# Param 1 - The path to base the name of the log file / command line file on 871214571Sdim# Param 2 - The command to run 872214571SdimExecuteWithLog = \ 873214571Sdim $(call LogCmdlines, Exececuting: [$(strip $2)]) \ 874214571Sdim $(call WriteFile, $2, $(strip $1).cmdline) \ 875214571Sdim ( $(strip $2) > >($(TEE) $(strip $1).log) 2> >($(TEE) $(strip $1).log >&2) || \ 876214571Sdim ( exitcode=$(DOLLAR)? && \ 877214571Sdim $(CP) $(strip $1).log $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(BUILD_OUTPUT)/%,%,$(strip $1))).log && \ 878214571Sdim exit $(DOLLAR)exitcode ) ) 879214571Sdim 880214571Sdim################################################################################ 881214571Sdim# Find lib dir for module 882214571Sdim# Param 1 - module name 883214571Sdimifeq ($(OPENJDK_TARGET_OS_TYPE), unix) 884214571Sdim FindLibDirForModule = \ 885214571Sdim $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1)$(OPENJDK_TARGET_CPU_LIBDIR) 886214571Sdimelse 887214571Sdim FindLibDirForModule = \ 888214571Sdim $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1) 889214571Sdimendif 890214571Sdim 891214571Sdim################################################################################ 892214571Sdim# Return a string suitable for use after a -classpath or --module-path option. It 893214571Sdim# will be correct and safe to use on all platforms. Arguments are given as space 894214571Sdim# separate classpath entries. Safe for multiple nested calls. 895214571Sdim# param 1 : A space separated list of classpath entries 896214571Sdim# The surrounding strip is needed to keep additional whitespace out 897214571SdimPathList = \ 898214571Sdim "$(subst $(SPACE),$(PATH_SEP),$(strip $(subst $(DQUOTE),,$1)))" 899214571Sdim 900214571Sdim################################################################################ 901214571Sdim# Check if a specified hotspot variant is being built, or at least one of a 902214571Sdim# list of variants. Will return 'true' or 'false'. 903214571Sdim# $1 - the variant to test for 904214571Sdimcheck-jvm-variant = \ 905214571Sdim $(strip \ 906214571Sdim $(if $(filter-out $(VALID_JVM_VARIANTS), $1), \ 907214571Sdim $(error Internal error: Invalid variant tested: $1)) \ 908214571Sdim $(if $(filter $1, $(JVM_VARIANTS)), true, false)) 909214571Sdim 910214571Sdim################################################################################ 911214571Sdim# Converts a space separated list to a comma separated list. 912214571Sdim# 913214571Sdim# Replacing double-comma with a single comma is to workaround the issue with 914214571Sdim# some version of make on windows that doesn't substitute spaces with one comma 915214571Sdim# properly. 916214571SdimCommaList = \ 917214571Sdim $(strip \ 918214571Sdim $(subst $(COMMA)$(COMMA),$(COMMA),$(subst $(SPACE),$(COMMA),$(strip $1))) \ 919214571Sdim ) 920214571Sdim 921214571Sdim################################################################################ 922214571Sdim 923214571Sdim# Hook to include the corresponding custom file, if present. 924214571Sdim$(eval $(call IncludeCustomExtension, , common/MakeBase.gmk)) 925214571Sdim 926214571Sdimendif # _MAKEBASE_GMK 927214571Sdim