1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
|
#
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
################################################################
#
# Setup common utility functions.
#
################################################################
ifndef _MAKEBASE_GMK
_MAKEBASE_GMK := 1
ifeq ($(wildcard $(SPEC)),)
$(error MakeBase.gmk needs SPEC set to a proper spec.gmk)
endif
# By defining this pseudo target, make will automatically remove targets
# if their recipe fails so that a rebuild is automatically triggered on the
# next make invocation.
.DELETE_ON_ERROR:
################################################################################
# Definitions for special characters
################################################################################
# When calling macros, the spaces between arguments are
# often semantically important! Sometimes we need to subst
# spaces and commas, therefore we need the following macros.
X:=
SPACE:=$(X) $(X)
COMMA:=,
DOLLAR:=$$
HASH:=\#
LEFT_PAREN:=(
RIGHT_PAREN:=)
SQUOTE:='
#'
DQUOTE:="
#"
define NEWLINE
endef
# Make sure we have a value (could be overridden on command line by caller)
CREATING_BUILDJDK ?= false
# Certain features only work in newer version of GNU Make. The build will still
# function in 3.81, but will be less performant.
ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION))))
HAS_FILE_FUNCTION := true
CORRECT_FUNCTION_IN_RECIPE_EVALUATION := true
RWILDCARD_WORKS := true
endif
# For convenience, MakeBase.gmk continues to include these separate files, at
# least for now.
include $(TOPDIR)/make/common/Utils.gmk
include $(TOPDIR)/make/common/MakeIO.gmk
include $(TOPDIR)/make/common/CopyFiles.gmk
################################################################################
# Functions for timers
################################################################################
# Store the build times in this directory.
BUILDTIMESDIR=$(OUTPUTDIR)/make-support/build-times
# Record starting time for build of a sub repository.
define RecordStartTime
$(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) && \
$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$(strip $1)_human_readable
endef
# Record ending time and calculate the difference and store it in a
# easy to read format. Handles builds that cross midnight. Expects
# that a build will never take 24 hours or more.
define RecordEndTime
$(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)
$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)_human_readable
$(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$(strip $1)` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$(strip $1)` $1 | \
$(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \
M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \
> $(BUILDTIMESDIR)/build_time_diff_$(strip $1)
endef
# Hook to be called when starting to execute a top-level target
define TargetEnter
$(PRINTF) "## Starting $(patsubst %-only,%,$@)\n"
$(call RecordStartTime,$(patsubst %-only,%,$@))
endef
# Hook to be called when finish executing a top-level target
define TargetExit
$(call RecordEndTime,$(patsubst %-only,%,$@))
$(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \
"`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`"
endef
################################################################################
# A file containing a way to uniquely identify the source code revision that
# the build was created from
SOURCE_REVISION_TRACKER := $(SUPPORT_OUTPUTDIR)/src-rev/source-revision-tracker
# Locate all hg repositories included in the forest, as absolute paths
FindAllReposAbs = \
$(strip $(sort $(dir $(filter-out $(TOPDIR)/build/%, $(wildcard \
$(addprefix $(TOPDIR)/, .hg */.hg */*/.hg */*/*/.hg */*/*/*/.hg) \
$(addprefix $(TOPDIR)/, .git */.git */*/.git */*/*/.git */*/*/*/.git) \
)))))
# Locate all hg repositories included in the forest, as relative paths
FindAllReposRel = \
$(strip $(subst $(TOPDIR)/,.,$(patsubst $(TOPDIR)/%/, %, $(FindAllReposAbs))))
################################################################################
define SetupLogging
ifeq ($$(LOG_PROFILE_TIMES_FILE), true)
ifeq ($$(IS_GNU_TIME), yes)
SHELL := $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \
gnutime $$(TIME) \
$$(OUTPUTDIR)/build-profile.log $$(SHELL)
else ifneq ($$(FLOCK), )
SHELL := $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \
flock $$(FLOCK) \
$$(OUTPUTDIR)/build-profile.log $$(SHELL)
endif
endif
ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
SHELL := $$(SHELL) -x
endif
ifeq ($$(LOG_LEVEL), trace)
SHELL_NO_RECURSE := $$(SHELL)
# Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
# For each target executed, will print
# Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer)
# but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much
# (and causing a crash on Cygwin).
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
endif
# The warn level can never be turned off
LogWarn = $$(info $$(strip $$1))
LOG_WARN :=
ifneq ($$(findstring $$(LOG_LEVEL), info debug trace),)
LogInfo = $$(info $$(strip $$1))
LOG_INFO :=
else
LogInfo =
LOG_INFO := > /dev/null
endif
ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
LogDebug = $$(info $$(strip $$1))
LOG_DEBUG :=
else
LogDebug =
LOG_DEBUG := > /dev/null
endif
ifneq ($$(findstring $$(LOG_LEVEL), trace),)
LogTrace = $$(info $$(strip $$1))
LOG_TRACE :=
else
LogTrace =
LOG_TRACE := > /dev/null
endif
endef
# Make sure logging is setup for everyone that includes MakeBase.gmk.
$(eval $(call SetupLogging))
################################################################################
MAX_PARAMS := 36
PARAM_SEQUENCE := $(call sequence, 2, $(MAX_PARAMS))
# Template for creating a macro taking named parameters. To use it, assign the
# template to a variable with the name you want for your macro, using '='
# assignment. Then define a macro body with the suffix "Body". The Body macro
# should take 1 parameter which should be a unique string for that invocation
# of the macro.
# Ex:
# SetupFoo = $(NamedParamsMacroTemplate)
# define SetupFooBody
# # do something
# # access parameters as $$($1_BAR)
# endef
# Call it like this
# $(eval $(call SetupFoo, BUILD_SOMETHING, \
# BAR := some parameter value, \
# ))
define NamedParamsMacroTemplate
$(if $($(MAX_PARAMS)),$(error Internal makefile error: \
Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk))
# Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix
$(foreach i,$(PARAM_SEQUENCE), $(if $(strip $($i)),\
$(strip $1)_$(strip $(call EscapeHash, $(call DoubleDollar, $($i))))$(NEWLINE)))
# Debug print all named parameter names and values
$(if $(findstring $(LOG_LEVEL),debug trace), \
$(info $0 $(strip $1) $(foreach i,$(PARAM_SEQUENCE), \
$(if $(strip $($i)),$(NEWLINE) $(strip [$i] $(if $(filter $(LOG_LEVEL), trace), \
$($i), $(wordlist 1, 20, $($(i))) $(if $(word 21, $($(i))), ...)))))))
$(if $(DEBUG_$(strip $1)),
$(info -------- <<< Begin expansion of $(strip $1)) \
$(info $(call $(0)Body,$(strip $1))) \
$(info -------- >>> End expansion of $(strip $1)) \
)
$(call $(0)Body,$(strip $1))
endef
################################################################################
# Make directory without forking mkdir if not needed.
#
# If a directory with an encoded space is provided, the wildcard function
# sometimes returns false answers (typically if the dir existed when the
# makefile was parsed, but was deleted by a previous rule). In that case, always
# call mkdir regardless of what wildcard says.
#
# 1: List of directories to create
MakeDir = \
$(strip \
$(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \
$(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \
$(if $(wildcard $d), , $d) \
) \
))) \
$(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \
)
# Make directory for target file. Should handle spaces in filenames. Just
# calling $(call MakeDir $(@D)) will not work if the directory contains a space
# and the target file already exists. In that case, the target file will have
# its wildcard ? resolved and the $(@D) will evaluate each space separated dir
# part on its own.
MakeTargetDir = \
$(call MakeDir, $(dir $(call EncodeSpace, $@)))
################################################################################
# All install-file and related macros automatically call DecodeSpace when needed.
ifeq ($(call isTargetOs, solaris), true)
# On Solaris, if the target is a symlink and exists, cp won't overwrite.
# Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
# name of the target file differs from the source file, rename after copy.
# If the source and target parent directories are the same, recursive copy doesn't work
# so we fall back on regular copy, which isn't preserving symlinks.
define install-file
$(call MakeTargetDir)
$(RM) '$(call DecodeSpace, $@)'
if [ '$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))' != \
'$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))' ]; then \
$(CP) -f -r -P '$(call DecodeSpace, $<)' \
'$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))'; \
if [ '$(call DecodeSpace, $(notdir $(call EncodeSpace, $@)))' != \
'$(call DecodeSpace, $(notdir $(call EncodeSpace, $(<))))' ]; then \
$(MV) '$(call DecodeSpace, $(dir $(call EncodeSpace, $@))/$(notdir $(call EncodeSpace, $<)))' \
'$(call DecodeSpace, $@)'; \
fi; \
else \
if [ -L '$(call DecodeSpace, $<)' ]; then \
$(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \
exit 1; \
fi; \
$(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
fi
endef
else ifeq ($(call isTargetOs, macosx), true)
# On mac, extended attributes sometimes creep into the source files, which may later
# cause the creation of ._* files which confuses testing. Clear these with xattr if
# set. Some files get their write permissions removed after being copied to the
# output dir. When these are copied again to images, xattr would fail. By only clearing
# attributes when they are present, failing on this is avoided.
#
# If copying a soft link to a directory, need to delete the target first to avoid
# weird errors.
define install-file
$(call MakeTargetDir)
$(RM) '$(call DecodeSpace, $@)'
# Work around a weirdness with cp on Macosx. When copying a symlink, if
# the target of the link is write protected (e.g. 444), cp will add
# write permission for the user on the target file (644). Avoid this by
# using ln to create a new link instead.
if [ -h '$(call DecodeSpace, $<)' ]; then \
$(LN) -s "`$(READLINK) '$(call DecodeSpace, $<)'`" '$(call DecodeSpace, $@)'; \
else \
$(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
fi
if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then \
$(XATTR) -cs '$(call DecodeSpace, $@)'; \
fi
endef
else
define install-file
$(call MakeTargetDir)
$(CP) -fP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
endef
endif
# Variant of install file that does not preserve symlinks
define install-file-nolink
$(call MakeTargetDir)
$(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
endef
################################################################################
# link-file-* works similarly to install-file but creates a symlink instead.
# There are two versions, either creating a relative or an absolute link. Be
# careful when using this on Windows since the symlink created is only valid in
# the unix emulation environment.
# In msys2 we use mklink /J because its ln would perform a deep copy of the target.
# This inhibits performance and can lead to issues with long paths. With mklink /J
# relative linking does not work, so we handle the link as absolute path.
ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2)
define link-file-relative
$(call MakeTargetDir)
$(RM) '$(call DecodeSpace, $@)'
cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))"
endef
else
define link-file-relative
$(call MakeTargetDir)
$(RM) '$(call DecodeSpace, $@)'
$(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)'
endef
endif
ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2)
define link-file-absolute
$(call MakeTargetDir)
$(RM) '$(call DecodeSpace, $@)'
cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))"
endef
else
define link-file-absolute
$(call MakeTargetDir)
$(RM) '$(call DecodeSpace, $@)'
$(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'
endef
endif
################################################################################
# Recursive wildcard function. Walks down directories recursively and matches
# files with the search patterns. Patterns use standard file wildcards (* and
# ?).
#
# $1 - Directories to start search in
# $2 - Search patterns
rwildcard = \
$(strip \
$(foreach d, \
$(patsubst %/,%,$(sort $(dir $(wildcard $(addsuffix /*/*, $(strip $1)))))), \
$(call rwildcard,$d,$2) \
) \
$(call DoubleDollar, $(wildcard $(foreach p, $2, $(addsuffix /$(strip $p), $(strip $1))))) \
)
# Find non directories using recursive wildcard function. This function may
# be used directly when a small amount of directories is expected to be
# searched and caching is not expected to be of use.
#
# $1 - Directory to start search in
# $2 - Optional search patterns, defaults to '*'.
WildcardFindFiles = \
$(sort $(strip \
$(eval WildcardFindFiles_result := $(call rwildcard,$(patsubst %/,%,$1),$(if $(strip $2),$2,*))) \
$(filter-out $(patsubst %/,%,$(sort $(dir $(WildcardFindFiles_result)))), \
$(WildcardFindFiles_result) \
) \
))
# Find non directories using the find utility in the shell. Safe to call for
# non existing directories, or directories containing wildcards.
#
# Files containing space will get spaces replaced with ? because GNU Make
# cannot handle lists of files with space in them. By using ?, make will match
# the wildcard to space in many situations so we don't need to replace back
# to space on every use. While not a complete solution it does allow some uses
# of FindFiles to function with spaces in file names, including for
# SetupCopyFiles. Unfortunately this does not work for WildcardFindFiles so
# if files with spaces are anticipated, use ShellFindFiles directly.
#
# $1 - Directories to start search in.
# $2 - Optional search patterns, empty means find everything. Patterns use
# standard file wildcards (* and ?) and should not be quoted.
# $3 - Optional options to find.
ShellFindFiles = \
$(if $(wildcard $1), \
$(sort \
$(shell $(FIND) $3 $(patsubst %/,%,$(wildcard $1)) \( -type f -o -type l \) \
$(if $(strip $2), -a \( -name "$(firstword $2)" \
$(foreach p, $(filter-out $(firstword $2), $2), -o -name "$(p)") \)) \
| $(TR) ' ' '?' \
) \
) \
)
# Find non directories using the method most likely to work best for the
# current build host
#
# $1 - Directory to start search in
# $2 - Optional search patterns, defaults to '*'.
ifeq ($(OPENJDK_BUILD_OS)-$(RWILDCARD_WORKS), windows-true)
DirectFindFiles = $(WildcardFindFiles)
else
DirectFindFiles = $(ShellFindFiles)
endif
# Finds files using a cache that is populated by FillFindCache below. If any of
# the directories given have not been cached, DirectFindFiles is used for
# everything. Caching is especially useful in Cygwin, where file finds are very
# costly.
#
# $1 - Directories to start search in.
# $2 - Optional search patterns. If used, no caching is done.
CacheFindFiles_CACHED_DIRS :=
CacheFindFiles_CACHED_FILES :=
CacheFindFiles = \
$(if $2, \
$(call DirectFindFiles, $1, $2) \
, \
$(if $(filter-out $(addsuffix /%, $(CacheFindFiles_CACHED_DIRS)) \
$(CacheFindFiles_CACHED_DIRS), $1), \
$(call DirectFindFiles, $1) \
, \
$(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(CacheFindFiles_CACHED_FILES)) \
) \
)
# Explicitly adds files to the find cache used by CacheFindFiles.
#
# $1 - Directories to start search in
FillFindCache = \
$(eval CacheFindFiles_NEW_DIRS := $$(filter-out $$(addsuffix /%,\
$$(CacheFindFiles_CACHED_DIRS)) $$(CacheFindFiles_CACHED_DIRS), $1)) \
$(if $(CacheFindFiles_NEW_DIRS), \
$(eval CacheFindFiles_CACHED_DIRS += $$(patsubst %/,%,$$(CacheFindFiles_NEW_DIRS))) \
$(eval CacheFindFiles_CACHED_FILES := $$(sort $$(CacheFindFiles_CACHED_FILES) \
$$(call DirectFindFiles, $$(CacheFindFiles_NEW_DIRS)))) \
)
# Findfiles is the default macro that should be used to find files in the file
# system. This function does not always support files with spaces in the names.
# If files with spaces are anticipated, use ShellFindFiles directly.
#
# $1 - Directories to start search in.
# $2 - Optional search patterns, empty means find everything. Patterns use
# standard file wildcards (* and ?) and should not be quoted.
ifeq ($(DISABLE_CACHE_FIND), true)
FindFiles = $(DirectFindFiles)
else
FindFiles = $(CacheFindFiles)
endif
################################################################################
# FixPath
#
# On Windows, converts a path from cygwin/unix style (e.g. /bin/foo) into
# "mixed mode" (e.g. c:/cygwin/bin/foo). On other platforms, return the path
# unchanged.
# This also converts a colon-separated list of paths to a semicolon-separated
# list.
# This is normally not needed since we use the FIXPATH prefix for command lines,
# but might be needed in certain circumstances.
ifeq ($(call isTargetOs, windows), true)
FixPath = \
$(strip $(subst \,\\, $(shell $(FIXPATH_BASE) print $(patsubst $(FIXPATH), , $1))))
else
FixPath = \
$1
endif
################################################################################
# DependOnVariable
#
# This macro takes a variable name and puts the value in a file only if the
# value has changed since last. The name of the file is returned. This can be
# used to create rule dependencies on make variable values. The following
# example would get rebuilt if the value of SOME_VAR was changed:
#
# path/to/some-file: $(call DependOnVariable, SOME_VAR)
# echo $(SOME_VAR) > $@
#
# Note that leading and trailing white space in the value is ignored.
#
# Defines the sub directory structure to store variable value file in
DependOnVariableDirName = \
$(strip $(addsuffix $(if $(MODULE),/$(MODULE)), \
$(subst $(TOPDIR)/,, $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \
$(firstword $(MAKEFILE_LIST)), \
$(CURDIR)/$(firstword $(MAKEFILE_LIST))))))
# Defines the name of the file to store variable value in. Generates a name
# unless parameter 2 is given.
# Param 1 - Name of variable
# Param 2 - (optional) name of file to store value in
DependOnVariableFileName = \
$(strip $(if $(strip $2), $2, \
$(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps))
# Does the actual work with parameters stripped.
# If the file exists AND the contents is the same as the variable, do nothing
# else print a new file.
# Always returns the name of the file where the value was printed.
# Param 1 - Name of variable
# Param 2 - (optional) name of file to store value in
DependOnVariableHelper = \
$(strip \
$(eval $1_filename := $(call DependOnVariableFileName, $1, $2)) \
$(if $(wildcard $($1_filename)), $(eval include $($1_filename))) \
$(if $(call equals, $(strip $($1)), $(strip $($1_old))),,\
$(call MakeDir, $(dir $($1_filename))) \
$(if $(findstring $(LOG_LEVEL), trace), \
$(info NewVariable $1: >$(strip $($1))<) \
$(info OldVariable $1: >$(strip $($1_old))<)) \
$(call WriteFile, $1_old:=$(call DoubleDollar,$(call EscapeHash,$($1))), \
$($1_filename))) \
$($1_filename) \
)
# Main macro
# Param 1 - Name of variable
# Param 2 - (optional) name of file to store value in
DependOnVariable = \
$(call DependOnVariableHelper,$(strip $1),$(strip $2))
# LogCmdlines is only intended to be used by ExecuteWithLog
ifeq ($(LOG_CMDLINES), true)
LogCmdlines = $(info $(strip $1))
else
LogCmdlines =
endif
################################################################################
# ExecuteWithLog will run a command and log the output appropriately. This is
# meant to be used by commands that do "real" work, like a compilation.
# The output is stored in a specified log file, which is displayed at the end
# of the build in case of failure. The command line itself is stored in a file,
# and also logged to stdout if the LOG=cmdlines option has been given.
#
# NOTE: If the command redirects stdout, the caller needs to wrap it in a
# subshell (by adding parentheses around it), otherwise the redirect to the
# subshell tee process will create a race condition where the target file may
# not be fully written when the make recipe is done.
#
# Param 1 - The path to base the name of the log file / command line file on
# Param 2 - The command to run
ExecuteWithLog = \
$(call LogCmdlines, Exececuting: [$(strip $2)]) \
$(call MakeDir, $(dir $(strip $1))) \
$(call WriteFile, $2, $(strip $1).cmdline) \
( $(RM) $(strip $1).log && $(strip $2) > >($(TEE) -a $(strip $1).log) 2> >($(TEE) -a $(strip $1).log >&2) || \
( exitcode=$(DOLLAR)? && \
$(CP) $(strip $1).log $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).log && \
$(CP) $(strip $1).cmdline $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).cmdline && \
exit $(DOLLAR)exitcode ) )
################################################################################
# Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, common/MakeBase.gmk))
endif # _MAKEBASE_GMK
|