make/common/MakeBase.gmk
changeset 29312 f3f859137ce6
parent 29304 81a723f8d33c
child 29662 78c47f0002c3
equal deleted inserted replaced
29311:bc685175f836 29312:f3f859137ce6
   372 endef
   372 endef
   373 
   373 
   374 # Make sure logging is setup for everyone that includes MakeBase.gmk.
   374 # Make sure logging is setup for everyone that includes MakeBase.gmk.
   375 $(eval $(call SetupLogging))
   375 $(eval $(call SetupLogging))
   376 
   376 
   377 # This is to be called by all SetupFoo macros
   377 ################################################################################
   378 define LogSetupMacroEntry
   378 # Creates a sequence of increasing numbers (inclusive).
   379   $(if $(30),$(error Internal makefile error: Too many arguments to LogSetupMacroEntry, please update MakeBase.gmk))
   379 # Param 1 - starting number
   380   $(if $(findstring $(LOG_LEVEL),debug trace), $(info $1 $(foreach i,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,$(if $(strip $($i)),$(NEWLINE) $(strip [$i] $($i))))))
   380 # Param 2 - ending number
   381 endef
   381 sequence = \
   382 
   382     $(wordlist $1, $2, $(strip \
   383 # Support macro for all SetupFoo macros.
   383         $(eval SEQUENCE_COUNT :=) \
   384 define EvalDebugWrapper
   384         $(call _sequence-do,$(strip $2))))
   385   $(if $(DEBUG_$1),
   385 
   386     $(info -------- <<< Begin expansion of $1)
   386 _sequence-do = \
   387     $(info $2)
   387     $(if $(word $1, $(SEQUENCE_COUNT)),, \
   388     $(info -------- >>> End expansion of $1)
   388       $(eval SEQUENCE_COUNT += .) \
       
   389       $(words $(SEQUENCE_COUNT)) \
       
   390       $(call _sequence-do,$1))
       
   391 
       
   392 ################################################################################
       
   393 
       
   394 MAX_PARAMS := 30
       
   395 PARAM_SEQUENCE := $(call sequence, 2, $(MAX_PARAMS))
       
   396 
       
   397 # Template for creating a macro taking named parameters. To use it, assign the
       
   398 # template to a variable with the name you want for your macro, using '='
       
   399 # assignment. Then define a macro body with the suffix "Body". The Body macro
       
   400 # should take 1 parameter which should be a unique string for that invocation
       
   401 # of the macro.
       
   402 # Ex:
       
   403 # SetupFoo = $(NamedParamsMacroTemplate)
       
   404 # define SetupFooBody
       
   405 #   # do something
       
   406 #   # access parameters as $$($1_BAR)
       
   407 # endef
       
   408 # Call it like this
       
   409 # $(eval $(call SetupFoo, BUILD_SOMETHING, \
       
   410 #     BAR := some parameter value, \
       
   411 # ))
       
   412 define NamedParamsMacroTemplate
       
   413   $(if $($(MAX_PARAMS)),$(error Internal makefile error: \
       
   414       Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk))
       
   415   # Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix
       
   416   $(foreach i,$(PARAM_SEQUENCE), $(if $(strip $($i)),\
       
   417     $(strip $1)_$(strip $($i)))$(NEWLINE))
       
   418   # Debug print all named parameter names and values
       
   419   $(if $(findstring $(LOG_LEVEL),debug trace), \
       
   420     $(info $0 $(strip $1) $(foreach i,$(PARAM_SEQUENCE), \
       
   421       $(if $(strip $($i)),$(NEWLINE) $(strip [$i] $(if $(filter $(LOG_LEVEL), trace), \
       
   422         $($i), $(wordlist 1, 20, $($(i))) $(if $(word 21, $($(i))), ...)))))))
       
   423 
       
   424   $(if $(DEBUG_$(strip $1)),
       
   425     $(info -------- <<< Begin expansion of $(strip $1)) \
       
   426     $(info $(call $(0)Body,$(strip $1))) \
       
   427     $(info -------- >>> End expansion of $(strip $1)) \
   389   )
   428   )
   390 
   429 
   391   $2
   430   $(call $(0)Body,$(strip $1))
   392 endef
   431 endef
   393 
   432 
       
   433 ################################################################################
   394 # Make directory without forking mkdir if not needed
   434 # Make directory without forking mkdir if not needed
   395 MakeDir = \
   435 MakeDir = \
   396     $(strip $(if $(subst $(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),,$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)),\
   436     $(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)))
   437       $(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9)))
       
   438 
       
   439 ################################################################################
   398 
   440 
   399 ifeq ($(OPENJDK_TARGET_OS),solaris)
   441 ifeq ($(OPENJDK_TARGET_OS),solaris)
   400   # On Solaris, if the target is a symlink and exists, cp won't overwrite.
   442   # On Solaris, if the target is a symlink and exists, cp won't overwrite.
   401   # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
   443   # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
   402   # name of the target file differs from the source file, rename after copy.
   444   # name of the target file differs from the source file, rename after copy.
   435   define install-file
   477   define install-file
   436 	$(MKDIR) -p '$(@D)' && $(CP) -fP '$<' '$@'
   478 	$(MKDIR) -p '$(@D)' && $(CP) -fP '$<' '$@'
   437   endef
   479   endef
   438 endif
   480 endif
   439 
   481 
       
   482 ################################################################################
   440 # Convenience functions for working around make's limitations with $(filter ).
   483 # Convenience functions for working around make's limitations with $(filter ).
   441 containing = \
   484 containing = \
   442     $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),$v)))
   485     $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),$v)))
   443 not-containing = \
   486 not-containing = \
   444     $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v)))
   487     $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v)))
   455 # String equals
   498 # String equals
   456 equals = \
   499 equals = \
   457     $(and $(findstring $(strip $1),$(strip $2)),\
   500     $(and $(findstring $(strip $1),$(strip $2)),\
   458         $(findstring $(strip $2),$(strip $1)))
   501         $(findstring $(strip $2),$(strip $1)))
   459 
   502 
       
   503 ################################################################################
       
   504 
   460 ifneq ($(DISABLE_CACHE_FIND), true)
   505 ifneq ($(DISABLE_CACHE_FIND), true)
   461   ################################################################################
       
   462   # In Cygwin, finds are very costly, both because of expensive forks and because
   506   # In Cygwin, finds are very costly, both because of expensive forks and because
   463   # of bad file system caching. Find is used extensively in $(shell) commands to
   507   # of bad file system caching. Find is used extensively in $(shell) commands to
   464   # find source files. This makes rerunning make with no or few changes rather
   508   # find source files. This makes rerunning make with no or few changes rather
   465   # expensive. To speed this up, these two macros are used to cache the results
   509   # expensive. To speed this up, these two macros are used to cache the results
   466   # of simple find commands for reuse.
   510   # of simple find commands for reuse.
   542 #   FILES   : List of files to copy with absolute paths, or path relative to SRC.
   586 #   FILES   : List of files to copy with absolute paths, or path relative to SRC.
   543 #             Must be in SRC.
   587 #             Must be in SRC.
   544 #   FLATTEN : Set to flatten the directory structure in the DEST dir.
   588 #   FLATTEN : Set to flatten the directory structure in the DEST dir.
   545 #   MACRO   : Optionally override the default macro used for making the copy.
   589 #   MACRO   : Optionally override the default macro used for making the copy.
   546 #             Default is 'install-file'
   590 #             Default is 'install-file'
   547 
   591 SetupCopyFiles = $(NamedParamsMacroTemplate)
   548 define SetupCopyFiles
   592 define SetupCopyFilesBody
   549   $(if $(16),$(error Internal makefile error: Too many arguments to SetupCopyFiles, please update MakeBase.gmk))
       
   550   $(call EvalDebugWrapper,$(strip $1),$(call SetupCopyFilesInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
       
   551 endef
       
   552 
       
   553 define SetupCopyFilesInner
       
   554   $(foreach i,2 3 4 5 6, $(if $(strip $($i)),$1_$(strip $($i)))$(NEWLINE))
       
   555   $(call LogSetupMacroEntry,SetupCopyFiles($1),$2,$3,$4,$5,$6)
       
   556   $(if $(7),$(error Internal makefile error: Too many arguments to SetupCopyFiles, please update MakeBase.gmk))
       
   557 
   593 
   558   ifeq ($$($1_MACRO), )
   594   ifeq ($$($1_MACRO), )
   559     $1_MACRO := install-file
   595     $1_MACRO := install-file
   560   endif
   596   endif
   561 
   597