annotate make/common/MakeBase.gmk @ 1642:382d23edebb6

8136383: Improve make utilities containing and not-containing Reviewed-by: ihse
author erikj
date Tue, 15 Sep 2015 18:00:21 +0200
parents 8b56a0ce50f0
children 216f63a10515 c800f2919a1f
rev   line source
ohair@423 1 #
ihse@1349 2 # Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
ohair@423 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@423 4 #
ohair@423 5 # This code is free software; you can redistribute it and/or modify it
ohair@423 6 # under the terms of the GNU General Public License version 2 only, as
ohair@423 7 # published by the Free Software Foundation. Oracle designates this
ohair@423 8 # particular file as subject to the "Classpath" exception as provided
ohair@423 9 # by Oracle in the LICENSE file that accompanied this code.
ohair@423 10 #
ohair@423 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@423 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@423 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@423 14 # version 2 for more details (a copy is included in the LICENSE file that
ohair@423 15 # accompanied this code).
ohair@423 16 #
ohair@423 17 # You should have received a copy of the GNU General Public License version
ohair@423 18 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@423 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@423 20 #
ohair@423 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@423 22 # or visit www.oracle.com if you need additional information or have any
ohair@423 23 # questions.
ohair@423 24 #
ohair@423 25
ohair@423 26 ################################################################
ohair@423 27 #
ohair@423 28 # Setup common utility functions.
ohair@423 29 #
ohair@423 30 ################################################################
ohair@423 31
ohair@423 32 ifndef _MAKEBASE_GMK
ohair@423 33 _MAKEBASE_GMK := 1
ohair@423 34
ihse@1414 35 ifeq ($(wildcard $(SPEC)),)
ihse@1414 36 $(error MakeBase.gmk needs SPEC set to a proper spec.gmk)
ihse@1414 37 endif
ihse@1414 38
erikj@1453 39 # By defining this pseudo target, make will automatically remove targets
erikj@1453 40 # if their recipe fails so that a rebuild is automatically triggered on the
erikj@1453 41 # next make invocation.
erikj@1453 42 .DELETE_ON_ERROR:
ihse@1414 43
ihse@1637 44 ################################################################################
ihse@1637 45 # Definitions for special characters
ihse@1637 46 ################################################################################
ihse@1637 47
ihse@1637 48 # When calling macros, the spaces between arguments are
ihse@1637 49 # often semantically important! Sometimes we need to subst
ihse@1637 50 # spaces and commas, therefore we need the following macros.
ihse@1637 51 X:=
ihse@1637 52 SPACE:=$(X) $(X)
ihse@1637 53 COMMA:=,
ihse@1637 54 DOLLAR:=$$
ihse@1637 55 HASH:=\#
ihse@1637 56 LEFT_PAREN:=(
ihse@1637 57 RIGHT_PAREN:=)
ihse@1637 58 SQUOTE:='
ihse@1637 59 #'
ihse@1637 60 DQUOTE:="
ihse@1637 61 #"
ihse@1637 62 define NEWLINE
ihse@1637 63
ihse@1637 64
ihse@1637 65 endef
ihse@1637 66
ihse@1414 67 ##############################
ihse@1414 68 # Functions
ihse@1414 69 ##############################
ihse@1414 70
erikj@1486 71 ### Debug functions
erikj@1486 72
erikj@1486 73 # Prints the name and value of a variable
erikj@1486 74 PrintVar = \
erikj@1486 75 $(info $(strip $1) >$($(strip $1))<)
ihse@1414 76
ihse@1414 77 ### Functions for timers
ihse@1414 78
ihse@1414 79 # Store the build times in this directory.
ihse@1414 80 BUILDTIMESDIR=$(OUTPUT_ROOT)/make-support/build-times
ihse@1414 81
ihse@1414 82 # Record starting time for build of a sub repository.
ihse@1414 83 define RecordStartTime
ihse@1414 84 $(MKDIR) -p $(BUILDTIMESDIR)
ihse@1414 85 $(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)
ihse@1414 86 $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$(strip $1)_human_readable
ihse@1414 87 endef
ihse@1414 88
ihse@1414 89 # Record ending time and calculate the difference and store it in a
ihse@1414 90 # easy to read format. Handles builds that cross midnight. Expects
ihse@1414 91 # that a build will never take 24 hours or more.
ihse@1414 92 define RecordEndTime
ihse@1414 93 $(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)
ihse@1414 94 $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)_human_readable
ihse@1414 95 $(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$(strip $1)` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$(strip $1)` $1 | \
ihse@1414 96 $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \
ihse@1414 97 M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \
ihse@1414 98 > $(BUILDTIMESDIR)/build_time_diff_$(strip $1)
ihse@1414 99 endef
ihse@1414 100
ihse@1414 101 # Hook to be called when starting to execute a top-level target
ihse@1414 102 define TargetEnter
ihse@1414 103 $(PRINTF) "## Starting $(patsubst %-only,%,$@)\n"
ihse@1414 104 $(call RecordStartTime,$(patsubst %-only,%,$@))
ihse@1414 105 endef
ihse@1414 106
ihse@1414 107 # Hook to be called when finish executing a top-level target
ihse@1414 108 define TargetExit
ihse@1414 109 $(call RecordEndTime,$(patsubst %-only,%,$@))
ihse@1414 110 $(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \
ihse@1414 111 "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`"
ihse@1414 112 endef
ihse@1414 113
chegar@1120 114 ################################################################################
chegar@1120 115 # This macro translates $ into \$ to protect the $ from expansion in the shell.
chegar@1120 116 # To make this macro resilient against already escaped strings, first remove
chegar@1120 117 # any present escapes before escaping so that no double escapes are added.
chegar@1120 118 EscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1)))
chegar@1120 119
chegar@1120 120 ################################################################################
chegar@1120 121 # This macro translates $ into $$ to protect the string from make itself.
chegar@1120 122 DoubleDollar = $(subst $$,$$$$,$(strip $1))
chegar@1120 123
chegar@1120 124 ################################################################################
chegar@1120 125
ohair@423 126 # If the variable that you want to send to stdout for piping into a file or otherwise,
ohair@423 127 # is potentially long, for example the a list of file paths, eg a list of all package directories.
ohair@423 128 # Then you need to use ListPathsSafely, which optimistically splits the output into several shell
ohair@423 129 # calls as well as use compression on recurrent file paths segments, to get around the potential
ohair@423 130 # command line length problem that exists in cygwin and other shells.
ihse@910 131 compress_pre:=$(strip $(shell $(CAT) $(SRC_ROOT)/make/common/support/ListPathsSafely-pre-compress.incl))
ihse@910 132 compress_post:=$(strip $(shell $(CAT) $(SRC_ROOT)/make/common/support/ListPathsSafely-post-compress.incl))
ohair@423 133 compress_paths=$(compress_pre)\
ohair@423 134 $(subst $(SRC_ROOT),X97,\
ohair@423 135 $(subst $(OUTPUT_ROOT),X98,\
ohair@423 136 $(subst X,X00,\
ohair@423 137 $(subst $(SPACE),\n,$(strip $1)))))\
ohair@423 138 $(compress_post)
ohair@423 139
ihse@910 140 decompress_paths=$(SED) -f $(SRC_ROOT)/make/common/support/ListPathsSafely-uncompress.sed -e 's|X99|\\n|g' \
ihse@837 141 -e 's|X98|$(OUTPUT_ROOT)|g' -e 's|X97|$(SRC_ROOT)|g' \
ihse@837 142 -e 's|X00|X|g' | tr '\n' '$2'
ohair@423 143
ohair@423 144 define ListPathsSafely_If
ihse@837 145 $(if $(word $3,$($1)),$(eval $1_LPS$3:=$(call compress_paths,$(wordlist $3,$4,$($1)))))
ohair@423 146 endef
ohair@423 147
ohair@423 148 define ListPathsSafely_Printf
erikj@838 149 $(if $(strip $($1_LPS$4)),$(if $(findstring $(LOG_LEVEL),trace),,@)printf \
chegar@1120 150 -- "$(strip $(call EscapeDollar, $($1_LPS$4)))\n" | $(decompress_paths) $3)
ohair@423 151 endef
ohair@423 152
ohair@423 153 # Receipt example:
ihse@837 154 # rm -f thepaths
ihse@837 155 # $(call ListPathsSafely,THEPATHS,\n, >> thepaths)
ihse@837 156 # The \n argument means translate spaces into \n
ihse@837 157 # if instead , , (a space) is supplied, then spaces remain spaces.
ohair@423 158 define ListPathsSafely
ihse@837 159 $(if $(word 16001,$($1)),$(error Cannot list safely more than 16000 paths. $1 has $(words $($1)) paths!))
erikj@838 160 $(ECHO) $(LOG_DEBUG) Writing $(words $($1)) paths to '$3'
ihse@837 161 $(call ListPathsSafely_If,$1,$2,1,250)
ihse@837 162 $(call ListPathsSafely_If,$1,$2,251,500)
ihse@837 163 $(call ListPathsSafely_If,$1,$2,501,750)
ihse@837 164 $(call ListPathsSafely_If,$1,$2,751,1000)
ohair@423 165
ihse@837 166 $(call ListPathsSafely_If,$1,$2,1001,1250)
ihse@837 167 $(call ListPathsSafely_If,$1,$2,1251,1500)
ihse@837 168 $(call ListPathsSafely_If,$1,$2,1501,1750)
ihse@837 169 $(call ListPathsSafely_If,$1,$2,1751,2000)
ohair@423 170
ihse@837 171 $(call ListPathsSafely_If,$1,$2,2001,2250)
ihse@837 172 $(call ListPathsSafely_If,$1,$2,2251,2500)
ihse@837 173 $(call ListPathsSafely_If,$1,$2,2501,2750)
ihse@837 174 $(call ListPathsSafely_If,$1,$2,2751,3000)
ohair@423 175
ihse@837 176 $(call ListPathsSafely_If,$1,$2,3001,3250)
ihse@837 177 $(call ListPathsSafely_If,$1,$2,3251,3500)
ihse@837 178 $(call ListPathsSafely_If,$1,$2,3501,3750)
ihse@837 179 $(call ListPathsSafely_If,$1,$2,3751,4000)
ohair@423 180
ihse@837 181 $(call ListPathsSafely_If,$1,$2,4001,4250)
ihse@837 182 $(call ListPathsSafely_If,$1,$2,4251,4500)
ihse@837 183 $(call ListPathsSafely_If,$1,$2,4501,4750)
ihse@837 184 $(call ListPathsSafely_If,$1,$2,4751,5000)
ohair@423 185
ihse@837 186 $(call ListPathsSafely_If,$1,$2,5001,5250)
ihse@837 187 $(call ListPathsSafely_If,$1,$2,5251,5500)
ihse@837 188 $(call ListPathsSafely_If,$1,$2,5501,5750)
ihse@837 189 $(call ListPathsSafely_If,$1,$2,5751,6000)
ohair@423 190
ihse@837 191 $(call ListPathsSafely_If,$1,$2,6001,6250)
ihse@837 192 $(call ListPathsSafely_If,$1,$2,6251,6500)
ihse@837 193 $(call ListPathsSafely_If,$1,$2,6501,6750)
ihse@837 194 $(call ListPathsSafely_If,$1,$2,6751,7000)
ohair@423 195
ihse@837 196 $(call ListPathsSafely_If,$1,$2,7001,7250)
ihse@837 197 $(call ListPathsSafely_If,$1,$2,7251,7500)
ihse@837 198 $(call ListPathsSafely_If,$1,$2,7501,7750)
ihse@837 199 $(call ListPathsSafely_If,$1,$2,7751,8000)
ohair@423 200
ihse@837 201 $(call ListPathsSafely_If,$1,$2,8001,8250)
ihse@837 202 $(call ListPathsSafely_If,$1,$2,8251,8500)
ihse@837 203 $(call ListPathsSafely_If,$1,$2,8501,8750)
ihse@837 204 $(call ListPathsSafely_If,$1,$2,8751,9000)
ohair@423 205
ihse@837 206 $(call ListPathsSafely_If,$1,$2,9001,9250)
ihse@837 207 $(call ListPathsSafely_If,$1,$2,9251,9500)
ihse@837 208 $(call ListPathsSafely_If,$1,$2,9501,9750)
ihse@837 209 $(call ListPathsSafely_If,$1,$2,9751,10000)
ohair@423 210
ihse@837 211 $(call ListPathsSafely_If,$1,$2,10001,10250)
ihse@837 212 $(call ListPathsSafely_If,$1,$2,10251,10500)
ihse@837 213 $(call ListPathsSafely_If,$1,$2,10501,10750)
ihse@837 214 $(call ListPathsSafely_If,$1,$2,10751,11000)
erikj@499 215
ihse@837 216 $(call ListPathsSafely_If,$1,$2,11001,11250)
ihse@837 217 $(call ListPathsSafely_If,$1,$2,11251,11500)
ihse@837 218 $(call ListPathsSafely_If,$1,$2,11501,11750)
ihse@837 219 $(call ListPathsSafely_If,$1,$2,11751,12000)
erikj@499 220
ihse@837 221 $(call ListPathsSafely_If,$1,$2,12001,12250)
ihse@837 222 $(call ListPathsSafely_If,$1,$2,12251,12500)
ihse@837 223 $(call ListPathsSafely_If,$1,$2,12501,12750)
ihse@837 224 $(call ListPathsSafely_If,$1,$2,12751,13000)
erikj@499 225
ihse@837 226 $(call ListPathsSafely_If,$1,$2,13001,13250)
ihse@837 227 $(call ListPathsSafely_If,$1,$2,13251,13500)
ihse@837 228 $(call ListPathsSafely_If,$1,$2,13501,13750)
ihse@837 229 $(call ListPathsSafely_If,$1,$2,13751,14000)
erikj@499 230
ihse@837 231 $(call ListPathsSafely_If,$1,$2,14001,14250)
ihse@837 232 $(call ListPathsSafely_If,$1,$2,14251,14500)
ihse@837 233 $(call ListPathsSafely_If,$1,$2,14501,14750)
ihse@837 234 $(call ListPathsSafely_If,$1,$2,14751,15000)
erikj@499 235
ihse@837 236 $(call ListPathsSafely_If,$1,$2,15001,15250)
ihse@837 237 $(call ListPathsSafely_If,$1,$2,15251,15500)
ihse@837 238 $(call ListPathsSafely_If,$1,$2,15501,15750)
ihse@837 239 $(call ListPathsSafely_If,$1,$2,15751,16000)
erikj@499 240
ihse@837 241 $(call ListPathsSafely_Printf,$1,$2,$3,1)
ihse@837 242 $(call ListPathsSafely_Printf,$1,$2,$3,251)
ihse@837 243 $(call ListPathsSafely_Printf,$1,$2,$3,501)
ihse@837 244 $(call ListPathsSafely_Printf,$1,$2,$3,751)
ohair@423 245
ihse@837 246 $(call ListPathsSafely_Printf,$1,$2,$3,1001)
ihse@837 247 $(call ListPathsSafely_Printf,$1,$2,$3,1251)
ihse@837 248 $(call ListPathsSafely_Printf,$1,$2,$3,1501)
ihse@837 249 $(call ListPathsSafely_Printf,$1,$2,$3,1751)
ohair@423 250
ihse@837 251 $(call ListPathsSafely_Printf,$1,$2,$3,2001)
ihse@837 252 $(call ListPathsSafely_Printf,$1,$2,$3,2251)
ihse@837 253 $(call ListPathsSafely_Printf,$1,$2,$3,2501)
ihse@837 254 $(call ListPathsSafely_Printf,$1,$2,$3,2751)
ohair@423 255
ihse@837 256 $(call ListPathsSafely_Printf,$1,$2,$3,3001)
ihse@837 257 $(call ListPathsSafely_Printf,$1,$2,$3,3251)
ihse@837 258 $(call ListPathsSafely_Printf,$1,$2,$3,3501)
ihse@837 259 $(call ListPathsSafely_Printf,$1,$2,$3,3751)
ohair@423 260
ihse@837 261 $(call ListPathsSafely_Printf,$1,$2,$3,4001)
ihse@837 262 $(call ListPathsSafely_Printf,$1,$2,$3,4251)
ihse@837 263 $(call ListPathsSafely_Printf,$1,$2,$3,4501)
ihse@837 264 $(call ListPathsSafely_Printf,$1,$2,$3,4751)
ohair@423 265
ihse@837 266 $(call ListPathsSafely_Printf,$1,$2,$3,5001)
ihse@837 267 $(call ListPathsSafely_Printf,$1,$2,$3,5251)
ihse@837 268 $(call ListPathsSafely_Printf,$1,$2,$3,5501)
ihse@837 269 $(call ListPathsSafely_Printf,$1,$2,$3,5751)
ohair@423 270
ihse@837 271 $(call ListPathsSafely_Printf,$1,$2,$3,6001)
ihse@837 272 $(call ListPathsSafely_Printf,$1,$2,$3,6251)
ihse@837 273 $(call ListPathsSafely_Printf,$1,$2,$3,6501)
ihse@837 274 $(call ListPathsSafely_Printf,$1,$2,$3,6751)
ohair@423 275
ihse@837 276 $(call ListPathsSafely_Printf,$1,$2,$3,7001)
ihse@837 277 $(call ListPathsSafely_Printf,$1,$2,$3,7251)
ihse@837 278 $(call ListPathsSafely_Printf,$1,$2,$3,7501)
ihse@837 279 $(call ListPathsSafely_Printf,$1,$2,$3,7751)
ohair@423 280
ihse@837 281 $(call ListPathsSafely_Printf,$1,$2,$3,8001)
ihse@837 282 $(call ListPathsSafely_Printf,$1,$2,$3,8251)
ihse@837 283 $(call ListPathsSafely_Printf,$1,$2,$3,8501)
ihse@837 284 $(call ListPathsSafely_Printf,$1,$2,$3,8751)
ohair@423 285
ihse@837 286 $(call ListPathsSafely_Printf,$1,$2,$3,9001)
ihse@837 287 $(call ListPathsSafely_Printf,$1,$2,$3,9251)
ihse@837 288 $(call ListPathsSafely_Printf,$1,$2,$3,9501)
ihse@837 289 $(call ListPathsSafely_Printf,$1,$2,$3,9751)
erikj@499 290
ihse@837 291 $(call ListPathsSafely_Printf,$1,$2,$3,10001)
ihse@837 292 $(call ListPathsSafely_Printf,$1,$2,$3,10251)
ihse@837 293 $(call ListPathsSafely_Printf,$1,$2,$3,10501)
ihse@837 294 $(call ListPathsSafely_Printf,$1,$2,$3,10751)
erikj@499 295
ihse@837 296 $(call ListPathsSafely_Printf,$1,$2,$3,11001)
ihse@837 297 $(call ListPathsSafely_Printf,$1,$2,$3,11251)
ihse@837 298 $(call ListPathsSafely_Printf,$1,$2,$3,11501)
ihse@837 299 $(call ListPathsSafely_Printf,$1,$2,$3,11751)
erikj@499 300
ihse@837 301 $(call ListPathsSafely_Printf,$1,$2,$3,12001)
ihse@837 302 $(call ListPathsSafely_Printf,$1,$2,$3,12251)
ihse@837 303 $(call ListPathsSafely_Printf,$1,$2,$3,12501)
ihse@837 304 $(call ListPathsSafely_Printf,$1,$2,$3,12751)
erikj@499 305
ihse@837 306 $(call ListPathsSafely_Printf,$1,$2,$3,13001)
ihse@837 307 $(call ListPathsSafely_Printf,$1,$2,$3,13251)
ihse@837 308 $(call ListPathsSafely_Printf,$1,$2,$3,13501)
ihse@837 309 $(call ListPathsSafely_Printf,$1,$2,$3,13751)
erikj@499 310
ihse@837 311 $(call ListPathsSafely_Printf,$1,$2,$3,14001)
ihse@837 312 $(call ListPathsSafely_Printf,$1,$2,$3,14251)
ihse@837 313 $(call ListPathsSafely_Printf,$1,$2,$3,14501)
ihse@837 314 $(call ListPathsSafely_Printf,$1,$2,$3,14751)
erikj@499 315
ihse@837 316 $(call ListPathsSafely_Printf,$1,$2,$3,15001)
ihse@837 317 $(call ListPathsSafely_Printf,$1,$2,$3,15251)
ihse@837 318 $(call ListPathsSafely_Printf,$1,$2,$3,15501)
ihse@837 319 $(call ListPathsSafely_Printf,$1,$2,$3,15751)
ohair@423 320 endef
ohair@423 321
ohair@423 322 define ListPathsSafelyNow_IfPrintf
ihse@837 323 ifneq (,$$(word $4,$$($1)))
ihse@837 324 $$(eval $1_LPS$4:=$$(call compress_paths,$$(wordlist $4,$5,$$($1))))
ihse@837 325 $$(shell printf -- "$$(strip $$($1_LPS$4))\n" | $(decompress_paths) $3)
ihse@837 326 endif
ohair@423 327 endef
ohair@423 328
ohair@423 329 # And an non-receipt version:
ohair@423 330 define ListPathsSafelyNow
ihse@837 331 ifneq (,$$(word 10001,$$($1)))
ihse@837 332 $$(error Cannot list safely more than 10000 paths. $1 has $$(words $$($1)) paths!)
ihse@837 333 endif
ihse@837 334 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1,250)
ihse@837 335 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,251,500)
ihse@837 336 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,501,750)
ihse@837 337 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,751,1000)
ohair@423 338
ihse@837 339 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1001,1250)
ihse@837 340 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1251,1500)
ihse@837 341 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1501,1750)
ihse@837 342 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,1751,2000)
ohair@423 343
ihse@837 344 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2001,2250)
ihse@837 345 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2251,2500)
ihse@837 346 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2501,2750)
ihse@837 347 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,2751,3000)
ohair@423 348
ihse@837 349 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3001,3250)
ihse@837 350 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3251,3500)
ihse@837 351 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3501,3750)
ihse@837 352 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,3751,4000)
ohair@423 353
ihse@837 354 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4001,4250)
ihse@837 355 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4251,4500)
ihse@837 356 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4501,4750)
ihse@837 357 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,4751,5000)
ohair@423 358
ihse@837 359 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5001,5250)
ihse@837 360 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5251,5500)
ihse@837 361 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5501,5750)
ihse@837 362 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,5751,6000)
ohair@423 363
ihse@837 364 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6001,6250)
ihse@837 365 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6251,6500)
ihse@837 366 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6501,6750)
ihse@837 367 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,6751,7000)
ohair@423 368
ihse@837 369 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7001,7250)
ihse@837 370 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7251,7500)
ihse@837 371 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7501,7750)
ihse@837 372 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,7751,8000)
ohair@423 373
ihse@837 374 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8001,8250)
ihse@837 375 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8251,8500)
ihse@837 376 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8501,8750)
ihse@837 377 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,8751,9000)
ohair@423 378
ihse@837 379 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9001,9250)
ihse@837 380 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9251,9500)
ihse@837 381 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9501,9750)
ihse@837 382 $(call ListPathsSafelyNow_IfPrintf,$1,$2,$3,9751,10000)
ohair@423 383
ohair@423 384 endef
ohair@423 385
erikj@443 386 # The source tips can come from the Mercurial repository, or in the files
ihse@837 387 # $(HGTIP_FILENAME) which contains the tip but is also positioned in the same
ihse@837 388 # directory as the original $(HGDIR) directory.
ihse@837 389 # These should not be := assignments, only used from the root Makefile.
erikj@443 390 HG_VERSION = $(shell $(HG) version 2> /dev/null)
erikj@443 391 HG_DIRECTORY=.hg
erikj@443 392 HGTIP_FILENAME=.hgtip
erikj@443 393 HG_SEARCH = ./REPO ./*/REPO ./*/*/REPO ./*/*/*/REPO
erikj@443 394 REPO_LIST = $(patsubst ./%,%,$(patsubst %/,%,$(sort $(dir \
erikj@1547 395 $(shell $(CD) $(SRC_ROOT) ; \
erikj@1547 396 $(LS) -d $(HG_SEARCH:%/REPO=%/$(HG_DIRECTORY)) \
erikj@1547 397 $(HG_SEARCH:%/REPO=%/$(HGTIP_FILENAME)) \
ihse@837 398 2> /dev/null)))))
erikj@443 399
erikj@443 400 # Emit the repo:tip pairs to $@
erikj@443 401 define GetSourceTips
ihse@837 402 $(CD) $(SRC_ROOT) ; \
ihse@837 403 for i in $(REPO_LIST) IGNORE ; do \
ihse@837 404 if [ "$${i}" = "IGNORE" ] ; then \
ihse@837 405 continue; \
ihse@837 406 elif [ -d $${i}/$(HG_DIRECTORY) -a "$(HG_VERSION)" != "" ] ; then \
ihse@837 407 $(PRINTF) " %s:%s" \
ihse@837 408 "$${i}" `$(HG) tip --repository $${i} --template '{node|short}\n'` ; \
ihse@837 409 elif [ -f $${i}/$(HGTIP_FILENAME) ] ; then \
ihse@837 410 $(PRINTF) " %s:%s" \
ihse@837 411 "$${i}" `$(CAT) $${i}/$(HGTIP_FILENAME)` ; \
ihse@837 412 fi; \
ihse@837 413 done >> $@
ihse@837 414 $(PRINTF) "\n" >> $@
erikj@443 415 endef
erikj@443 416
erikj@443 417 # Create the HGTIP_FILENAME file. Called from jdk/make/closed/bundles.gmk
erikj@443 418 define CreateHgTip
ihse@837 419 $(HG) tip --repository $1 --template '{node|short}\n' > $1/$(HGTIP_FILENAME); \
ihse@837 420 $(ECHO) $1/$(HGTIP_FILENAME)
erikj@443 421 endef
erikj@443 422
erikj@443 423 define SetupLogging
ihse@1414 424 ifeq ($$(LOG_LEVEL), trace)
ihse@837 425 # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
ihse@837 426 # For each target executed, will print
ihse@837 427 # Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer)
ihse@837 428 # but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much
ihse@837 429 # (and causing a crash on Cygwin).
ihse@837 430 # Default shell seems to always be /bin/sh. Must override with bash to get this to work on Solaris.
ihse@837 431 # Only use time if it's GNU time which supports format and output file.
ihse@1414 432 WRAPPER_SHELL := $$(BASH) $$(SRC_ROOT)/common/bin/shell-tracer.sh $$(if $$(findstring yes,$$(IS_GNU_TIME)),$$(TIME),-) $$(OUTPUT_ROOT)/build-trace-time.log $$(SHELL)
ihse@1414 433 SHELL := $$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(WRAPPER_SHELL)
ihse@837 434 endif
ihse@837 435 # Never remove warning messages; this is just for completeness
ihse@1414 436 LOG_WARN :=
ihse@1414 437 ifneq ($$(findstring $$(LOG_LEVEL), info debug trace),)
ihse@1414 438 LOG_INFO :=
ihse@837 439 else
ihse@1414 440 LOG_INFO := > /dev/null
ihse@837 441 endif
ihse@1414 442 ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
ihse@1414 443 LOG_DEBUG :=
ihse@837 444 else
ihse@1414 445 LOG_DEBUG := > /dev/null
ihse@837 446 endif
ihse@1414 447 ifneq ($$(findstring $$(LOG_LEVEL), trace),)
ihse@1414 448 LOG_TRACE :=
ihse@837 449 else
ihse@1414 450 LOG_TRACE := > /dev/null
ihse@837 451 endif
erikj@443 452 endef
erikj@443 453
erikj@443 454 # Make sure logging is setup for everyone that includes MakeBase.gmk.
erikj@443 455 $(eval $(call SetupLogging))
erikj@443 456
erikj@1383 457 ################################################################################
erikj@1383 458 # Creates a sequence of increasing numbers (inclusive).
erikj@1383 459 # Param 1 - starting number
erikj@1383 460 # Param 2 - ending number
erikj@1383 461 sequence = \
erikj@1383 462 $(wordlist $1, $2, $(strip \
erikj@1383 463 $(eval SEQUENCE_COUNT :=) \
erikj@1383 464 $(call _sequence-do,$(strip $2))))
erikj@1383 465
erikj@1383 466 _sequence-do = \
erikj@1383 467 $(if $(word $1, $(SEQUENCE_COUNT)),, \
erikj@1383 468 $(eval SEQUENCE_COUNT += .) \
erikj@1383 469 $(words $(SEQUENCE_COUNT)) \
erikj@1383 470 $(call _sequence-do,$1))
erikj@1383 471
erikj@1383 472 ################################################################################
erikj@1383 473
erikj@1383 474 MAX_PARAMS := 30
erikj@1383 475 PARAM_SEQUENCE := $(call sequence, 2, $(MAX_PARAMS))
erikj@1383 476
erikj@1383 477 # Template for creating a macro taking named parameters. To use it, assign the
erikj@1383 478 # template to a variable with the name you want for your macro, using '='
erikj@1383 479 # assignment. Then define a macro body with the suffix "Body". The Body macro
erikj@1383 480 # should take 1 parameter which should be a unique string for that invocation
erikj@1383 481 # of the macro.
erikj@1383 482 # Ex:
erikj@1383 483 # SetupFoo = $(NamedParamsMacroTemplate)
erikj@1383 484 # define SetupFooBody
erikj@1383 485 # # do something
erikj@1383 486 # # access parameters as $$($1_BAR)
erikj@1383 487 # endef
erikj@1383 488 # Call it like this
erikj@1383 489 # $(eval $(call SetupFoo, BUILD_SOMETHING, \
erikj@1383 490 # BAR := some parameter value, \
erikj@1383 491 # ))
erikj@1383 492 define NamedParamsMacroTemplate
erikj@1383 493 $(if $($(MAX_PARAMS)),$(error Internal makefile error: \
erikj@1383 494 Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk))
erikj@1383 495 # Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix
erikj@1383 496 $(foreach i,$(PARAM_SEQUENCE), $(if $(strip $($i)),\
erikj@1383 497 $(strip $1)_$(strip $($i)))$(NEWLINE))
erikj@1383 498 # Debug print all named parameter names and values
erikj@1383 499 $(if $(findstring $(LOG_LEVEL),debug trace), \
erikj@1383 500 $(info $0 $(strip $1) $(foreach i,$(PARAM_SEQUENCE), \
erikj@1383 501 $(if $(strip $($i)),$(NEWLINE) $(strip [$i] $(if $(filter $(LOG_LEVEL), trace), \
erikj@1383 502 $($i), $(wordlist 1, 20, $($(i))) $(if $(word 21, $($(i))), ...)))))))
erikj@1383 503
erikj@1383 504 $(if $(DEBUG_$(strip $1)),
erikj@1383 505 $(info -------- <<< Begin expansion of $(strip $1)) \
erikj@1383 506 $(info $(call $(0)Body,$(strip $1))) \
erikj@1383 507 $(info -------- >>> End expansion of $(strip $1)) \
erikj@1383 508 )
erikj@1383 509
erikj@1383 510 $(call $(0)Body,$(strip $1))
ohair@492 511 endef
ohair@492 512
erikj@1383 513 ################################################################################
ohair@492 514 # Make directory without forking mkdir if not needed
erikj@1303 515 MakeDir = \
erikj@1303 516 $(strip $(if $(subst $(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),,$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)),\
erikj@1303 517 $(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9)))
ohair@492 518
erikj@1383 519 ################################################################################
erikj@1458 520 # Assign a variable only if it is empty
erikj@1458 521 # Param 1 - Variable to assign
erikj@1458 522 # Param 2 - Value to assign
erikj@1458 523 SetIfEmpty = \
erikj@1458 524 $(if $($(strip $1)),,$(eval $(strip $1) := $2))
erikj@1458 525
erikj@1458 526 ################################################################################
erikj@1383 527
ohair@492 528 ifeq ($(OPENJDK_TARGET_OS),solaris)
ihse@837 529 # On Solaris, if the target is a symlink and exists, cp won't overwrite.
ihse@837 530 # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
ihse@837 531 # name of the target file differs from the source file, rename after copy.
erikj@995 532 # If the source and target parent directories are the same, recursive copy doesn't work
erikj@995 533 # so we fall back on regular copy, which isn't preserving symlinks.
ihse@837 534 define install-file
ihse@1240 535 $(MKDIR) -p '$(@D)'
ohair@492 536 $(RM) '$@'
erikj@995 537 if [ "$(@D)" != "$(<D)" ]; then \
erikj@995 538 $(CP) -f -r -P '$<' '$(@D)'; \
erikj@995 539 if [ "$(@F)" != "$(<F)" ]; then \
erikj@995 540 $(MV) '$(@D)/$(<F)' '$@'; \
erikj@995 541 fi; \
erikj@995 542 else \
erikj@995 543 if [ -L '$<' ]; then \
erikj@995 544 $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \
erikj@995 545 exit 1; \
erikj@995 546 fi; \
erikj@995 547 $(CP) -f '$<' '$@'; \
erikj@995 548 fi
ihse@837 549 endef
ohair@492 550 else ifeq ($(OPENJDK_TARGET_OS),macosx)
ihse@837 551 # On mac, extended attributes sometimes creep into the source files, which may later
ihse@837 552 # cause the creation of ._* files which confuses testing. Clear these with xattr if
ihse@837 553 # set. Some files get their write permissions removed after being copied to the
ihse@837 554 # output dir. When these are copied again to images, xattr would fail. By only clearing
ihse@837 555 # attributes when they are present, failing on this is avoided.
ihse@837 556 define install-file
ihse@1240 557 $(MKDIR) -p '$(@D)'
erikj@668 558 $(CP) -fRP '$<' '$@'
erikj@668 559 if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi
ihse@837 560 endef
ohair@492 561 else
chegar@1120 562 # Running mkdir and cp in the same shell speeds up copy intensive tasks in Cygwin
chegar@1120 563 # significantly.
ihse@837 564 define install-file
ihse@1240 565 $(MKDIR) -p '$(@D)' && $(CP) -fP '$<' '$@'
ihse@837 566 endef
ohair@492 567 endif
ohair@492 568
erikj@1383 569 ################################################################################
chegar@1120 570 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
ihse@1349 571 uniq = \
ihse@1349 572 $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
ihse@1349 573
erikj@1642 574 # Returns all whitespace-separated words in $2 where at least one of the
erikj@1642 575 # whitespace-separated words in $1 is a substring.
erikj@1642 576 containing = \
erikj@1642 577 $(strip \
erikj@1642 578 $(foreach v,$(strip $2),\
erikj@1642 579 $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v)))))
erikj@1642 580
erikj@1642 581 # Returns all whitespace-separated words in $2 where none of the
erikj@1642 582 # whitespace-separated words in $1 is a substring.
erikj@1642 583 not-containing = \
erikj@1642 584 $(strip $(filter-out $(call containing,$1,$2),$2))
erikj@1642 585
ihse@1349 586 # Return a list of all string elements that are duplicated in $1.
ihse@1349 587 dups = \
ihse@1349 588 $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
ihse@1349 589 $(words $(filter $v, $1))), $v)))
erikj@555 590
erikj@1303 591 # String equals
erikj@1310 592 equals = \
erikj@1310 593 $(and $(findstring $(strip $1),$(strip $2)),\
erikj@1310 594 $(findstring $(strip $2),$(strip $1)))
erikj@1303 595
erikj@1486 596 # Remove a whole list of prefixes
erikj@1486 597 # $1 - List of prefixes
erikj@1486 598 # $2 - List of elements to process
erikj@1486 599 remove-prefixes = \
erikj@1486 600 $(strip $(if $1,$(patsubst $(firstword $1)%,%,\
erikj@1486 601 $(call remove-prefixes,$(filter-out $(firstword $1),$1),$2)),$2))
erikj@1486 602
erikj@1383 603 ################################################################################
erikj@1383 604
erikj@997 605 ifneq ($(DISABLE_CACHE_FIND), true)
mduigou@1029 606 # In Cygwin, finds are very costly, both because of expensive forks and because
mduigou@1029 607 # of bad file system caching. Find is used extensively in $(shell) commands to
mduigou@1029 608 # find source files. This makes rerunning make with no or few changes rather
mduigou@1029 609 # expensive. To speed this up, these two macros are used to cache the results
mduigou@1029 610 # of simple find commands for reuse.
mduigou@1029 611 #
mduigou@1029 612 # Runs a find and stores both the directories where it was run and the results.
mduigou@1029 613 # This macro can be called multiple times to add to the cache. Only finds files
mduigou@1029 614 # with no filters.
mduigou@1029 615 #
mduigou@1029 616 # Needs to be called with $(eval )
mduigou@1029 617 #
erikj@997 618 # Even if the performance benifit is negligible on other platforms, keep the
erikj@997 619 # functionality active unless explicitly disabled to exercise it more.
erikj@997 620 #
erikj@997 621 # Initialize FIND_CACHE_DIRS with := to make it a non recursively-expanded variable
erikj@997 622 FIND_CACHE_DIRS :=
mduigou@1029 623 # Param 1 - Dirs to find in
mduigou@1029 624 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
ihse@837 625 define FillCacheFind
mduigou@1029 626 # Filter out already cached dirs. The - is needed when FIND_CACHE_DIRS is empty
erikj@997 627 # since filter out will then return empty.
erikj@997 628 FIND_CACHE_NEW_DIRS := $$(filter-out $$(addsuffix /%,\
erikj@997 629 - $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS), $1)
erikj@997 630 ifneq ($$(FIND_CACHE_NEW_DIRS), )
erikj@997 631 # Remove any trailing slash from dirs in the cache dir list
erikj@997 632 FIND_CACHE_DIRS += $$(patsubst %/,%, $$(FIND_CACHE_NEW_DIRS))
mduigou@1029 633 FIND_CACHE := $$(sort $$(FIND_CACHE) $$(shell $(FIND) $$(FIND_CACHE_NEW_DIRS) \( -type f -o -type l \) $2))
erikj@997 634 endif
ihse@837 635 endef
erikj@555 636
mduigou@1029 637 # Mimics find by looking in the cache if all of the directories have been cached.
mduigou@1029 638 # Otherwise reverts to shell find. This is safe to call on all platforms, even if
mduigou@1029 639 # cache is deactivated.
mduigou@1029 640 #
chegar@1120 641 # $1 can be either a directory or a file. If it's a directory, make
chegar@1120 642 # sure we have exactly one trailing slash before the wildcard.
mduigou@1029 643 # The extra - is needed when FIND_CACHE_DIRS is empty but should be harmless.
mduigou@1029 644 #
mduigou@1029 645 # Param 1 - Dirs to find in
mduigou@1029 646 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
mduigou@1029 647 define CacheFind
erikj@997 648 $(if $(filter-out $(addsuffix /%,- $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS),$1), \
mduigou@1029 649 $(shell $(FIND) $1 \( -type f -o -type l \) $2), \
chegar@1120 650 $(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(FIND_CACHE)))
mduigou@1029 651 endef
chegar@1120 652
erikj@997 653 else
erikj@997 654 # If CacheFind is disabled, just run the find command.
mduigou@1029 655 # Param 1 - Dirs to find in
mduigou@1029 656 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
erikj@997 657 define CacheFind
mduigou@1029 658 $(shell $(FIND) $1 \( -type f -o -type l \) $2)
erikj@997 659 endef
erikj@997 660 endif
erikj@555 661
erikj@555 662 ################################################################################
erikj@555 663
chegar@1120 664 define AddFileToCopy
chegar@1120 665 # Helper macro for SetupCopyFiles
chegar@1120 666 # 1 : Source file
chegar@1120 667 # 2 : Dest file
chegar@1120 668 # 3 : Variable to add targets to
chegar@1120 669 # 4 : Macro to call for copy operation
chegar@1120 670 $2: $1
chegar@1120 671 $(ECHO) $(LOG_INFO) Copying $$(patsubst $(OUTPUT_ROOT)/%,%,$$@)
chegar@1120 672 $$($$(strip $4))
chegar@1120 673
chegar@1120 674 $3 += $2
chegar@1120 675 endef
chegar@1120 676
ihse@1331 677 # Setup make rules for copying files, with an option to do more complex
ihse@1331 678 # processing instead of copying.
ihse@1331 679 #
ihse@1331 680 # Parameter 1 is the name of the rule. This name is used as variable prefix,
ihse@1331 681 # and the targets generated are listed in a variable by that name.
ihse@1331 682 #
ihse@1331 683 # Remaining parameters are named arguments. These include:
ihse@1331 684 # SRC : Source root dir (defaults to dir of first file)
ihse@1331 685 # DEST : Dest root dir
ihse@1331 686 # FILES : List of files to copy with absolute paths, or path relative to SRC.
ihse@1331 687 # Must be in SRC.
ihse@1331 688 # FLATTEN : Set to flatten the directory structure in the DEST dir.
ihse@1331 689 # MACRO : Optionally override the default macro used for making the copy.
ihse@1331 690 # Default is 'install-file'
erikj@1383 691 SetupCopyFiles = $(NamedParamsMacroTemplate)
erikj@1383 692 define SetupCopyFilesBody
chegar@1120 693
chegar@1120 694 ifeq ($$($1_MACRO), )
chegar@1120 695 $1_MACRO := install-file
chegar@1120 696 endif
chegar@1120 697
erikj@1330 698 # Default SRC to the dir of the first file.
erikj@1330 699 ifeq ($$($1_SRC), )
erikj@1330 700 $1_SRC := $$(dir $$(firstword $$($1_FILES)))
erikj@1330 701 endif
erikj@1330 702
erikj@1330 703 # Remove any trailing slash from SRC
erikj@1330 704 $1_SRC := $$(patsubst %/,%,$$($1_SRC))
erikj@1330 705
chegar@1120 706 $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
chegar@1120 707 $$(eval $$(call AddFileToCopy, $$($1_SRC)/$$f, \
chegar@1120 708 $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO))))
chegar@1120 709
chegar@1120 710 endef
chegar@1120 711
chegar@1120 712 ################################################################################
erikj@1303 713 # ShellQuote
erikj@1303 714 #
ihse@1349 715 # Quotes a string with single quotes and replaces single quotes with '\'' so
erikj@1303 716 # that the contents survives being given to the shell.
erikj@1303 717
erikj@1303 718 ShellQuote = \
erikj@1303 719 $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE)
erikj@1303 720
erikj@1303 721 ################################################################################
erikj@1303 722 # Write to and read from file
erikj@1303 723
erikj@1303 724 # Param 1 - File to read
erikj@1303 725 ReadFile = \
erikj@1303 726 $(shell $(CAT) $1)
erikj@1303 727
erikj@1303 728 # Param 1 - Text to write
erikj@1303 729 # Param 2 - File to write to
erikj@1303 730 # Use printf to get consistent behavior on all platforms.
erikj@1303 731 WriteFile = \
erikj@1303 732 $(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2)
erikj@1303 733
erikj@1303 734 ################################################################################
erikj@1303 735 # DependOnVariable
erikj@1303 736 #
ihse@1349 737 # This macro takes a variable name and puts the value in a file only if the
ihse@1349 738 # value has changed since last. The name of the file is returned. This can be
erikj@1303 739 # used to create rule dependencies on make variable values. The following
erikj@1303 740 # example would get rebuilt if the value of SOME_VAR was changed:
erikj@1303 741 #
erikj@1303 742 # path/to/some-file: $(call DependOnVariable, SOME_VAR)
erikj@1303 743 # echo $(SOME_VAR) > $@
erikj@1303 744 #
erikj@1303 745 # Note that leading and trailing white space in the value is ignored.
erikj@1303 746 #
erikj@1303 747
erikj@1303 748 # Defines the sub directory structure to store variable value file in
erikj@1303 749 DependOnVariableDirName = \
erikj@1303 750 $(strip $(subst $(SRC_ROOT)/,,\
erikj@1303 751 $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \
erikj@1303 752 $(firstword $(MAKEFILE_LIST)), \
erikj@1303 753 $(CURDIR)/$(firstword $(MAKEFILE_LIST)))))
erikj@1303 754
erikj@1303 755 # Defines the name of the file to store variable value in. Generates a name
erikj@1303 756 # unless parameter 2 is given.
erikj@1303 757 # Param 1 - Name of variable
erikj@1303 758 # Param 2 - (optional) name of file to store value in
erikj@1303 759 DependOnVariableFileName = \
erikj@1303 760 $(strip $(if $(strip $2), $2, \
erikj@1303 761 $(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps))
erikj@1303 762
erikj@1303 763 # Does the actual work with parameters stripped.
erikj@1303 764 # If the file exists AND the contents is the same as the variable, do nothing
erikj@1303 765 # else print a new file.
erikj@1303 766 # Always returns the name of the file where the value was printed.
erikj@1303 767 # Param 1 - Name of variable
erikj@1303 768 # Param 2 - (optional) name of file to store value in
erikj@1303 769 DependOnVariableHelper = \
erikj@1303 770 $(strip $(if $(and $(wildcard $(call DependOnVariableFileName, $1, $2)),\
erikj@1303 771 $(call equals, $(strip $($1)), \
erikj@1303 772 $(call ReadFile, $(call DependOnVariableFileName, $1, $2)))),,\
erikj@1303 773 $(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \
erikj@1303 774 $(if $(findstring $(LOG_LEVEL), trace), \
erikj@1310 775 $(info Variable $1: >$(strip $($1))<) \
erikj@1310 776 $(info File: >$(call ReadFile, $(call DependOnVariableFileName, $1, $2))<)) \
erikj@1303 777 $(call WriteFile, $($1), $(call DependOnVariableFileName, $1, $2))) \
erikj@1303 778 $(call DependOnVariableFileName, $1, $2))
erikj@1303 779
erikj@1303 780 # Main macro
erikj@1303 781 # Param 1 - Name of variable
erikj@1303 782 # Param 2 - (optional) name of file to store value in
erikj@1303 783 DependOnVariable = \
erikj@1303 784 $(call DependOnVariableHelper,$(strip $1),$(strip $2))
erikj@1303 785
erikj@1303 786 ################################################################################
ihse@1633 787 # Failure logging support macros. These are supposed to be used by the Setup*
ihse@1633 788 # compilation macros.
ihse@1633 789 #
ihse@1633 790 # LogFailures will run a command and store a copy of output in a specified file.
ihse@1633 791 # If the command succeeds, the file is deleted, otherwise it is moved to the
ihse@1633 792 # failure-logs directory.
ihse@1633 793 # Param 1 - The log file of the failed command
ihse@1633 794 # Param 2 - A compact but representative name to describe this command
ihse@1633 795 # Param 3 - Command to run
ihse@1633 796 LogFailures = \
ihse@1633 797 ( ($(BASH) $(SRC_ROOT)/common/bin/logger.sh $1 $3 && $(RM) $1) || \
ihse@1633 798 (exitcode=$(DOLLAR)$(DOLLAR)? && $(MV) $1 $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(strip $2).log && exit $(DOLLAR)$(DOLLAR)exitcode) )
ihse@1633 799
ihse@1633 800 ################################################################################
erikj@1560 801 # Find lib dir for module
erikj@1560 802 # Param 1 - module name
erikj@1560 803 ifeq ($(OPENJDK_TARGET_OS_TYPE), unix)
erikj@1560 804 FindLibDirForModule = \
erikj@1560 805 $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1)$(OPENJDK_TARGET_CPU_LIBDIR)
erikj@1560 806 else
erikj@1560 807 FindLibDirForModule = \
erikj@1560 808 $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1)
erikj@1560 809 endif
erikj@1560 810
erikj@1560 811 ################################################################################
ihse@1637 812 # Return a string suitable for use after a -classpath option. It will correct and safe to use
ihse@1637 813 # on all platforms. Arguments are given as space separate classpath entries.
ihse@1637 814 # param 1 : A space separated list of classpath entries
ihse@1637 815 # The surrounding strip is needed to keep additional whitespace out
ihse@1637 816 PathList = \
ihse@1637 817 "$(subst $(SPACE),$(PATH_SEP),$(strip $1))"
ihse@1637 818
ihse@1637 819 ################################################################################
chegar@1120 820
chegar@1120 821 # Hook to include the corresponding custom file, if present.
chegar@1120 822 $(eval $(call IncludeCustomExtension, , common/MakeBase.gmk))
chegar@1120 823
ohair@423 824 endif # _MAKEBASE_GMK