annotate make/common/MakeBase.gmk @ 47290:b90a1b5b8142

manual merge
author mcimadamore
date Mon, 25 Sep 2017 16:38:40 +0100
parents 59bdd7243c52
children 9b9d2ce82f37
rev   line source
ohair@12258 1 #
ihse@43173 2 # Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
ohair@12258 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@12258 4 #
ohair@12258 5 # This code is free software; you can redistribute it and/or modify it
ohair@12258 6 # under the terms of the GNU General Public License version 2 only, as
ohair@12258 7 # published by the Free Software Foundation. Oracle designates this
ohair@12258 8 # particular file as subject to the "Classpath" exception as provided
ohair@12258 9 # by Oracle in the LICENSE file that accompanied this code.
ohair@12258 10 #
ohair@12258 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@12258 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@12258 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@12258 14 # version 2 for more details (a copy is included in the LICENSE file that
ohair@12258 15 # accompanied this code).
ohair@12258 16 #
ohair@12258 17 # You should have received a copy of the GNU General Public License version
ohair@12258 18 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@12258 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@12258 20 #
ohair@12258 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@12258 22 # or visit www.oracle.com if you need additional information or have any
ohair@12258 23 # questions.
ohair@12258 24 #
ohair@12258 25
ohair@12258 26 ################################################################
ohair@12258 27 #
ohair@12258 28 # Setup common utility functions.
ohair@12258 29 #
ohair@12258 30 ################################################################
ohair@12258 31
ohair@12258 32 ifndef _MAKEBASE_GMK
ohair@12258 33 _MAKEBASE_GMK := 1
ohair@12258 34
ihse@29662 35 ifeq ($(wildcard $(SPEC)),)
ihse@29662 36 $(error MakeBase.gmk needs SPEC set to a proper spec.gmk)
ihse@29662 37 endif
ihse@29662 38
erikj@29861 39 # By defining this pseudo target, make will automatically remove targets
erikj@29861 40 # if their recipe fails so that a rebuild is automatically triggered on the
erikj@29861 41 # next make invocation.
erikj@29861 42 .DELETE_ON_ERROR:
ihse@29662 43
ihse@32460 44 ################################################################################
ihse@32460 45 # Definitions for special characters
ihse@32460 46 ################################################################################
ihse@32460 47
ihse@32460 48 # When calling macros, the spaces between arguments are
ihse@32460 49 # often semantically important! Sometimes we need to subst
ihse@32460 50 # spaces and commas, therefore we need the following macros.
ihse@32460 51 X:=
ihse@32460 52 SPACE:=$(X) $(X)
ihse@32460 53 COMMA:=,
ihse@32460 54 DOLLAR:=$$
ihse@32460 55 HASH:=\#
ihse@32460 56 LEFT_PAREN:=(
ihse@32460 57 RIGHT_PAREN:=)
ihse@32460 58 SQUOTE:='
ihse@32460 59 #'
ihse@32460 60 DQUOTE:="
ihse@32460 61 #"
ihse@32460 62 define NEWLINE
ihse@32460 63
ihse@32460 64
ihse@32460 65 endef
ihse@32460 66
erikj@32807 67 # In GNU Make 4.0 and higher, there is a file function for writing to files.
erikj@32807 68 ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION))))
erikj@32807 69 HAS_FILE_FUNCTION := true
erikj@32807 70 endif
erikj@32807 71
ihse@29662 72 ##############################
ihse@29662 73 # Functions
ihse@29662 74 ##############################
ihse@29662 75
erikj@30095 76 ### Debug functions
erikj@30095 77
erikj@30095 78 # Prints the name and value of a variable
erikj@30095 79 PrintVar = \
erikj@30095 80 $(info $(strip $1) >$($(strip $1))<)
ihse@29662 81
ihse@29662 82 ### Functions for timers
ihse@29662 83
ihse@29662 84 # Store the build times in this directory.
mcimadamore@47290 85 BUILDTIMESDIR=$(OUTPUTDIR)/make-support/build-times
ihse@29662 86
ihse@29662 87 # Record starting time for build of a sub repository.
ihse@29662 88 define RecordStartTime
erikj@35008 89 $(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@29662 90 $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$(strip $1)_human_readable
ihse@29662 91 endef
ihse@29662 92
ihse@29662 93 # Record ending time and calculate the difference and store it in a
ihse@29662 94 # easy to read format. Handles builds that cross midnight. Expects
ihse@29662 95 # that a build will never take 24 hours or more.
ihse@29662 96 define RecordEndTime
ihse@29662 97 $(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@29662 98 $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)_human_readable
ihse@29662 99 $(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$(strip $1)` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$(strip $1)` $1 | \
ihse@29662 100 $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \
ihse@29662 101 M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \
ihse@29662 102 > $(BUILDTIMESDIR)/build_time_diff_$(strip $1)
ihse@29662 103 endef
ihse@29662 104
ihse@29662 105 # Hook to be called when starting to execute a top-level target
ihse@29662 106 define TargetEnter
ihse@29662 107 $(PRINTF) "## Starting $(patsubst %-only,%,$@)\n"
ihse@29662 108 $(call RecordStartTime,$(patsubst %-only,%,$@))
ihse@29662 109 endef
ihse@29662 110
ihse@29662 111 # Hook to be called when finish executing a top-level target
ihse@29662 112 define TargetExit
ihse@29662 113 $(call RecordEndTime,$(patsubst %-only,%,$@))
ihse@29662 114 $(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \
ihse@29662 115 "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`"
ihse@29662 116 endef
ihse@29662 117
chegar@25854 118 ################################################################################
chegar@25854 119 # This macro translates $ into \$ to protect the $ from expansion in the shell.
chegar@25854 120 # To make this macro resilient against already escaped strings, first remove
chegar@25854 121 # any present escapes before escaping so that no double escapes are added.
chegar@25854 122 EscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1)))
chegar@25854 123
chegar@25854 124 ################################################################################
ihse@42134 125 # This macro works just like EscapeDollar above, but for #.
ihse@42134 126 EscapeHash = $(subst \#,\\\#,$(subst \\\#,\#,$(strip $1)))
ihse@42134 127
ihse@42134 128 ################################################################################
chegar@25854 129 # This macro translates $ into $$ to protect the string from make itself.
chegar@25854 130 DoubleDollar = $(subst $$,$$$$,$(strip $1))
chegar@25854 131
chegar@25854 132 ################################################################################
erikj@32807 133 # ListPathsSafely can be used to print command parameters to a file. This is
erikj@32807 134 # typically done if the command line lenght risk being too long for the
erikj@32807 135 # OS/shell. In later make versions, the file function can be used for this
erikj@32807 136 # purpose. For earlier versions, a more complex implementation is provided.
erikj@32807 137 #
erikj@32807 138 # The function ListPathsSafely can be called either directly or, more commonly
erikj@32807 139 # from a recipe line. If called from a recipe, it will be executed in the
erikj@32807 140 # evaluation phase of that recipe, which means that it will write to the file
erikj@32807 141 # before any other line in the recipe has been run.
erikj@32807 142 ifeq ($(HAS_FILE_FUNCTION), true)
erikj@32807 143 # Param 1 - Name of variable containing paths/arguments to output
erikj@32807 144 # Param 2 - File to print to
erikj@32807 145 # Param 3 - Set to true to append to file instead of overwriting
erikj@32807 146 define ListPathsSafely
erikj@32807 147 $$(call MakeDir, $$(dir $$(strip $2)))
erikj@32807 148 $$(file $$(if $$(filter true, $$(strip $3)),>>,>) \
erikj@32807 149 $$(strip $2),$$(subst $$(SPACE),$$(NEWLINE),$$(strip $$($$(strip $1)))))
erikj@32807 150 endef
chegar@25854 151
erikj@37972 152 else # HAS_FILE_FUNCTION = false
erikj@32807 153
erikj@32807 154 $(eval compress_paths = \
erikj@47217 155 $(strip $(shell $(CAT) $(TOPDIR)/make/common/support/ListPathsSafely-pre-compress.incl)))
erikj@32807 156 compress_paths += \
erikj@47217 157 $(subst $(TOPDIR),X97, \
mcimadamore@47290 158 $(subst $(OUTPUTDIR),X98, \
ihse@34596 159 $(subst X,X00, \
erikj@32807 160 $(subst $(SPACE),\n,$(strip $1)))))
erikj@32807 161 $(eval compress_paths += \
erikj@47217 162 $(strip $(shell $(CAT) $(TOPDIR)/make/common/support/ListPathsSafely-post-compress.incl)))
ohair@12258 163
erikj@47217 164 decompress_paths=$(SED) -f $(TOPDIR)/make/common/support/ListPathsSafely-uncompress.sed \
erikj@32807 165 -e 's|X99|\\n|g' \
mcimadamore@47290 166 -e 's|X98|$(OUTPUTDIR)|g' -e 's|X97|$(TOPDIR)|g' \
erikj@32807 167 -e 's|X00|X|g'
ohair@12258 168
erikj@32807 169 ListPathsSafely_IfPrintf = \
erikj@32807 170 $(if $(word $3,$($(strip $1))), \
erikj@32807 171 $(shell $(PRINTF) -- "$(strip $(call EscapeDollar, \
erikj@32807 172 $(call compress_paths, $(wordlist $3,$4,$($(strip $1))))))\n" \
erikj@32807 173 | $(decompress_paths) >> $2))
ohair@12258 174
erikj@32807 175 # Param 1 - Name of variable containing paths/arguments to output
erikj@32807 176 # Param 2 - File to print to
erikj@32807 177 # Param 3 - Set to true to append to file instead of overwriting
ihse@34596 178 define ListPathsSafely
erikj@37972 179 ifneq (,$$(word 30001,$$($$(strip $1))))
erikj@37972 180 $$(error Cannot list safely more than 30000 paths. $1 has $$(words $$($$(strip $1))) paths!)
ihse@34596 181 endif
erikj@32807 182 $$(call MakeDir, $$(dir $2))
erikj@32807 183 ifneq ($$(strip $3), true)
erikj@32807 184 $$(shell $(RM) $$(strip $2))
erikj@32807 185 endif
ohair@12258 186
erikj@32807 187 $$(call ListPathsSafely_IfPrintf,$1,$2,1,250)
erikj@32807 188 $$(call ListPathsSafely_IfPrintf,$1,$2,251,500)
erikj@32807 189 $$(call ListPathsSafely_IfPrintf,$1,$2,501,750)
erikj@32807 190 $$(call ListPathsSafely_IfPrintf,$1,$2,751,1000)
ohair@12258 191
erikj@32807 192 $$(call ListPathsSafely_IfPrintf,$1,$2,1001,1250)
erikj@32807 193 $$(call ListPathsSafely_IfPrintf,$1,$2,1251,1500)
erikj@32807 194 $$(call ListPathsSafely_IfPrintf,$1,$2,1501,1750)
erikj@32807 195 $$(call ListPathsSafely_IfPrintf,$1,$2,1751,2000)
ohair@12258 196
erikj@32807 197 $$(call ListPathsSafely_IfPrintf,$1,$2,2001,2250)
erikj@32807 198 $$(call ListPathsSafely_IfPrintf,$1,$2,2251,2500)
erikj@32807 199 $$(call ListPathsSafely_IfPrintf,$1,$2,2501,2750)
erikj@32807 200 $$(call ListPathsSafely_IfPrintf,$1,$2,2751,3000)
ohair@12258 201
erikj@32807 202 $$(call ListPathsSafely_IfPrintf,$1,$2,3001,3250)
erikj@32807 203 $$(call ListPathsSafely_IfPrintf,$1,$2,3251,3500)
erikj@32807 204 $$(call ListPathsSafely_IfPrintf,$1,$2,3501,3750)
erikj@32807 205 $$(call ListPathsSafely_IfPrintf,$1,$2,3751,4000)
ohair@12258 206
erikj@32807 207 $$(call ListPathsSafely_IfPrintf,$1,$2,4001,4250)
erikj@32807 208 $$(call ListPathsSafely_IfPrintf,$1,$2,4251,4500)
erikj@32807 209 $$(call ListPathsSafely_IfPrintf,$1,$2,4501,4750)
erikj@32807 210 $$(call ListPathsSafely_IfPrintf,$1,$2,4751,5000)
ohair@12258 211
erikj@32807 212 $$(call ListPathsSafely_IfPrintf,$1,$2,5001,5250)
erikj@32807 213 $$(call ListPathsSafely_IfPrintf,$1,$2,5251,5500)
erikj@32807 214 $$(call ListPathsSafely_IfPrintf,$1,$2,5501,5750)
erikj@32807 215 $$(call ListPathsSafely_IfPrintf,$1,$2,5751,6000)
ohair@12258 216
erikj@32807 217 $$(call ListPathsSafely_IfPrintf,$1,$2,6001,6250)
erikj@32807 218 $$(call ListPathsSafely_IfPrintf,$1,$2,6251,6500)
erikj@32807 219 $$(call ListPathsSafely_IfPrintf,$1,$2,6501,6750)
erikj@32807 220 $$(call ListPathsSafely_IfPrintf,$1,$2,6751,7000)
ohair@12258 221
erikj@32807 222 $$(call ListPathsSafely_IfPrintf,$1,$2,7001,7250)
erikj@32807 223 $$(call ListPathsSafely_IfPrintf,$1,$2,7251,7500)
erikj@32807 224 $$(call ListPathsSafely_IfPrintf,$1,$2,7501,7750)
erikj@32807 225 $$(call ListPathsSafely_IfPrintf,$1,$2,7751,8000)
ohair@12258 226
erikj@32807 227 $$(call ListPathsSafely_IfPrintf,$1,$2,8001,8250)
erikj@32807 228 $$(call ListPathsSafely_IfPrintf,$1,$2,8251,8500)
erikj@32807 229 $$(call ListPathsSafely_IfPrintf,$1,$2,8501,8750)
erikj@32807 230 $$(call ListPathsSafely_IfPrintf,$1,$2,8751,9000)
ohair@12258 231
erikj@32807 232 $$(call ListPathsSafely_IfPrintf,$1,$2,9001,9250)
erikj@32807 233 $$(call ListPathsSafely_IfPrintf,$1,$2,9251,9500)
erikj@32807 234 $$(call ListPathsSafely_IfPrintf,$1,$2,9501,9750)
erikj@32807 235 $$(call ListPathsSafely_IfPrintf,$1,$2,9751,10000)
erikj@37972 236
erikj@37972 237 $$(call ListPathsSafely_IfPrintf,$1,$2,10001,10250)
erikj@37972 238 $$(call ListPathsSafely_IfPrintf,$1,$2,10251,10500)
erikj@37972 239 $$(call ListPathsSafely_IfPrintf,$1,$2,10501,10750)
erikj@37972 240 $$(call ListPathsSafely_IfPrintf,$1,$2,10751,11000)
erikj@37972 241
erikj@37972 242 $$(call ListPathsSafely_IfPrintf,$1,$2,11001,11250)
erikj@37972 243 $$(call ListPathsSafely_IfPrintf,$1,$2,11251,11500)
erikj@37972 244 $$(call ListPathsSafely_IfPrintf,$1,$2,11501,11750)
erikj@37972 245 $$(call ListPathsSafely_IfPrintf,$1,$2,11751,12000)
erikj@37972 246
erikj@37972 247 $$(call ListPathsSafely_IfPrintf,$1,$2,12001,12250)
erikj@37972 248 $$(call ListPathsSafely_IfPrintf,$1,$2,12251,12500)
erikj@37972 249 $$(call ListPathsSafely_IfPrintf,$1,$2,12501,12750)
erikj@37972 250 $$(call ListPathsSafely_IfPrintf,$1,$2,12751,13000)
erikj@37972 251
erikj@37972 252 $$(call ListPathsSafely_IfPrintf,$1,$2,13001,13250)
erikj@37972 253 $$(call ListPathsSafely_IfPrintf,$1,$2,13251,13500)
erikj@37972 254 $$(call ListPathsSafely_IfPrintf,$1,$2,13501,13750)
erikj@37972 255 $$(call ListPathsSafely_IfPrintf,$1,$2,13751,14000)
erikj@37972 256
erikj@37972 257 $$(call ListPathsSafely_IfPrintf,$1,$2,14001,14250)
erikj@37972 258 $$(call ListPathsSafely_IfPrintf,$1,$2,14251,14500)
erikj@37972 259 $$(call ListPathsSafely_IfPrintf,$1,$2,14501,14750)
erikj@37972 260 $$(call ListPathsSafely_IfPrintf,$1,$2,14751,15000)
erikj@37972 261
erikj@37972 262 $$(call ListPathsSafely_IfPrintf,$1,$2,15001,15250)
erikj@37972 263 $$(call ListPathsSafely_IfPrintf,$1,$2,15251,15500)
erikj@37972 264 $$(call ListPathsSafely_IfPrintf,$1,$2,15501,15750)
erikj@37972 265 $$(call ListPathsSafely_IfPrintf,$1,$2,15751,16000)
erikj@37972 266
erikj@37972 267 $$(call ListPathsSafely_IfPrintf,$1,$2,16001,16250)
erikj@37972 268 $$(call ListPathsSafely_IfPrintf,$1,$2,16251,16500)
erikj@37972 269 $$(call ListPathsSafely_IfPrintf,$1,$2,16501,16750)
erikj@37972 270 $$(call ListPathsSafely_IfPrintf,$1,$2,16751,17000)
erikj@37972 271
erikj@37972 272 $$(call ListPathsSafely_IfPrintf,$1,$2,17001,17250)
erikj@37972 273 $$(call ListPathsSafely_IfPrintf,$1,$2,17251,17500)
erikj@37972 274 $$(call ListPathsSafely_IfPrintf,$1,$2,17501,17750)
erikj@37972 275 $$(call ListPathsSafely_IfPrintf,$1,$2,17751,18000)
erikj@37972 276
erikj@37972 277 $$(call ListPathsSafely_IfPrintf,$1,$2,18001,18250)
erikj@37972 278 $$(call ListPathsSafely_IfPrintf,$1,$2,18251,18500)
erikj@37972 279 $$(call ListPathsSafely_IfPrintf,$1,$2,18501,18750)
erikj@37972 280 $$(call ListPathsSafely_IfPrintf,$1,$2,18751,19000)
erikj@37972 281
erikj@37972 282 $$(call ListPathsSafely_IfPrintf,$1,$2,19001,19250)
erikj@37972 283 $$(call ListPathsSafely_IfPrintf,$1,$2,19251,19500)
erikj@37972 284 $$(call ListPathsSafely_IfPrintf,$1,$2,19501,19750)
erikj@37972 285 $$(call ListPathsSafely_IfPrintf,$1,$2,19751,20000)
erikj@37972 286
erikj@37972 287 $$(call ListPathsSafely_IfPrintf,$1,$2,20001,20250)
erikj@37972 288 $$(call ListPathsSafely_IfPrintf,$1,$2,20251,20500)
erikj@37972 289 $$(call ListPathsSafely_IfPrintf,$1,$2,20501,20750)
erikj@37972 290 $$(call ListPathsSafely_IfPrintf,$1,$2,20751,21000)
erikj@37972 291
erikj@37972 292 $$(call ListPathsSafely_IfPrintf,$1,$2,21001,21250)
erikj@37972 293 $$(call ListPathsSafely_IfPrintf,$1,$2,21251,21500)
erikj@37972 294 $$(call ListPathsSafely_IfPrintf,$1,$2,21501,21750)
erikj@37972 295 $$(call ListPathsSafely_IfPrintf,$1,$2,21751,22000)
erikj@37972 296
erikj@37972 297 $$(call ListPathsSafely_IfPrintf,$1,$2,22001,22250)
erikj@37972 298 $$(call ListPathsSafely_IfPrintf,$1,$2,22251,22500)
erikj@37972 299 $$(call ListPathsSafely_IfPrintf,$1,$2,22501,22750)
erikj@37972 300 $$(call ListPathsSafely_IfPrintf,$1,$2,22751,23000)
erikj@37972 301
erikj@37972 302 $$(call ListPathsSafely_IfPrintf,$1,$2,23001,23250)
erikj@37972 303 $$(call ListPathsSafely_IfPrintf,$1,$2,23251,23500)
erikj@37972 304 $$(call ListPathsSafely_IfPrintf,$1,$2,23501,23750)
erikj@37972 305 $$(call ListPathsSafely_IfPrintf,$1,$2,23751,24000)
erikj@37972 306
erikj@37972 307 $$(call ListPathsSafely_IfPrintf,$1,$2,24001,24250)
erikj@37972 308 $$(call ListPathsSafely_IfPrintf,$1,$2,24251,24500)
erikj@37972 309 $$(call ListPathsSafely_IfPrintf,$1,$2,24501,24750)
erikj@37972 310 $$(call ListPathsSafely_IfPrintf,$1,$2,24751,25000)
erikj@37972 311
erikj@37972 312 $$(call ListPathsSafely_IfPrintf,$1,$2,25001,25250)
erikj@37972 313 $$(call ListPathsSafely_IfPrintf,$1,$2,25251,25500)
erikj@37972 314 $$(call ListPathsSafely_IfPrintf,$1,$2,25501,25750)
erikj@37972 315 $$(call ListPathsSafely_IfPrintf,$1,$2,25751,26000)
erikj@37972 316
erikj@37972 317 $$(call ListPathsSafely_IfPrintf,$1,$2,26001,26250)
erikj@37972 318 $$(call ListPathsSafely_IfPrintf,$1,$2,26251,26500)
erikj@37972 319 $$(call ListPathsSafely_IfPrintf,$1,$2,26501,26750)
erikj@37972 320 $$(call ListPathsSafely_IfPrintf,$1,$2,26751,27000)
erikj@37972 321
erikj@37972 322 $$(call ListPathsSafely_IfPrintf,$1,$2,27001,27250)
erikj@37972 323 $$(call ListPathsSafely_IfPrintf,$1,$2,27251,27500)
erikj@37972 324 $$(call ListPathsSafely_IfPrintf,$1,$2,27501,27750)
erikj@37972 325 $$(call ListPathsSafely_IfPrintf,$1,$2,27751,28000)
erikj@37972 326
erikj@37972 327 $$(call ListPathsSafely_IfPrintf,$1,$2,28001,28250)
erikj@37972 328 $$(call ListPathsSafely_IfPrintf,$1,$2,28251,28500)
erikj@37972 329 $$(call ListPathsSafely_IfPrintf,$1,$2,28501,28750)
erikj@37972 330 $$(call ListPathsSafely_IfPrintf,$1,$2,28751,29000)
erikj@37972 331
erikj@37972 332 $$(call ListPathsSafely_IfPrintf,$1,$2,29001,29250)
erikj@37972 333 $$(call ListPathsSafely_IfPrintf,$1,$2,29251,29500)
erikj@37972 334 $$(call ListPathsSafely_IfPrintf,$1,$2,29501,29750)
erikj@37972 335 $$(call ListPathsSafely_IfPrintf,$1,$2,29751,30000)
ihse@34596 336 endef
erikj@32807 337 endif # HAS_FILE_FUNCTION
ohair@12258 338
erikj@35008 339 ################################################################################
ihse@42282 340
ihse@42282 341 # A file containing a way to uniquely identify the source code revision that
ihse@42282 342 # the build was created from
ihse@42282 343 SOURCE_REVISION_TRACKER := $(SUPPORT_OUTPUTDIR)/src-rev/source-revision-tracker
ihse@42282 344
ihse@42282 345 # Locate all hg repositories included in the forest, as absolute paths
erikj@39110 346 FindAllReposAbs = \
erikj@47217 347 $(strip $(sort $(dir $(filter-out $(TOPDIR)/build/%, $(wildcard \
erikj@47217 348 $(addprefix $(TOPDIR)/, .hg */.hg */*/.hg */*/*/.hg */*/*/*/.hg) \
erikj@39110 349 )))))
erikj@39110 350
ihse@42282 351 # Locate all hg repositories included in the forest, as relative paths
erikj@39110 352 FindAllReposRel = \
erikj@47217 353 $(strip $(subst $(TOPDIR)/,.,$(patsubst $(TOPDIR)/%/, %, $(FindAllReposAbs))))
erikj@12801 354
erikj@35008 355 ################################################################################
erikj@35008 356
erikj@12801 357 define SetupLogging
asemenyuk@44465 358 ifeq ($$(LOG_PROFILE_TIMES_FILE), true)
asemenyuk@44465 359 ifeq ($$(IS_GNU_TIME), yes)
erikj@47217 360 SHELL := $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \
asemenyuk@44465 361 gnutime $$(TIME) \
mcimadamore@47290 362 $$(OUTPUTDIR)/build-profile.log $$(SHELL)
asemenyuk@44465 363 else ifneq ($$(FLOCK), )
erikj@47217 364 SHELL := $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \
asemenyuk@44465 365 flock $$(FLOCK) \
mcimadamore@47290 366 $$(OUTPUTDIR)/build-profile.log $$(SHELL)
asemenyuk@44465 367 endif
asemenyuk@44465 368 endif
asemenyuk@44465 369
ihse@29662 370 ifeq ($$(LOG_LEVEL), trace)
asemenyuk@44465 371 SHELL_NO_RECURSE := $$(SHELL)
ihse@20363 372 # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
ihse@20363 373 # For each target executed, will print
ihse@20363 374 # Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer)
ihse@20363 375 # but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much
ihse@20363 376 # (and causing a crash on Cygwin).
asemenyuk@44465 377 SHELL = $$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(SHELL_NO_RECURSE) -x
ihse@20363 378 endif
asemenyuk@44465 379
ihse@35444 380 # The warn level can never be turned off
ihse@35444 381 LogWarn = $$(info $$(strip $$1))
ihse@29662 382 LOG_WARN :=
ihse@29662 383 ifneq ($$(findstring $$(LOG_LEVEL), info debug trace),)
ihse@34596 384 LogInfo = $$(info $$(strip $$1))
ihse@29662 385 LOG_INFO :=
ihse@20363 386 else
ihse@34596 387 LogInfo =
ihse@29662 388 LOG_INFO := > /dev/null
ihse@20363 389 endif
ihse@29662 390 ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
ihse@34596 391 LogDebug = $$(info $$(strip $$1))
ihse@29662 392 LOG_DEBUG :=
ihse@20363 393 else
ihse@34596 394 LogDebug =
ihse@29662 395 LOG_DEBUG := > /dev/null
ihse@20363 396 endif
ihse@29662 397 ifneq ($$(findstring $$(LOG_LEVEL), trace),)
ihse@34596 398 LogTrace = $$(info $$(strip $$1))
ihse@29662 399 LOG_TRACE :=
ihse@20363 400 else
ihse@34596 401 LogTrace =
ihse@29662 402 LOG_TRACE := > /dev/null
ihse@20363 403 endif
erikj@12801 404 endef
erikj@12801 405
erikj@12801 406 # Make sure logging is setup for everyone that includes MakeBase.gmk.
erikj@12801 407 $(eval $(call SetupLogging))
erikj@12801 408
erikj@29312 409 ################################################################################
erikj@29312 410 # Creates a sequence of increasing numbers (inclusive).
erikj@29312 411 # Param 1 - starting number
erikj@29312 412 # Param 2 - ending number
erikj@29312 413 sequence = \
erikj@29312 414 $(wordlist $1, $2, $(strip \
erikj@29312 415 $(eval SEQUENCE_COUNT :=) \
erikj@29312 416 $(call _sequence-do,$(strip $2))))
erikj@29312 417
erikj@29312 418 _sequence-do = \
erikj@29312 419 $(if $(word $1, $(SEQUENCE_COUNT)),, \
erikj@29312 420 $(eval SEQUENCE_COUNT += .) \
erikj@29312 421 $(words $(SEQUENCE_COUNT)) \
erikj@29312 422 $(call _sequence-do,$1))
erikj@29312 423
erikj@29312 424 ################################################################################
erikj@29312 425
ihse@33394 426 MAX_PARAMS := 35
erikj@29312 427 PARAM_SEQUENCE := $(call sequence, 2, $(MAX_PARAMS))
erikj@29312 428
erikj@29312 429 # Template for creating a macro taking named parameters. To use it, assign the
erikj@29312 430 # template to a variable with the name you want for your macro, using '='
erikj@29312 431 # assignment. Then define a macro body with the suffix "Body". The Body macro
erikj@29312 432 # should take 1 parameter which should be a unique string for that invocation
erikj@29312 433 # of the macro.
erikj@29312 434 # Ex:
erikj@29312 435 # SetupFoo = $(NamedParamsMacroTemplate)
erikj@29312 436 # define SetupFooBody
erikj@29312 437 # # do something
erikj@29312 438 # # access parameters as $$($1_BAR)
erikj@29312 439 # endef
erikj@29312 440 # Call it like this
erikj@29312 441 # $(eval $(call SetupFoo, BUILD_SOMETHING, \
erikj@29312 442 # BAR := some parameter value, \
erikj@29312 443 # ))
erikj@29312 444 define NamedParamsMacroTemplate
erikj@29312 445 $(if $($(MAX_PARAMS)),$(error Internal makefile error: \
erikj@29312 446 Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk))
erikj@29312 447 # Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix
erikj@29312 448 $(foreach i,$(PARAM_SEQUENCE), $(if $(strip $($i)),\
erikj@43044 449 $(strip $1)_$(strip $(call EscapeHash, $(call DoubleDollar, $($i))))$(NEWLINE)))
erikj@29312 450 # Debug print all named parameter names and values
erikj@29312 451 $(if $(findstring $(LOG_LEVEL),debug trace), \
erikj@29312 452 $(info $0 $(strip $1) $(foreach i,$(PARAM_SEQUENCE), \
erikj@29312 453 $(if $(strip $($i)),$(NEWLINE) $(strip [$i] $(if $(filter $(LOG_LEVEL), trace), \
erikj@29312 454 $($i), $(wordlist 1, 20, $($(i))) $(if $(word 21, $($(i))), ...)))))))
erikj@29312 455
erikj@29312 456 $(if $(DEBUG_$(strip $1)),
erikj@29312 457 $(info -------- <<< Begin expansion of $(strip $1)) \
erikj@29312 458 $(info $(call $(0)Body,$(strip $1))) \
erikj@29312 459 $(info -------- >>> End expansion of $(strip $1)) \
erikj@29312 460 )
erikj@29312 461
erikj@29312 462 $(call $(0)Body,$(strip $1))
ohair@14111 463 endef
ohair@14111 464
erikj@29312 465 ################################################################################
ohair@14111 466 # Make directory without forking mkdir if not needed
erikj@35008 467 # 1: List of directories to create
erikj@28600 468 MakeDir = \
ihse@35444 469 $(strip \
ihse@35444 470 $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, $(if $(wildcard $d), , $d)))) \
ihse@35444 471 $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \
ihse@35444 472 )
ohair@14111 473
erikj@29312 474 ################################################################################
erikj@29866 475 # Assign a variable only if it is empty
erikj@29866 476 # Param 1 - Variable to assign
erikj@29866 477 # Param 2 - Value to assign
erikj@29866 478 SetIfEmpty = \
erikj@29866 479 $(if $($(strip $1)),,$(eval $(strip $1) := $2))
erikj@29866 480
erikj@29866 481 ################################################################################
erikj@29312 482
ohair@14111 483 ifeq ($(OPENJDK_TARGET_OS),solaris)
ihse@20363 484 # On Solaris, if the target is a symlink and exists, cp won't overwrite.
ihse@20363 485 # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
ihse@20363 486 # name of the target file differs from the source file, rename after copy.
erikj@23168 487 # If the source and target parent directories are the same, recursive copy doesn't work
erikj@23168 488 # so we fall back on regular copy, which isn't preserving symlinks.
ihse@20363 489 define install-file
ihse@27595 490 $(MKDIR) -p '$(@D)'
ohair@14111 491 $(RM) '$@'
erikj@23168 492 if [ "$(@D)" != "$(<D)" ]; then \
erikj@23168 493 $(CP) -f -r -P '$<' '$(@D)'; \
erikj@23168 494 if [ "$(@F)" != "$(<F)" ]; then \
erikj@23168 495 $(MV) '$(@D)/$(<F)' '$@'; \
erikj@23168 496 fi; \
erikj@23168 497 else \
erikj@23168 498 if [ -L '$<' ]; then \
erikj@23168 499 $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \
erikj@23168 500 exit 1; \
erikj@23168 501 fi; \
erikj@23168 502 $(CP) -f '$<' '$@'; \
erikj@23168 503 fi
ihse@20363 504 endef
ohair@14111 505 else ifeq ($(OPENJDK_TARGET_OS),macosx)
ihse@20363 506 # On mac, extended attributes sometimes creep into the source files, which may later
ihse@20363 507 # cause the creation of ._* files which confuses testing. Clear these with xattr if
ihse@20363 508 # set. Some files get their write permissions removed after being copied to the
ihse@20363 509 # output dir. When these are copied again to images, xattr would fail. By only clearing
ihse@20363 510 # attributes when they are present, failing on this is avoided.
erikj@37972 511 #
erikj@37972 512 # If copying a soft link to a directory, need to delete the target first to avoid
erikj@37972 513 # weird errors.
ihse@20363 514 define install-file
ihse@27595 515 $(MKDIR) -p '$(@D)'
erikj@37972 516 $(RM) '$@'
erikj@16580 517 $(CP) -fRP '$<' '$@'
erikj@16580 518 if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi
ihse@20363 519 endef
ohair@14111 520 else
ihse@20363 521 define install-file
erikj@35008 522 $(call MakeDir, $(@D))
erikj@35008 523 $(CP) -fP '$<' '$@'
ihse@20363 524 endef
ohair@14111 525 endif
ohair@14111 526
erikj@42425 527 # Variant of install file that does not preserve symlinks
erikj@42425 528 define install-file-nolink
erikj@42425 529 $(call MakeDir, $(@D))
erikj@42425 530 $(CP) -f '$<' '$@'
erikj@42425 531 endef
erikj@42425 532
erikj@29312 533 ################################################################################
erikj@41260 534 # Take two paths and return the path of the last common directory.
erikj@41260 535 # Ex: /foo/bar/baz, /foo/bar/banan -> /foo/bar
erikj@41260 536 # foo/bar/baz, /foo/bar -> <empty>
erikj@41260 537 #
erikj@41260 538 # The x prefix is used to preserve the presence of the initial slash
erikj@41260 539 #
erikj@41260 540 # $1 - Path to compare
erikj@41260 541 # $2 - Other path to compare
erikj@41260 542 FindCommonPathPrefix = \
erikj@41260 543 $(patsubst x%,%,$(subst $(SPACE),/,$(strip \
erikj@41260 544 $(call FindCommonPathPrefixHelper, \
erikj@41260 545 $(subst /,$(SPACE),x$(strip $1)), $(subst /,$(SPACE),x$(strip $2))) \
erikj@41260 546 )))
erikj@41260 547
erikj@41260 548 FindCommonPathPrefixHelper = \
erikj@41260 549 $(if $(call equals, $(firstword $1), $(firstword $2)), \
erikj@41260 550 $(firstword $1) \
erikj@41260 551 $(call FindCommonPathPrefixHelper, \
erikj@41260 552 $(wordlist 2, $(words $1), $1), $(wordlist 2, $(words $2), $2) \
erikj@41260 553 ) \
erikj@41260 554 )
erikj@41260 555
erikj@41260 556 # Convert a partial path into as many directory levels of ../, removing
erikj@41260 557 # leading and following /.
erikj@41260 558 # Ex: foo/bar/baz/ -> ../../..
erikj@41260 559 # foo/bar -> ../..
erikj@41260 560 # /foo -> ..
erikj@41260 561 DirToDotDot = \
erikj@41260 562 $(subst $(SPACE),/,$(foreach d, $(subst /,$(SPACE),$1),..))
erikj@41260 563
erikj@41260 564 # Computes the relative path from a directory to a file
erikj@41260 565 # $1 - File to compute the relative path to
erikj@41260 566 # $2 - Directory to compute the relative path from
erikj@41260 567 RelativePath = \
erikj@41260 568 $(eval $1_prefix := $(call FindCommonPathPrefix, $1, $2)) \
erikj@41260 569 $(eval $1_dotdots := $(call DirToDotDot, $(patsubst $($(strip $1)_prefix)/%, %, $2))) \
erikj@41260 570 $(eval $1_suffix := $(patsubst $($(strip $1)_prefix)/%, %, $1)) \
erikj@41260 571 $($(strip $1)_dotdots)/$($(strip $1)_suffix)
erikj@41260 572
erikj@41260 573 ################################################################################
erikj@41658 574 # link-file-* works similarly to install-file but creates a symlink instead.
erikj@41658 575 # There are two versions, either creating a relative or an absolute link. Be
erikj@41658 576 # careful when using this on Windows since the symlink created is only valid in
erikj@41658 577 # the unix emulation environment.
erikj@41658 578 define link-file-relative
erikj@41260 579 $(call MakeDir, $(@D))
erikj@41260 580 $(RM) $@
erikj@41260 581 $(LN) -s $(call RelativePath, $<, $(@D)) $@
erikj@41658 582 endef
erikj@41260 583
erikj@41658 584 define link-file-absolute
erikj@41260 585 $(call MakeDir, $(@D))
erikj@41260 586 $(RM) $@
erikj@41260 587 $(LN) -s $< $@
erikj@41658 588 endef
erikj@41260 589
erikj@41260 590 ################################################################################
chegar@25854 591 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
ihse@29156 592 uniq = \
ihse@29156 593 $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
ihse@29156 594
erikj@32553 595 # Returns all whitespace-separated words in $2 where at least one of the
erikj@32553 596 # whitespace-separated words in $1 is a substring.
erikj@32553 597 containing = \
erikj@32553 598 $(strip \
erikj@32553 599 $(foreach v,$(strip $2),\
erikj@32553 600 $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v)))))
erikj@32553 601
erikj@32553 602 # Returns all whitespace-separated words in $2 where none of the
erikj@32553 603 # whitespace-separated words in $1 is a substring.
erikj@32553 604 not-containing = \
erikj@32553 605 $(strip $(filter-out $(call containing,$1,$2),$2))
erikj@32553 606
ihse@29156 607 # Return a list of all string elements that are duplicated in $1.
ihse@29156 608 dups = \
ihse@29156 609 $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
ihse@29156 610 $(words $(filter $v, $1))), $v)))
erikj@15051 611
erikj@28600 612 # String equals
erikj@28607 613 equals = \
erikj@28607 614 $(and $(findstring $(strip $1),$(strip $2)),\
erikj@28607 615 $(findstring $(strip $2),$(strip $1)))
erikj@28600 616
erikj@30095 617 # Remove a whole list of prefixes
erikj@30095 618 # $1 - List of prefixes
erikj@30095 619 # $2 - List of elements to process
erikj@30095 620 remove-prefixes = \
erikj@30095 621 $(strip $(if $1,$(patsubst $(firstword $1)%,%,\
erikj@30095 622 $(call remove-prefixes,$(filter-out $(firstword $1),$1),$2)),$2))
erikj@30095 623
ihse@34596 624 # Convert the string given to upper case, without any $(shell)
ihse@34596 625 # Inspired by http://lists.gnu.org/archive/html/help-make/2013-09/msg00009.html
ihse@34596 626 uppercase_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 \
ihse@34596 627 p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z
ihse@34596 628
ihse@34596 629 uppercase_internal = \
ihse@34596 630 $(if $(strip $1), $$(subst $(firstword $1), $(call uppercase_internal, \
ihse@34596 631 $(wordlist 2, $(words $1), $1), $2)), $2)
ihse@34596 632
ihse@34596 633 # Convert a string to upper case. Works only on a-z.
ihse@34596 634 # $1 - The string to convert
ihse@34596 635 uppercase = \
ihse@34596 636 $(strip \
ihse@34596 637 $(eval uppercase_result := $(call uppercase_internal, $(uppercase_table), $1)) \
ihse@34596 638 $(uppercase_result) \
ihse@34596 639 )
ihse@34596 640
erikj@29312 641 ################################################################################
erikj@29312 642
erikj@23170 643 ifneq ($(DISABLE_CACHE_FIND), true)
mduigou@23984 644 # In Cygwin, finds are very costly, both because of expensive forks and because
mduigou@23984 645 # of bad file system caching. Find is used extensively in $(shell) commands to
mduigou@23984 646 # find source files. This makes rerunning make with no or few changes rather
mduigou@23984 647 # expensive. To speed this up, these two macros are used to cache the results
mduigou@23984 648 # of simple find commands for reuse.
mduigou@23984 649 #
mduigou@23984 650 # Runs a find and stores both the directories where it was run and the results.
mduigou@23984 651 # This macro can be called multiple times to add to the cache. Only finds files
mduigou@23984 652 # with no filters.
mduigou@23984 653 #
mduigou@23984 654 # Needs to be called with $(eval )
mduigou@23984 655 #
erikj@23170 656 # Even if the performance benifit is negligible on other platforms, keep the
erikj@23170 657 # functionality active unless explicitly disabled to exercise it more.
erikj@23170 658 #
erikj@23170 659 # Initialize FIND_CACHE_DIRS with := to make it a non recursively-expanded variable
erikj@23170 660 FIND_CACHE_DIRS :=
mduigou@23984 661 # Param 1 - Dirs to find in
mduigou@23984 662 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
ihse@20363 663 define FillCacheFind
mduigou@23984 664 # Filter out already cached dirs. The - is needed when FIND_CACHE_DIRS is empty
erikj@23170 665 # since filter out will then return empty.
erikj@23170 666 FIND_CACHE_NEW_DIRS := $$(filter-out $$(addsuffix /%,\
erikj@23170 667 - $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS), $1)
erikj@23170 668 ifneq ($$(FIND_CACHE_NEW_DIRS), )
erikj@23170 669 # Remove any trailing slash from dirs in the cache dir list
erikj@23170 670 FIND_CACHE_DIRS += $$(patsubst %/,%, $$(FIND_CACHE_NEW_DIRS))
mduigou@23984 671 FIND_CACHE := $$(sort $$(FIND_CACHE) $$(shell $(FIND) $$(FIND_CACHE_NEW_DIRS) \( -type f -o -type l \) $2))
erikj@23170 672 endif
ihse@20363 673 endef
erikj@15051 674
mduigou@23984 675 # Mimics find by looking in the cache if all of the directories have been cached.
mduigou@23984 676 # Otherwise reverts to shell find. This is safe to call on all platforms, even if
mduigou@23984 677 # cache is deactivated.
mduigou@23984 678 #
chegar@25854 679 # $1 can be either a directory or a file. If it's a directory, make
chegar@25854 680 # sure we have exactly one trailing slash before the wildcard.
mduigou@23984 681 # The extra - is needed when FIND_CACHE_DIRS is empty but should be harmless.
mduigou@23984 682 #
mduigou@23984 683 # Param 1 - Dirs to find in
mduigou@23984 684 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
mduigou@23984 685 define CacheFind
ihse@44725 686 $(if $(filter-out $(addsuffix /%,- $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS),$1), \
ihse@44725 687 $(if $(wildcard $1), $(shell $(FIND) $1 \( -type f -o -type l \) $2)), \
ihse@44725 688 $(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(FIND_CACHE)))
mduigou@23984 689 endef
chegar@25854 690
erikj@23170 691 else
erikj@23170 692 # If CacheFind is disabled, just run the find command.
mduigou@23984 693 # Param 1 - Dirs to find in
mduigou@23984 694 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
erikj@23170 695 define CacheFind
mduigou@23984 696 $(shell $(FIND) $1 \( -type f -o -type l \) $2)
erikj@23170 697 endef
erikj@23170 698 endif
erikj@15051 699
erikj@15051 700 ################################################################################
erikj@15051 701
chegar@25854 702 define AddFileToCopy
chegar@25854 703 # Helper macro for SetupCopyFiles
chegar@25854 704 # 1 : Source file
chegar@25854 705 # 2 : Dest file
chegar@25854 706 # 3 : Variable to add targets to
chegar@25854 707 # 4 : Macro to call for copy operation
erikj@42983 708 # 5 : Action text to log
chegar@25854 709 $2: $1
mcimadamore@47290 710 $$(call LogInfo, $(strip $5) $$(patsubst $(OUTPUTDIR)/%,%,$$@))
chegar@25854 711 $$($$(strip $4))
chegar@25854 712
chegar@25854 713 $3 += $2
chegar@25854 714 endef
chegar@25854 715
erikj@32811 716 # Returns the value of the first argument
erikj@32811 717 identity = \
erikj@32811 718 $(strip $1)
erikj@32811 719
ihse@28902 720 # Setup make rules for copying files, with an option to do more complex
ihse@28902 721 # processing instead of copying.
ihse@28902 722 #
ihse@28902 723 # Parameter 1 is the name of the rule. This name is used as variable prefix,
ihse@28902 724 # and the targets generated are listed in a variable by that name.
ihse@28902 725 #
ihse@28902 726 # Remaining parameters are named arguments. These include:
ihse@28902 727 # SRC : Source root dir (defaults to dir of first file)
ihse@28902 728 # DEST : Dest root dir
ihse@28902 729 # FILES : List of files to copy with absolute paths, or path relative to SRC.
ihse@28902 730 # Must be in SRC.
ihse@28902 731 # FLATTEN : Set to flatten the directory structure in the DEST dir.
ihse@28902 732 # MACRO : Optionally override the default macro used for making the copy.
ihse@28902 733 # Default is 'install-file'
erikj@32811 734 # NAME_MACRO : Optionally supply a macro that rewrites the target file name
erikj@32811 735 # based on the source file name
erikj@42983 736 # LOG_ACTION : Optionally specify a different action text for log messages
erikj@29312 737 SetupCopyFiles = $(NamedParamsMacroTemplate)
erikj@29312 738 define SetupCopyFilesBody
chegar@25854 739
chegar@25854 740 ifeq ($$($1_MACRO), )
chegar@25854 741 $1_MACRO := install-file
chegar@25854 742 endif
chegar@25854 743
erikj@28901 744 # Default SRC to the dir of the first file.
erikj@28901 745 ifeq ($$($1_SRC), )
erikj@28901 746 $1_SRC := $$(dir $$(firstword $$($1_FILES)))
erikj@28901 747 endif
erikj@28901 748
erikj@32811 749 ifeq ($$($1_NAME_MACRO), )
erikj@32811 750 $1_NAME_MACRO := identity
erikj@32811 751 endif
erikj@32811 752
erikj@42983 753 ifeq ($$($1_LOG_ACTION), )
erikj@42983 754 $1_LOG_ACTION := Copying
erikj@42983 755 endif
erikj@42983 756
ihse@34596 757 # Remove any trailing slash from SRC and DEST
erikj@28901 758 $1_SRC := $$(patsubst %/,%,$$($1_SRC))
ihse@34596 759 $1_DEST := $$(patsubst %/,%,$$($1_DEST))
erikj@28901 760
chegar@25854 761 $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
chegar@25854 762 $$(eval $$(call AddFileToCopy, $$($1_SRC)/$$f, \
erikj@32811 763 $$($1_DEST)/$$(call $$(strip $$($1_NAME_MACRO)),$$(if $$($1_FLATTEN),$$(notdir $$f),$$f)), \
erikj@42983 764 $1, $$($1_MACRO), $$($1_LOG_ACTION))))
chegar@25854 765
chegar@25854 766 endef
chegar@25854 767
chegar@25854 768 ################################################################################
ihse@44027 769 # Parse a multiple-keyword variable, like FOO="KEYWORD1=val1;KEYWORD2=val2;..."
ihse@44027 770 # These will be converted into a series of variables like FOO_KEYWORD1=val1,
ihse@44027 771 # FOO_KEYWORD2=val2, etc. Unknown keywords will cause an error.
ihse@44027 772 #
ihse@44027 773 # Parameter 1 is the name of the rule, and is also the name of the variable.
ihse@44027 774 #
ihse@44027 775 # Remaining parameters are named arguments. These include:
ihse@44027 776 # KEYWORDS A list of valid keywords
ihse@44027 777 # STRING_KEYWORDS A list of valid keywords, processed as string. This means
ihse@44027 778 # that '%20' will be replaced by ' ' to allow for multi-word strings.
ihse@44027 779 #
ihse@44027 780 ParseKeywordVariable = $(NamedParamsMacroTemplate)
ihse@44027 781 define ParseKeywordVariableBody
ihse@44027 782 ifneq ($$($1), )
ihse@44027 783 # To preserve spaces, substitute them with a hopefully unique pattern
ihse@44027 784 # before splitting and then re-substitute spaces back.
ihse@44027 785 $1_MANGLED := $$(subst $$(SPACE),||||,$$($1))
ihse@44027 786 $$(foreach mangled_part, $$(subst ;, , $$($1_MANGLED)), \
ihse@44027 787 $$(eval mangled_part_eval := $$(call DoubleDollar, $$(mangled_part))) \
ihse@44027 788 $$(eval part := $$$$(subst ||||,$$$$(SPACE),$$$$(mangled_part_eval))) \
ihse@44027 789 $$(eval $1_NO_MATCH := true) \
ihse@44027 790 $$(foreach keyword, $$($1_KEYWORDS), \
ihse@44027 791 $$(eval keyword_eval := $$(call DoubleDollar, $$(keyword))) \
ihse@44027 792 $$(if $$(filter $$(keyword)=%, $$(part)), \
ihse@44027 793 $$(eval $(strip $1)_$$$$(keyword_eval) := $$$$(strip $$$$(patsubst $$$$(keyword_eval)=%, %, $$$$(part)))) \
ihse@44027 794 $$(eval $1_NO_MATCH := ) \
ihse@44027 795 ) \
ihse@44027 796 ) \
ihse@44027 797 $$(foreach keyword, $$($1_STRING_KEYWORDS), \
ihse@44027 798 $$(eval keyword_eval := $$(call DoubleDollar, $$(keyword))) \
ihse@44027 799 $$(if $$(filter $$(keyword)=%, $$(part)), \
ihse@44027 800 $$(eval $(strip $1)_$$$$(keyword_eval) := $$$$(strip $$$$(subst %20, , $$$$(patsubst $$$$(keyword_eval)=%, %, $$$$(part))))) \
ihse@44027 801 $$(eval $1_NO_MATCH := ) \
ihse@44027 802 ) \
ihse@44027 803 ) \
ihse@44027 804 $$(if $$($1_NO_MATCH), \
ihse@44027 805 $$(if $$(filter $$(part), $$($1_KEYWORDS) $$($1_STRING_KEYWORDS)), \
ihse@44027 806 $$(info Keyword $$(part) for $1 needs to be assigned a value.) \
ihse@44027 807 , \
ihse@44027 808 $$(info $$(part) is not a valid keyword for $1.) \
ihse@44027 809 $$(info Valid keywords: $$($1_KEYWORDS) $$($1_STRING_KEYWORDS).) \
ihse@44027 810 ) \
ihse@44027 811 $$(error Cannot continue) \
ihse@44027 812 ) \
ihse@44027 813 )
ihse@44027 814 endif
ihse@44027 815 endef
ihse@44027 816
ihse@44027 817 ################################################################################
erikj@28600 818 # ShellQuote
erikj@28600 819 #
ihse@29156 820 # Quotes a string with single quotes and replaces single quotes with '\'' so
erikj@28600 821 # that the contents survives being given to the shell.
erikj@28600 822
erikj@28600 823 ShellQuote = \
erikj@28600 824 $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE)
erikj@28600 825
erikj@28600 826 ################################################################################
ihse@44027 827 # FixPath
ihse@44027 828 #
ihse@44027 829 # On Windows, converts a path from cygwin/unix style (e.g. /bin/foo) into
ihse@44027 830 # "mixed mode" (e.g. c:/cygwin/bin/foo). On other platforms, return the path
ihse@44027 831 # unchanged.
ihse@44027 832 # This is normally not needed since we use the FIXPATH prefix for command lines,
ihse@44027 833 # but might be needed in certain circumstances.
ihse@44027 834 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@44027 835 FixPath = \
ihse@44027 836 $(shell $(CYGPATH) -m $1)
ihse@44027 837 else
ihse@44027 838 FixPath = \
ihse@44027 839 $1
ihse@44027 840 endif
ihse@44027 841
ihse@44027 842 ################################################################################
erikj@28600 843 # Write to and read from file
erikj@28600 844
erikj@28600 845 # Param 1 - File to read
erikj@28600 846 ReadFile = \
erikj@28600 847 $(shell $(CAT) $1)
erikj@28600 848
erikj@28600 849 # Param 1 - Text to write
erikj@28600 850 # Param 2 - File to write to
erikj@32807 851 ifeq ($(HAS_FILE_FUNCTION), true)
erikj@32807 852 WriteFile = \
erikj@32807 853 $(file >$2,$(strip $1))
erikj@32807 854 else
ihse@34596 855 # Use printf to get consistent behavior on all platforms.
ihse@34596 856 WriteFile = \
ihse@34596 857 $(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2)
erikj@32807 858 endif
erikj@28600 859
erikj@28600 860 ################################################################################
erikj@28600 861 # DependOnVariable
erikj@28600 862 #
ihse@29156 863 # This macro takes a variable name and puts the value in a file only if the
ihse@29156 864 # value has changed since last. The name of the file is returned. This can be
erikj@28600 865 # used to create rule dependencies on make variable values. The following
erikj@28600 866 # example would get rebuilt if the value of SOME_VAR was changed:
erikj@28600 867 #
erikj@28600 868 # path/to/some-file: $(call DependOnVariable, SOME_VAR)
erikj@28600 869 # echo $(SOME_VAR) > $@
erikj@28600 870 #
erikj@28600 871 # Note that leading and trailing white space in the value is ignored.
erikj@28600 872 #
erikj@28600 873
erikj@28600 874 # Defines the sub directory structure to store variable value file in
erikj@28600 875 DependOnVariableDirName = \
alanb@36506 876 $(strip $(addsuffix $(if $(MODULE),/$(MODULE)), \
erikj@47217 877 $(subst $(TOPDIR)/,, $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \
erikj@28600 878 $(firstword $(MAKEFILE_LIST)), \
alanb@36506 879 $(CURDIR)/$(firstword $(MAKEFILE_LIST))))))
erikj@28600 880
erikj@28600 881 # Defines the name of the file to store variable value in. Generates a name
erikj@28600 882 # unless parameter 2 is given.
erikj@28600 883 # Param 1 - Name of variable
erikj@28600 884 # Param 2 - (optional) name of file to store value in
erikj@28600 885 DependOnVariableFileName = \
erikj@28600 886 $(strip $(if $(strip $2), $2, \
erikj@28600 887 $(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps))
erikj@28600 888
erikj@28600 889 # Does the actual work with parameters stripped.
erikj@28600 890 # If the file exists AND the contents is the same as the variable, do nothing
erikj@28600 891 # else print a new file.
erikj@28600 892 # Always returns the name of the file where the value was printed.
erikj@28600 893 # Param 1 - Name of variable
erikj@28600 894 # Param 2 - (optional) name of file to store value in
erikj@28600 895 DependOnVariableHelper = \
erikj@32807 896 $(strip \
erikj@32807 897 $(eval -include $(call DependOnVariableFileName, $1, $2)) \
erikj@32807 898 $(if $(call equals, $(strip $($1)), $(strip $($1_old))),,\
erikj@32807 899 $(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \
erikj@32807 900 $(if $(findstring $(LOG_LEVEL), trace), \
erikj@32807 901 $(info NewVariable $1: >$(strip $($1))<) \
erikj@32807 902 $(info OldVariable $1: >$(strip $($1_old))<)) \
ihse@42134 903 $(call WriteFile, $1_old:=$(call DoubleDollar,$(call EscapeHash,$($1))), \
erikj@33054 904 $(call DependOnVariableFileName, $1, $2))) \
erikj@32807 905 $(call DependOnVariableFileName, $1, $2) \
erikj@32807 906 )
erikj@28600 907
erikj@28600 908 # Main macro
erikj@28600 909 # Param 1 - Name of variable
erikj@28600 910 # Param 2 - (optional) name of file to store value in
erikj@28600 911 DependOnVariable = \
erikj@28600 912 $(call DependOnVariableHelper,$(strip $1),$(strip $2))
erikj@28600 913
ihse@35444 914 # LogCmdlines is only intended to be used by ExecuteWithLog
ihse@35444 915 ifeq ($(LOG_CMDLINES), true)
ihse@35444 916 LogCmdlines = $(info $(strip $1))
ihse@35444 917 else
ihse@35444 918 LogCmdlines =
ihse@35444 919 endif
ihse@35444 920
erikj@28600 921 ################################################################################
ihse@35444 922 # ExecuteWithLog will run a command and log the output appropriately. This is
ihse@35444 923 # meant to be used by commands that do "real" work, like a compilation.
ihse@35444 924 # The output is stored in a specified log file, which is displayed at the end
ihse@35444 925 # of the build in case of failure. The command line itself is stored in a file,
ihse@35444 926 # and also logged to stdout if the LOG=cmdlines option has been given.
ihse@32344 927 #
erikj@39607 928 # NOTE: If the command redirects stdout, the caller needs to wrap it in a
erikj@39607 929 # subshell (by adding parentheses around it), otherwise the redirect to the
erikj@39607 930 # subshell tee process will create a race condition where the target file may
erikj@39607 931 # not be fully written when the make recipe is done.
erikj@39607 932 #
ihse@35444 933 # Param 1 - The path to base the name of the log file / command line file on
ihse@35444 934 # Param 2 - The command to run
ihse@35444 935 ExecuteWithLog = \
ihse@35444 936 $(call LogCmdlines, Exececuting: [$(strip $2)]) \
ihse@35444 937 $(call WriteFile, $2, $(strip $1).cmdline) \
erikj@39607 938 ( $(strip $2) > >($(TEE) $(strip $1).log) 2> >($(TEE) $(strip $1).log >&2) || \
ihse@35444 939 ( exitcode=$(DOLLAR)? && \
mcimadamore@47290 940 $(CP) $(strip $1).log $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).log && \
mcimadamore@47290 941 $(CP) $(strip $1).cmdline $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).cmdline && \
erikj@39607 942 exit $(DOLLAR)exitcode ) )
ihse@32344 943
ihse@32344 944 ################################################################################
erikj@31310 945 # Find lib dir for module
erikj@31310 946 # Param 1 - module name
erikj@42528 947 FindLibDirForModule = \
erikj@42528 948 $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1)
erikj@31310 949
erikj@31310 950 ################################################################################
mchung@40241 951 # Return a string suitable for use after a -classpath or --module-path option. It
erikj@37030 952 # will be correct and safe to use on all platforms. Arguments are given as space
erikj@37030 953 # separate classpath entries. Safe for multiple nested calls.
ihse@32460 954 # param 1 : A space separated list of classpath entries
ihse@32460 955 # The surrounding strip is needed to keep additional whitespace out
ihse@32460 956 PathList = \
erikj@37030 957 "$(subst $(SPACE),$(PATH_SEP),$(strip $(subst $(DQUOTE),,$1)))"
ihse@32460 958
ihse@32460 959 ################################################################################
erikj@37402 960 # Check if a specified hotspot variant is being built, or at least one of a
erikj@37402 961 # list of variants. Will return 'true' or 'false'.
erikj@37402 962 # $1 - the variant to test for
erikj@37402 963 check-jvm-variant = \
erikj@37402 964 $(strip \
erikj@37402 965 $(if $(filter-out $(VALID_JVM_VARIANTS), $1), \
erikj@37402 966 $(error Internal error: Invalid variant tested: $1)) \
erikj@37402 967 $(if $(filter $1, $(JVM_VARIANTS)), true, false))
erikj@37402 968
erikj@37402 969 ################################################################################
redestad@37770 970 # Converts a space separated list to a comma separated list.
redestad@37770 971 #
redestad@37770 972 # Replacing double-comma with a single comma is to workaround the issue with
redestad@37770 973 # some version of make on windows that doesn't substitute spaces with one comma
redestad@37770 974 # properly.
redestad@37770 975 CommaList = \
redestad@37770 976 $(strip \
redestad@37770 977 $(subst $(COMMA)$(COMMA),$(COMMA),$(subst $(SPACE),$(COMMA),$(strip $1))) \
redestad@37770 978 )
redestad@37770 979
redestad@37770 980 ################################################################################
ihse@45323 981 # Converts a space separated list to a colon separated list.
ihse@45323 982 #
ihse@45323 983 # Replacing double-colon with a single colon is to workaround the issue with
ihse@45323 984 # some version of make on windows that doesn't substitute spaces with one colon
ihse@45323 985 # properly.
ihse@45323 986 ColonList = \
ihse@45323 987 $(strip \
ihse@45323 988 $(subst ::,:,$(subst $(SPACE),:,$(strip $1))) \
ihse@45323 989 )
ihse@45323 990
ihse@45323 991 ################################################################################
chegar@25854 992
chegar@25854 993 # Hook to include the corresponding custom file, if present.
chegar@25854 994 $(eval $(call IncludeCustomExtension, , common/MakeBase.gmk))
chegar@25854 995
ohair@12258 996 endif # _MAKEBASE_GMK