make/common/MakeBase.gmk
changeset 28713 c1ea17b60964
parent 28602 51c0dcf51b67
parent 28600 09dd1740f176
child 28607 380f123263d8
equal deleted inserted replaced
28605:68bf16ffbd7a 28713:c1ea17b60964
   390 
   390 
   391   $2
   391   $2
   392 endef
   392 endef
   393 
   393 
   394 # Make directory without forking mkdir if not needed
   394 # Make directory without forking mkdir if not needed
   395 define MakeDir
   395 MakeDir = \
   396   ifneq ($$(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),$$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9))
   396     $(strip $(if $(subst $(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),,$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)),\
   397     $$(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9)
   397       $(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9)))
   398   endif
       
   399 endef
       
   400 
   398 
   401 ifeq ($(OPENJDK_TARGET_OS),solaris)
   399 ifeq ($(OPENJDK_TARGET_OS),solaris)
   402   # On Solaris, if the target is a symlink and exists, cp won't overwrite.
   400   # On Solaris, if the target is a symlink and exists, cp won't overwrite.
   403   # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
   401   # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
   404   # name of the target file differs from the source file, rename after copy.
   402   # name of the target file differs from the source file, rename after copy.
   444 not-containing = $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v)))
   442 not-containing = $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v)))
   445 
   443 
   446 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
   444 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
   447 uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
   445 uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
   448 
   446 
       
   447 # String equals
       
   448 equals = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
       
   449 
   449 ifneq ($(DISABLE_CACHE_FIND), true)
   450 ifneq ($(DISABLE_CACHE_FIND), true)
   450   ################################################################################
   451   ################################################################################
   451   # In Cygwin, finds are very costly, both because of expensive forks and because
   452   # In Cygwin, finds are very costly, both because of expensive forks and because
   452   # of bad file system caching. Find is used extensively in $(shell) commands to
   453   # of bad file system caching. Find is used extensively in $(shell) commands to
   453   # find source files. This makes rerunning make with no or few changes rather
   454   # find source files. This makes rerunning make with no or few changes rather
   541       $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO))))
   542       $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO))))
   542 
   543 
   543 endef
   544 endef
   544 
   545 
   545 ################################################################################
   546 ################################################################################
       
   547 # ShellQuote
       
   548 #
       
   549 # Quotes a string with single quotes and replaces single quotes with '\'' so 
       
   550 # that the contents survives being given to the shell.
       
   551 
       
   552 ShellQuote = \
       
   553     $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE)
       
   554 
       
   555 ################################################################################
       
   556 # Write to and read from file
       
   557 
       
   558 # Param 1 - File to read
       
   559 ReadFile = \
       
   560     $(shell $(CAT) $1)
       
   561 
       
   562 # Param 1 - Text to write
       
   563 # Param 2 - File to write to
       
   564 # Use printf to get consistent behavior on all platforms.
       
   565 WriteFile = \
       
   566     $(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2)
       
   567 
       
   568 ################################################################################
       
   569 # DependOnVariable
       
   570 #
       
   571 # This macro takes a variable name and puts the value in a file only if the 
       
   572 # value has changed since last. The name of the file is returned. This can be 
       
   573 # used to create rule dependencies on make variable values. The following
       
   574 # example would get rebuilt if the value of SOME_VAR was changed:
       
   575 #
       
   576 # path/to/some-file: $(call DependOnVariable, SOME_VAR)
       
   577 #         echo $(SOME_VAR) > $@
       
   578 #
       
   579 # Note that leading and trailing white space in the value is ignored.
       
   580 #
       
   581 
       
   582 # Defines the sub directory structure to store variable value file in
       
   583 DependOnVariableDirName = \
       
   584     $(strip $(subst $(SRC_ROOT)/,,\
       
   585         $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \
       
   586           $(firstword $(MAKEFILE_LIST)), \
       
   587           $(CURDIR)/$(firstword $(MAKEFILE_LIST)))))
       
   588 
       
   589 # Defines the name of the file to store variable value in. Generates a name
       
   590 # unless parameter 2 is given.
       
   591 # Param 1 - Name of variable
       
   592 # Param 2 - (optional) name of file to store value in
       
   593 DependOnVariableFileName = \
       
   594     $(strip $(if $(strip $2), $2, \
       
   595       $(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps))
       
   596 
       
   597 # Does the actual work with parameters stripped.
       
   598 # If the file exists AND the contents is the same as the variable, do nothing
       
   599 # else print a new file.
       
   600 # Always returns the name of the file where the value was printed.
       
   601 # Param 1 - Name of variable
       
   602 # Param 2 - (optional) name of file to store value in
       
   603 DependOnVariableHelper = \
       
   604     $(strip $(if $(and $(wildcard $(call DependOnVariableFileName, $1, $2)),\
       
   605         $(call equals, $(strip $($1)), \
       
   606             $(call ReadFile, $(call DependOnVariableFileName, $1, $2)))),,\
       
   607       $(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \
       
   608       $(if $(findstring $(LOG_LEVEL), trace), \
       
   609           $(info Variable $1: $(strip $($1))) \
       
   610           $(info File: $(call ReadFile, $(call DependOnVariableFileName, $1, $2)))) \
       
   611       $(call WriteFile, $($1), $(call DependOnVariableFileName, $1, $2))) \
       
   612     $(call DependOnVariableFileName, $1, $2))
       
   613 
       
   614 # Main macro
       
   615 # Param 1 - Name of variable
       
   616 # Param 2 - (optional) name of file to store value in
       
   617 DependOnVariable = \
       
   618     $(call DependOnVariableHelper,$(strip $1),$(strip $2))
       
   619 
       
   620 ################################################################################
   546 
   621 
   547 # Hook to include the corresponding custom file, if present.
   622 # Hook to include the corresponding custom file, if present.
   548 $(eval $(call IncludeCustomExtension, , common/MakeBase.gmk))
   623 $(eval $(call IncludeCustomExtension, , common/MakeBase.gmk))
   549 
   624 
   550 endif # _MAKEBASE_GMK
   625 endif # _MAKEBASE_GMK