< prev index next >

make/common/MakeBase.gmk

Print this page




 357   ifneq ($$(findstring $$(LOG_LEVEL),info debug trace),)
 358     LOG_INFO=
 359   else
 360     LOG_INFO=> /dev/null
 361   endif
 362   ifneq ($$(findstring $$(LOG_LEVEL),debug trace),)
 363     LOG_DEBUG=
 364   else
 365     LOG_DEBUG=> /dev/null
 366   endif
 367   ifneq ($$(findstring $$(LOG_LEVEL),trace),)
 368     LOG_TRACE=
 369   else
 370     LOG_TRACE=> /dev/null
 371   endif
 372 endef
 373 
 374 # Make sure logging is setup for everyone that includes MakeBase.gmk.
 375 $(eval $(call SetupLogging))
 376 
 377 # This is to be called by all SetupFoo macros
 378 define LogSetupMacroEntry
 379   $(if $(30),$(error Internal makefile error: Too many arguments to LogSetupMacroEntry, please update MakeBase.gmk))
 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))))))
 381 endef











 382 
 383 # Support macro for all SetupFoo macros.
 384 define EvalDebugWrapper
 385   $(if $(DEBUG_$1),
 386     $(info -------- <<< Begin expansion of $1)
 387     $(info $2)
 388     $(info -------- >>> End expansion of $1)




























 389   )
 390 
 391   $2
 392 endef
 393 

 394 # Make directory without forking mkdir if not needed
 395 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)),\
 397       $(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9)))
 398 


 399 ifeq ($(OPENJDK_TARGET_OS),solaris)
 400   # 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
 402   # name of the target file differs from the source file, rename after copy.
 403   # If the source and target parent directories are the same, recursive copy doesn't work
 404   # so we fall back on regular copy, which isn't preserving symlinks.
 405   define install-file
 406         $(MKDIR) -p '$(@D)'
 407         $(RM) '$@'
 408         if [ "$(@D)" != "$(<D)" ]; then \
 409           $(CP) -f -r -P '$<' '$(@D)'; \
 410           if [ "$(@F)" != "$(<F)" ]; then \
 411             $(MV) '$(@D)/$(<F)' '$@'; \
 412           fi; \
 413         else \
 414           if [ -L '$<' ]; then \
 415             $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \
 416             exit 1; \
 417           fi; \
 418           $(CP) -f '$<' '$@'; \


 420   endef
 421 else ifeq ($(OPENJDK_TARGET_OS),macosx)
 422   # On mac, extended attributes sometimes creep into the source files, which may later
 423   # cause the creation of ._* files which confuses testing. Clear these with xattr if
 424   # set. Some files get their write permissions removed after being copied to the
 425   # output dir. When these are copied again to images, xattr would fail. By only clearing
 426   # attributes when they are present, failing on this is avoided.
 427   define install-file
 428         $(MKDIR) -p '$(@D)'
 429         $(CP) -fRP '$<' '$@'
 430         if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi
 431   endef
 432 else
 433   # Running mkdir and cp in the same shell speeds up copy intensive tasks in Cygwin
 434   # significantly.
 435   define install-file
 436         $(MKDIR) -p '$(@D)' && $(CP) -fP '$<' '$@'
 437   endef
 438 endif
 439 

 440 # Convenience functions for working around make's limitations with $(filter ).
 441 containing = \
 442     $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),$v)))
 443 not-containing = \
 444     $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v)))
 445 
 446 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
 447 uniq = \
 448     $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
 449 
 450 # Return a list of all string elements that are duplicated in $1.
 451 dups = \
 452     $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
 453         $(words $(filter $v, $1))), $v)))
 454 
 455 # String equals
 456 equals = \
 457     $(and $(findstring $(strip $1),$(strip $2)),\
 458         $(findstring $(strip $2),$(strip $1)))
 459 


 460 ifneq ($(DISABLE_CACHE_FIND), true)
 461   ################################################################################
 462   # 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
 464   # 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
 466   # of simple find commands for reuse.
 467   #
 468   # Runs a find and stores both the directories where it was run and the results.
 469   # This macro can be called multiple times to add to the cache. Only finds files
 470   # with no filters.
 471   #
 472   # Needs to be called with $(eval )
 473   #
 474   # Even if the performance benifit is negligible on other platforms, keep the
 475   # functionality active unless explicitly disabled to exercise it more.
 476   #
 477   # Initialize FIND_CACHE_DIRS with := to make it a non recursively-expanded variable
 478   FIND_CACHE_DIRS :=
 479   # Param 1 - Dirs to find in
 480   # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
 481   define FillCacheFind


 527         $(ECHO) $(LOG_INFO) Copying $$(patsubst $(OUTPUT_ROOT)/%,%,$$@)
 528         $$($$(strip $4))
 529 
 530   $3 += $2
 531 endef
 532 
 533 # Setup make rules for copying files, with an option to do more complex
 534 # processing instead of copying.
 535 #
 536 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 537 # and the targets generated are listed in a variable by that name.
 538 #
 539 # Remaining parameters are named arguments. These include:
 540 #   SRC     : Source root dir (defaults to dir of first file)
 541 #   DEST    : Dest root dir
 542 #   FILES   : List of files to copy with absolute paths, or path relative to SRC.
 543 #             Must be in SRC.
 544 #   FLATTEN : Set to flatten the directory structure in the DEST dir.
 545 #   MACRO   : Optionally override the default macro used for making the copy.
 546 #             Default is 'install-file'
 547 
 548 define SetupCopyFiles
 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 
 558   ifeq ($$($1_MACRO), )
 559     $1_MACRO := install-file
 560   endif
 561 
 562   # Default SRC to the dir of the first file.
 563   ifeq ($$($1_SRC), )
 564     $1_SRC := $$(dir $$(firstword $$($1_FILES)))
 565   endif
 566 
 567   # Remove any trailing slash from SRC
 568   $1_SRC := $$(patsubst %/,%,$$($1_SRC))
 569 
 570   $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
 571       $$(eval $$(call AddFileToCopy, $$($1_SRC)/$$f, \
 572       $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO))))
 573 
 574 endef
 575 
 576 ################################################################################




 357   ifneq ($$(findstring $$(LOG_LEVEL),info debug trace),)
 358     LOG_INFO=
 359   else
 360     LOG_INFO=> /dev/null
 361   endif
 362   ifneq ($$(findstring $$(LOG_LEVEL),debug trace),)
 363     LOG_DEBUG=
 364   else
 365     LOG_DEBUG=> /dev/null
 366   endif
 367   ifneq ($$(findstring $$(LOG_LEVEL),trace),)
 368     LOG_TRACE=
 369   else
 370     LOG_TRACE=> /dev/null
 371   endif
 372 endef
 373 
 374 # Make sure logging is setup for everyone that includes MakeBase.gmk.
 375 $(eval $(call SetupLogging))
 376 
 377 ################################################################################
 378 # Creates a sequence of increasing numbers (inclusive).
 379 # Param 1 - starting number
 380 # Param 2 - ending number
 381 sequence = \
 382     $(wordlist $1, $2, $(strip \
 383         $(eval SEQUENCE_COUNT :=) \
 384         $(call _sequence-do,$(strip $2))))
 385 
 386 _sequence-do = \
 387     $(if $(word $1, $(SEQUENCE_COUNT)),, \
 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 macor
 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)) \
 428   )
 429 
 430   $(call $(0)Body,$(strip $1))
 431 endef
 432 
 433 ################################################################################
 434 # Make directory without forking mkdir if not needed
 435 MakeDir = \
 436     $(strip $(if $(subst $(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),,$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)),\
 437       $(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9)))
 438 
 439 ################################################################################
 440 
 441 ifeq ($(OPENJDK_TARGET_OS),solaris)
 442   # On Solaris, if the target is a symlink and exists, cp won't overwrite.
 443   # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
 444   # name of the target file differs from the source file, rename after copy.
 445   # If the source and target parent directories are the same, recursive copy doesn't work
 446   # so we fall back on regular copy, which isn't preserving symlinks.
 447   define install-file
 448         $(MKDIR) -p '$(@D)'
 449         $(RM) '$@'
 450         if [ "$(@D)" != "$(<D)" ]; then \
 451           $(CP) -f -r -P '$<' '$(@D)'; \
 452           if [ "$(@F)" != "$(<F)" ]; then \
 453             $(MV) '$(@D)/$(<F)' '$@'; \
 454           fi; \
 455         else \
 456           if [ -L '$<' ]; then \
 457             $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \
 458             exit 1; \
 459           fi; \
 460           $(CP) -f '$<' '$@'; \


 462   endef
 463 else ifeq ($(OPENJDK_TARGET_OS),macosx)
 464   # On mac, extended attributes sometimes creep into the source files, which may later
 465   # cause the creation of ._* files which confuses testing. Clear these with xattr if
 466   # set. Some files get their write permissions removed after being copied to the
 467   # output dir. When these are copied again to images, xattr would fail. By only clearing
 468   # attributes when they are present, failing on this is avoided.
 469   define install-file
 470         $(MKDIR) -p '$(@D)'
 471         $(CP) -fRP '$<' '$@'
 472         if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi
 473   endef
 474 else
 475   # Running mkdir and cp in the same shell speeds up copy intensive tasks in Cygwin
 476   # significantly.
 477   define install-file
 478         $(MKDIR) -p '$(@D)' && $(CP) -fP '$<' '$@'
 479   endef
 480 endif
 481 
 482 ################################################################################
 483 # Convenience functions for working around make's limitations with $(filter ).
 484 containing = \
 485     $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),$v)))
 486 not-containing = \
 487     $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v)))
 488 
 489 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
 490 uniq = \
 491     $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
 492 
 493 # Return a list of all string elements that are duplicated in $1.
 494 dups = \
 495     $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
 496         $(words $(filter $v, $1))), $v)))
 497 
 498 # String equals
 499 equals = \
 500     $(and $(findstring $(strip $1),$(strip $2)),\
 501         $(findstring $(strip $2),$(strip $1)))
 502 
 503 ################################################################################
 504 
 505 ifneq ($(DISABLE_CACHE_FIND), true)

 506   # In Cygwin, finds are very costly, both because of expensive forks and because
 507   # of bad file system caching. Find is used extensively in $(shell) commands to
 508   # find source files. This makes rerunning make with no or few changes rather
 509   # expensive. To speed this up, these two macros are used to cache the results
 510   # of simple find commands for reuse.
 511   #
 512   # Runs a find and stores both the directories where it was run and the results.
 513   # This macro can be called multiple times to add to the cache. Only finds files
 514   # with no filters.
 515   #
 516   # Needs to be called with $(eval )
 517   #
 518   # Even if the performance benifit is negligible on other platforms, keep the
 519   # functionality active unless explicitly disabled to exercise it more.
 520   #
 521   # Initialize FIND_CACHE_DIRS with := to make it a non recursively-expanded variable
 522   FIND_CACHE_DIRS :=
 523   # Param 1 - Dirs to find in
 524   # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
 525   define FillCacheFind


 571         $(ECHO) $(LOG_INFO) Copying $$(patsubst $(OUTPUT_ROOT)/%,%,$$@)
 572         $$($$(strip $4))
 573 
 574   $3 += $2
 575 endef
 576 
 577 # Setup make rules for copying files, with an option to do more complex
 578 # processing instead of copying.
 579 #
 580 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 581 # and the targets generated are listed in a variable by that name.
 582 #
 583 # Remaining parameters are named arguments. These include:
 584 #   SRC     : Source root dir (defaults to dir of first file)
 585 #   DEST    : Dest root dir
 586 #   FILES   : List of files to copy with absolute paths, or path relative to SRC.
 587 #             Must be in SRC.
 588 #   FLATTEN : Set to flatten the directory structure in the DEST dir.
 589 #   MACRO   : Optionally override the default macro used for making the copy.
 590 #             Default is 'install-file'
 591 SetupCopyFiles = $(NamedParamsMacroTemplate)
 592 define SetupCopyFilesBody








 593 
 594   ifeq ($$($1_MACRO), )
 595     $1_MACRO := install-file
 596   endif
 597 
 598   # Default SRC to the dir of the first file.
 599   ifeq ($$($1_SRC), )
 600     $1_SRC := $$(dir $$(firstword $$($1_FILES)))
 601   endif
 602 
 603   # Remove any trailing slash from SRC
 604   $1_SRC := $$(patsubst %/,%,$$($1_SRC))
 605 
 606   $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
 607       $$(eval $$(call AddFileToCopy, $$($1_SRC)/$$f, \
 608       $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO))))
 609 
 610 endef
 611 
 612 ################################################################################


< prev index next >