# # Copyright (c) 2011, 2016, 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 # In GNU Make 4.0 and higher, there is a file function for writing to files. ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION)))) HAS_FILE_FUNCTION := true endif ############################## # Functions ############################## ### Debug functions # Prints the name and value of a variable PrintVar = \ $(info $(strip $1) >$($(strip $1))<) ### Functions for timers # Store the build times in this directory. BUILDTIMESDIR=$(OUTPUT_ROOT)/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 ################################################################################ # This macro translates $ into \$ to protect the $ from expansion in the shell. # To make this macro resilient against already escaped strings, first remove # any present escapes before escaping so that no double escapes are added. EscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1))) ################################################################################ # This macro translates $ into $$ to protect the string from make itself. DoubleDollar = $(subst $$,$$$$,$(strip $1)) ################################################################################ # ListPathsSafely can be used to print command parameters to a file. This is # typically done if the command line lenght risk being too long for the # OS/shell. In later make versions, the file function can be used for this # purpose. For earlier versions, a more complex implementation is provided. # # The function ListPathsSafely can be called either directly or, more commonly # from a recipe line. If called from a recipe, it will be executed in the # evaluation phase of that recipe, which means that it will write to the file # before any other line in the recipe has been run. ifeq ($(HAS_FILE_FUNCTION), true) # Param 1 - Name of variable containing paths/arguments to output # Param 2 - File to print to # Param 3 - Set to true to append to file instead of overwriting define ListPathsSafely $$(call MakeDir, $$(dir $$(strip $2))) $$(file $$(if $$(filter true, $$(strip $3)),>>,>) \ $$(strip $2),$$(subst $$(SPACE),$$(NEWLINE),$$(strip $$($$(strip $1))))) endef else # HAS_FILE_FUNCTION = false $(eval compress_paths = \ $(strip $(shell $(CAT) $(SRC_ROOT)/make/common/support/ListPathsSafely-pre-compress.incl))) compress_paths += \ $(subst $(SRC_ROOT),X97, \ $(subst $(OUTPUT_ROOT),X98, \ $(subst X,X00, \ $(subst $(SPACE),\n,$(strip $1))))) $(eval compress_paths += \ $(strip $(shell $(CAT) $(SRC_ROOT)/make/common/support/ListPathsSafely-post-compress.incl))) decompress_paths=$(SED) -f $(SRC_ROOT)/make/common/support/ListPathsSafely-uncompress.sed \ -e 's|X99|\\n|g' \ -e 's|X98|$(OUTPUT_ROOT)|g' -e 's|X97|$(SRC_ROOT)|g' \ -e 's|X00|X|g' ListPathsSafely_IfPrintf = \ $(if $(word $3,$($(strip $1))), \ $(shell $(PRINTF) -- "$(strip $(call EscapeDollar, \ $(call compress_paths, $(wordlist $3,$4,$($(strip $1))))))\n" \ | $(decompress_paths) >> $2)) # Param 1 - Name of variable containing paths/arguments to output # Param 2 - File to print to # Param 3 - Set to true to append to file instead of overwriting define ListPathsSafely ifneq (,$$(word 30001,$$($$(strip $1)))) $$(error Cannot list safely more than 30000 paths. $1 has $$(words $$($$(strip $1))) paths!) endif $$(call MakeDir, $$(dir $2)) ifneq ($$(strip $3), true) $$(shell $(RM) $$(strip $2)) endif $$(call ListPathsSafely_IfPrintf,$1,$2,1,250) $$(call ListPathsSafely_IfPrintf,$1,$2,251,500) $$(call ListPathsSafely_IfPrintf,$1,$2,501,750) $$(call ListPathsSafely_IfPrintf,$1,$2,751,1000) $$(call ListPathsSafely_IfPrintf,$1,$2,1001,1250) $$(call ListPathsSafely_IfPrintf,$1,$2,1251,1500) $$(call ListPathsSafely_IfPrintf,$1,$2,1501,1750) $$(call ListPathsSafely_IfPrintf,$1,$2,1751,2000) $$(call ListPathsSafely_IfPrintf,$1,$2,2001,2250) $$(call ListPathsSafely_IfPrintf,$1,$2,2251,2500) $$(call ListPathsSafely_IfPrintf,$1,$2,2501,2750) $$(call ListPathsSafely_IfPrintf,$1,$2,2751,3000) $$(call ListPathsSafely_IfPrintf,$1,$2,3001,3250) $$(call ListPathsSafely_IfPrintf,$1,$2,3251,3500) $$(call ListPathsSafely_IfPrintf,$1,$2,3501,3750) $$(call ListPathsSafely_IfPrintf,$1,$2,3751,4000) $$(call ListPathsSafely_IfPrintf,$1,$2,4001,4250) $$(call ListPathsSafely_IfPrintf,$1,$2,4251,4500) $$(call ListPathsSafely_IfPrintf,$1,$2,4501,4750) $$(call ListPathsSafely_IfPrintf,$1,$2,4751,5000) $$(call ListPathsSafely_IfPrintf,$1,$2,5001,5250) $$(call ListPathsSafely_IfPrintf,$1,$2,5251,5500) $$(call ListPathsSafely_IfPrintf,$1,$2,5501,5750) $$(call ListPathsSafely_IfPrintf,$1,$2,5751,6000) $$(call ListPathsSafely_IfPrintf,$1,$2,6001,6250) $$(call ListPathsSafely_IfPrintf,$1,$2,6251,6500) $$(call ListPathsSafely_IfPrintf,$1,$2,6501,6750) $$(call ListPathsSafely_IfPrintf,$1,$2,6751,7000) $$(call ListPathsSafely_IfPrintf,$1,$2,7001,7250) $$(call ListPathsSafely_IfPrintf,$1,$2,7251,7500) $$(call ListPathsSafely_IfPrintf,$1,$2,7501,7750) $$(call ListPathsSafely_IfPrintf,$1,$2,7751,8000) $$(call ListPathsSafely_IfPrintf,$1,$2,8001,8250) $$(call ListPathsSafely_IfPrintf,$1,$2,8251,8500) $$(call ListPathsSafely_IfPrintf,$1,$2,8501,8750) $$(call ListPathsSafely_IfPrintf,$1,$2,8751,9000) $$(call ListPathsSafely_IfPrintf,$1,$2,9001,9250) $$(call ListPathsSafely_IfPrintf,$1,$2,9251,9500) $$(call ListPathsSafely_IfPrintf,$1,$2,9501,9750) $$(call ListPathsSafely_IfPrintf,$1,$2,9751,10000) $$(call ListPathsSafely_IfPrintf,$1,$2,10001,10250) $$(call ListPathsSafely_IfPrintf,$1,$2,10251,10500) $$(call ListPathsSafely_IfPrintf,$1,$2,10501,10750) $$(call ListPathsSafely_IfPrintf,$1,$2,10751,11000) $$(call ListPathsSafely_IfPrintf,$1,$2,11001,11250) $$(call ListPathsSafely_IfPrintf,$1,$2,11251,11500) $$(call ListPathsSafely_IfPrintf,$1,$2,11501,11750) $$(call ListPathsSafely_IfPrintf,$1,$2,11751,12000) $$(call ListPathsSafely_IfPrintf,$1,$2,12001,12250) $$(call ListPathsSafely_IfPrintf,$1,$2,12251,12500) $$(call ListPathsSafely_IfPrintf,$1,$2,12501,12750) $$(call ListPathsSafely_IfPrintf,$1,$2,12751,13000) $$(call ListPathsSafely_IfPrintf,$1,$2,13001,13250) $$(call ListPathsSafely_IfPrintf,$1,$2,13251,13500) $$(call ListPathsSafely_IfPrintf,$1,$2,13501,13750) $$(call ListPathsSafely_IfPrintf,$1,$2,13751,14000) $$(call ListPathsSafely_IfPrintf,$1,$2,14001,14250) $$(call ListPathsSafely_IfPrintf,$1,$2,14251,14500) $$(call ListPathsSafely_IfPrintf,$1,$2,14501,14750) $$(call ListPathsSafely_IfPrintf,$1,$2,14751,15000) $$(call ListPathsSafely_IfPrintf,$1,$2,15001,15250) $$(call ListPathsSafely_IfPrintf,$1,$2,15251,15500) $$(call ListPathsSafely_IfPrintf,$1,$2,15501,15750) $$(call ListPathsSafely_IfPrintf,$1,$2,15751,16000) $$(call ListPathsSafely_IfPrintf,$1,$2,16001,16250) $$(call ListPathsSafely_IfPrintf,$1,$2,16251,16500) $$(call ListPathsSafely_IfPrintf,$1,$2,16501,16750) $$(call ListPathsSafely_IfPrintf,$1,$2,16751,17000) $$(call ListPathsSafely_IfPrintf,$1,$2,17001,17250) $$(call ListPathsSafely_IfPrintf,$1,$2,17251,17500) $$(call ListPathsSafely_IfPrintf,$1,$2,17501,17750) $$(call ListPathsSafely_IfPrintf,$1,$2,17751,18000) $$(call ListPathsSafely_IfPrintf,$1,$2,18001,18250) $$(call ListPathsSafely_IfPrintf,$1,$2,18251,18500) $$(call ListPathsSafely_IfPrintf,$1,$2,18501,18750) $$(call ListPathsSafely_IfPrintf,$1,$2,18751,19000) $$(call ListPathsSafely_IfPrintf,$1,$2,19001,19250) $$(call ListPathsSafely_IfPrintf,$1,$2,19251,19500) $$(call ListPathsSafely_IfPrintf,$1,$2,19501,19750) $$(call ListPathsSafely_IfPrintf,$1,$2,19751,20000) $$(call ListPathsSafely_IfPrintf,$1,$2,20001,20250) $$(call ListPathsSafely_IfPrintf,$1,$2,20251,20500) $$(call ListPathsSafely_IfPrintf,$1,$2,20501,20750) $$(call ListPathsSafely_IfPrintf,$1,$2,20751,21000) $$(call ListPathsSafely_IfPrintf,$1,$2,21001,21250) $$(call ListPathsSafely_IfPrintf,$1,$2,21251,21500) $$(call ListPathsSafely_IfPrintf,$1,$2,21501,21750) $$(call ListPathsSafely_IfPrintf,$1,$2,21751,22000) $$(call ListPathsSafely_IfPrintf,$1,$2,22001,22250) $$(call ListPathsSafely_IfPrintf,$1,$2,22251,22500) $$(call ListPathsSafely_IfPrintf,$1,$2,22501,22750) $$(call ListPathsSafely_IfPrintf,$1,$2,22751,23000) $$(call ListPathsSafely_IfPrintf,$1,$2,23001,23250) $$(call ListPathsSafely_IfPrintf,$1,$2,23251,23500) $$(call ListPathsSafely_IfPrintf,$1,$2,23501,23750) $$(call ListPathsSafely_IfPrintf,$1,$2,23751,24000) $$(call ListPathsSafely_IfPrintf,$1,$2,24001,24250) $$(call ListPathsSafely_IfPrintf,$1,$2,24251,24500) $$(call ListPathsSafely_IfPrintf,$1,$2,24501,24750) $$(call ListPathsSafely_IfPrintf,$1,$2,24751,25000) $$(call ListPathsSafely_IfPrintf,$1,$2,25001,25250) $$(call ListPathsSafely_IfPrintf,$1,$2,25251,25500) $$(call ListPathsSafely_IfPrintf,$1,$2,25501,25750) $$(call ListPathsSafely_IfPrintf,$1,$2,25751,26000) $$(call ListPathsSafely_IfPrintf,$1,$2,26001,26250) $$(call ListPathsSafely_IfPrintf,$1,$2,26251,26500) $$(call ListPathsSafely_IfPrintf,$1,$2,26501,26750) $$(call ListPathsSafely_IfPrintf,$1,$2,26751,27000) $$(call ListPathsSafely_IfPrintf,$1,$2,27001,27250) $$(call ListPathsSafely_IfPrintf,$1,$2,27251,27500) $$(call ListPathsSafely_IfPrintf,$1,$2,27501,27750) $$(call ListPathsSafely_IfPrintf,$1,$2,27751,28000) $$(call ListPathsSafely_IfPrintf,$1,$2,28001,28250) $$(call ListPathsSafely_IfPrintf,$1,$2,28251,28500) $$(call ListPathsSafely_IfPrintf,$1,$2,28501,28750) $$(call ListPathsSafely_IfPrintf,$1,$2,28751,29000) $$(call ListPathsSafely_IfPrintf,$1,$2,29001,29250) $$(call ListPathsSafely_IfPrintf,$1,$2,29251,29500) $$(call ListPathsSafely_IfPrintf,$1,$2,29501,29750) $$(call ListPathsSafely_IfPrintf,$1,$2,29751,30000) endef endif # HAS_FILE_FUNCTION ################################################################################ # The source tips can come from the Mercurial repository, or in the files # $(HGTIP_FILENAME) which contains the tip but is also positioned in the same # directory as the original .hg directory. The hgtip files are created in # CreateHgtipFiles.gmk. HGTIP_FILENAME := .hgtip FindAllReposAbs = \ $(strip $(sort $(dir $(filter-out $(SRC_ROOT)/build/%, $(wildcard \ $(addprefix $(SRC_ROOT)/, \ .hg */.hg */*/.hg */*/.hg */*/*/.hg \ .hgtip */.hgtip */*/.hgtip */*/.hgtip */*/*/.hgtip \ ) \ ))))) FindAllReposRel = \ $(strip $(subst $(SRC_ROOT)/,.,$(patsubst $(SRC_ROOT)/%/, %, $(FindAllReposAbs)))) # Emit the repo:tip pairs to $@, but only if they changed since last time define GetSourceTips $(CD) $(SRC_ROOT) ; \ for i in $(FindAllReposRel) IGNORE ; do \ if [ "$${i}" = "IGNORE" ] ; then \ continue; \ elif [ -d $${i}/.hg -a "$(HG)" != "" ] ; then \ $(PRINTF) " %s:%s" \ "$${i}" `$(HG) tip --repository $${i} --template '{node|short}\n'` ; \ elif [ -f $${i}/$(HGTIP_FILENAME) ] ; then \ $(PRINTF) " %s:%s" \ "$${i}" `$(CAT) $${i}/$(HGTIP_FILENAME)` ; \ fi; \ done > $@.tmp $(PRINTF) "\n" >> $@.tmp if [ ! -f $@ ] || [ "`$(CAT) $@`" != "`$(CAT) $@.tmp`" ]; then \ $(MV) $@.tmp $@ ; \ else \ $(RM) $@.tmp ; \ fi endef ################################################################################ define SetupLogging ifeq ($$(LOG_LEVEL), trace) # 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 (from ) ( newer) # but with a limit of 20 on , to avoid cluttering logs too much # (and causing a crash on Cygwin). # Default shell seems to always be /bin/sh. Must override with bash to get this to work on Solaris. # Only use time if it's GNU time which supports format and output file. WRAPPER_SHELL := $$(BASH) $$(SRC_ROOT)/common/bin/shell-tracer.sh $$(if $$(findstring yes,$$(IS_GNU_TIME)),$$(TIME),-) $$(OUTPUT_ROOT)/build-trace-time.log $$(SHELL) SHELL = $$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(WRAPPER_SHELL) 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)) ################################################################################ # Creates a sequence of increasing numbers (inclusive). # Param 1 - starting number # Param 2 - ending number sequence = \ $(wordlist $1, $2, $(strip \ $(eval SEQUENCE_COUNT :=) \ $(call _sequence-do,$(strip $2)))) _sequence-do = \ $(if $(word $1, $(SEQUENCE_COUNT)),, \ $(eval SEQUENCE_COUNT += .) \ $(words $(SEQUENCE_COUNT)) \ $(call _sequence-do,$1)) ################################################################################ MAX_PARAMS := 35 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 $($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 # 1: List of directories to create MakeDir = \ $(strip \ $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, $(if $(wildcard $d), , $d)))) \ $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \ ) ################################################################################ # Assign a variable only if it is empty # Param 1 - Variable to assign # Param 2 - Value to assign SetIfEmpty = \ $(if $($(strip $1)),,$(eval $(strip $1) := $2)) ################################################################################ ifeq ($(OPENJDK_TARGET_OS),solaris) # 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 $(MKDIR) -p '$(@D)' $(RM) '$@' if [ "$(@D)" != "$($2,$(strip $1)) else # Use printf to get consistent behavior on all platforms. WriteFile = \ $(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2) 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 $(SRC_ROOT)/,, $(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 -include $(call DependOnVariableFileName, $1, $2)) \ $(if $(call equals, $(strip $($1)), $(strip $($1_old))),,\ $(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \ $(if $(findstring $(LOG_LEVEL), trace), \ $(info NewVariable $1: >$(strip $($1))<) \ $(info OldVariable $1: >$(strip $($1_old))<)) \ $(call WriteFile, $1_old:=$(call DoubleDollar,$($1)), \ $(call DependOnVariableFileName, $1, $2))) \ $(call DependOnVariableFileName, $1, $2) \ ) # 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 WriteFile, $2, $(strip $1).cmdline) \ ( $(strip $2) > >($(TEE) $(strip $1).log) 2> >($(TEE) $(strip $1).log >&2) || \ ( exitcode=$(DOLLAR)? && \ $(CP) $(strip $1).log $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(BUILD_OUTPUT)/%,%,$(strip $1))).log && \ exit $(DOLLAR)exitcode ) ) ################################################################################ # Find lib dir for module # Param 1 - module name ifeq ($(OPENJDK_TARGET_OS_TYPE), unix) FindLibDirForModule = \ $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1)$(OPENJDK_TARGET_CPU_LIBDIR) else FindLibDirForModule = \ $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1) endif ################################################################################ # Return a string suitable for use after a -classpath or --module-path option. It # will be correct and safe to use on all platforms. Arguments are given as space # separate classpath entries. Safe for multiple nested calls. # param 1 : A space separated list of classpath entries # The surrounding strip is needed to keep additional whitespace out PathList = \ "$(subst $(SPACE),$(PATH_SEP),$(strip $(subst $(DQUOTE),,$1)))" ################################################################################ # Check if a specified hotspot variant is being built, or at least one of a # list of variants. Will return 'true' or 'false'. # $1 - the variant to test for check-jvm-variant = \ $(strip \ $(if $(filter-out $(VALID_JVM_VARIANTS), $1), \ $(error Internal error: Invalid variant tested: $1)) \ $(if $(filter $1, $(JVM_VARIANTS)), true, false)) ################################################################################ # Converts a space separated list to a comma separated list. # # Replacing double-comma with a single comma is to workaround the issue with # some version of make on windows that doesn't substitute spaces with one comma # properly. CommaList = \ $(strip \ $(subst $(COMMA)$(COMMA),$(COMMA),$(subst $(SPACE),$(COMMA),$(strip $1))) \ ) ################################################################################ # Hook to include the corresponding custom file, if present. $(eval $(call IncludeCustomExtension, , common/MakeBase.gmk)) endif # _MAKEBASE_GMK