483 ) 484 485 ################################################################################ 486 # Assign a variable only if it is empty 487 # Param 1 - Variable to assign 488 # Param 2 - Value to assign 489 SetIfEmpty = \ 490 $(if $($(strip $1)),,$(eval $(strip $1) := $2)) 491 492 ################################################################################ 493 # All install-file and related macros automatically call DecodeSpace when needed. 494 495 ifeq ($(OPENJDK_TARGET_OS),solaris) 496 # On Solaris, if the target is a symlink and exists, cp won't overwrite. 497 # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the 498 # name of the target file differs from the source file, rename after copy. 499 # If the source and target parent directories are the same, recursive copy doesn't work 500 # so we fall back on regular copy, which isn't preserving symlinks. 501 define install-file 502 $(call MakeDir, $(@D)) 503 $(RM) "$(call DecodeSpace, $@)" 504 if [ "$(call DecodeSpace, $(dir $@))" != \ 505 "$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))" ]; then \ 506 $(CP) -f -r -P "$(call DecodeSpace, $<)" "$(call DecodeSpace, $(@D))"; \ 507 if [ "$(call DecodeSpace, $(@F))" != \ 508 "$(call DecodeSpace, $(notdir $(call EncodeSpace, $(<))))" ]; then \ 509 $(MV) "$(call DecodeSpace, $(@D)/$(<F))" "$(call DecodeSpace, $@)"; \ 510 fi; \ 511 else \ 512 if [ -L "$(call DecodeSpace, $<)" ]; then \ 513 $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \ 514 exit 1; \ 515 fi; \ 516 $(CP) -f "$(call DecodeSpace, $<)" "$(call DecodeSpace, $@)"; \ 517 fi 518 endef 519 else ifeq ($(OPENJDK_TARGET_OS),macosx) 520 # On mac, extended attributes sometimes creep into the source files, which may later 521 # cause the creation of ._* files which confuses testing. Clear these with xattr if 522 # set. Some files get their write permissions removed after being copied to the 523 # output dir. When these are copied again to images, xattr would fail. By only clearing 524 # attributes when they are present, failing on this is avoided. 525 # 526 # If copying a soft link to a directory, need to delete the target first to avoid 527 # weird errors. 528 define install-file 529 $(call MakeDir, $(@D)) 530 $(RM) "$(call DecodeSpace, $@)" 531 $(CP) -fRP "$(call DecodeSpace, $<)" "$(call DecodeSpace, $@)" 532 if [ -n "`$(XATTR) -l "$(call DecodeSpace, $@)"`" ]; then $(XATTR) -c "$(call DecodeSpace, $@)"; fi 533 endef 534 else 535 define install-file 536 $(call MakeDir, $(@D)) 537 $(CP) -fP "$(call DecodeSpace, $<)" "$(call DecodeSpace, $@)" 538 endef 539 endif 540 541 # Variant of install file that does not preserve symlinks 542 define install-file-nolink 543 $(call MakeDir, $(@D)) 544 $(CP) -f "$(call DecodeSpace, $<)" "$(call DecodeSpace, $@)" 545 endef 546 547 ################################################################################ 548 # Take two paths and return the path of the last common directory. 549 # Ex: /foo/bar/baz, /foo/bar/banan -> /foo/bar 550 # foo/bar/baz, /foo/bar -> <empty> 551 # 552 # The x prefix is used to preserve the presence of the initial slash 553 # 554 # $1 - Path to compare 555 # $2 - Other path to compare 556 FindCommonPathPrefix = \ 557 $(patsubst x%,%,$(subst $(SPACE),/,$(strip \ 558 $(call FindCommonPathPrefixHelper, \ 559 $(subst /,$(SPACE),x$(strip $1)), $(subst /,$(SPACE),x$(strip $2))) \ 560 ))) 561 562 FindCommonPathPrefixHelper = \ 563 $(if $(call equals, $(firstword $1), $(firstword $2)), \ 564 $(firstword $1) \ 574 # /foo -> .. 575 DirToDotDot = \ 576 $(subst $(SPACE),/,$(foreach d, $(subst /,$(SPACE),$1),..)) 577 578 # Computes the relative path from a directory to a file 579 # $1 - File to compute the relative path to 580 # $2 - Directory to compute the relative path from 581 RelativePath = \ 582 $(eval $1_prefix := $(call FindCommonPathPrefix, $1, $2)) \ 583 $(eval $1_dotdots := $(call DirToDotDot, $(patsubst $($(strip $1)_prefix)/%, %, $2))) \ 584 $(eval $1_suffix := $(patsubst $($(strip $1)_prefix)/%, %, $1)) \ 585 $($(strip $1)_dotdots)/$($(strip $1)_suffix) 586 587 ################################################################################ 588 # link-file-* works similarly to install-file but creates a symlink instead. 589 # There are two versions, either creating a relative or an absolute link. Be 590 # careful when using this on Windows since the symlink created is only valid in 591 # the unix emulation environment. 592 define link-file-relative 593 $(call MakeDir, $(@D)) 594 $(RM) "$(call DecodeSpace, $@)" 595 $(LN) -s "$(call DecodeSpace, $(call RelativePath, $<, $(@D)))" "$(call DecodeSpace, $@)" 596 endef 597 598 define link-file-absolute 599 $(call MakeDir, $(@D)) 600 $(RM) "$(call DecodeSpace, $@)" 601 $(LN) -s "$(call DecodeSpace, $<)" "$(call DecodeSpace, $@)" 602 endef 603 604 ################################################################################ 605 # Filter out duplicate sub strings while preserving order. Keeps the first occurance. 606 uniq = \ 607 $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) 608 609 # Returns all whitespace-separated words in $2 where at least one of the 610 # whitespace-separated words in $1 is a substring. 611 containing = \ 612 $(strip \ 613 $(foreach v,$(strip $2),\ 614 $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v))))) 615 616 # Returns all whitespace-separated words in $2 where none of the 617 # whitespace-separated words in $1 is a substring. 618 not-containing = \ 619 $(strip $(filter-out $(call containing,$1,$2),$2)) 620 621 # Return a list of all string elements that are duplicated in $1. | 483 ) 484 485 ################################################################################ 486 # Assign a variable only if it is empty 487 # Param 1 - Variable to assign 488 # Param 2 - Value to assign 489 SetIfEmpty = \ 490 $(if $($(strip $1)),,$(eval $(strip $1) := $2)) 491 492 ################################################################################ 493 # All install-file and related macros automatically call DecodeSpace when needed. 494 495 ifeq ($(OPENJDK_TARGET_OS),solaris) 496 # On Solaris, if the target is a symlink and exists, cp won't overwrite. 497 # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the 498 # name of the target file differs from the source file, rename after copy. 499 # If the source and target parent directories are the same, recursive copy doesn't work 500 # so we fall back on regular copy, which isn't preserving symlinks. 501 define install-file 502 $(call MakeDir, $(@D)) 503 $(RM) '$(call DecodeSpace, $@)' 504 if [ '$(call DecodeSpace, $(dir $@))' != \ 505 '$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))' ]; then \ 506 $(CP) -f -r -P '$(call DecodeSpace, $<)' '$(call DecodeSpace, $(@D))'; \ 507 if [ '$(call DecodeSpace, $(@F))' != \ 508 '$(call DecodeSpace, $(notdir $(call EncodeSpace, $(<))))' ]; then \ 509 $(MV) '$(call DecodeSpace, $(@D)/$(<F))' '$(call DecodeSpace, $@)'; \ 510 fi; \ 511 else \ 512 if [ -L '$(call DecodeSpace, $<)' ]; then \ 513 $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \ 514 exit 1; \ 515 fi; \ 516 $(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \ 517 fi 518 endef 519 else ifeq ($(OPENJDK_TARGET_OS),macosx) 520 # On mac, extended attributes sometimes creep into the source files, which may later 521 # cause the creation of ._* files which confuses testing. Clear these with xattr if 522 # set. Some files get their write permissions removed after being copied to the 523 # output dir. When these are copied again to images, xattr would fail. By only clearing 524 # attributes when they are present, failing on this is avoided. 525 # 526 # If copying a soft link to a directory, need to delete the target first to avoid 527 # weird errors. 528 define install-file 529 $(call MakeDir, $(@D)) 530 $(RM) '$(call DecodeSpace, $@)' 531 $(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' 532 if [ -n "`$(XATTR) -l '$(call DecodeSpace, $@)'`" ]; then $(XATTR) -c '$(call DecodeSpace, $@)'; fi 533 endef 534 else 535 define install-file 536 $(call MakeDir, $(@D)) 537 $(CP) -fP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' 538 endef 539 endif 540 541 # Variant of install file that does not preserve symlinks 542 define install-file-nolink 543 $(call MakeDir, $(@D)) 544 $(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' 545 endef 546 547 ################################################################################ 548 # Take two paths and return the path of the last common directory. 549 # Ex: /foo/bar/baz, /foo/bar/banan -> /foo/bar 550 # foo/bar/baz, /foo/bar -> <empty> 551 # 552 # The x prefix is used to preserve the presence of the initial slash 553 # 554 # $1 - Path to compare 555 # $2 - Other path to compare 556 FindCommonPathPrefix = \ 557 $(patsubst x%,%,$(subst $(SPACE),/,$(strip \ 558 $(call FindCommonPathPrefixHelper, \ 559 $(subst /,$(SPACE),x$(strip $1)), $(subst /,$(SPACE),x$(strip $2))) \ 560 ))) 561 562 FindCommonPathPrefixHelper = \ 563 $(if $(call equals, $(firstword $1), $(firstword $2)), \ 564 $(firstword $1) \ 574 # /foo -> .. 575 DirToDotDot = \ 576 $(subst $(SPACE),/,$(foreach d, $(subst /,$(SPACE),$1),..)) 577 578 # Computes the relative path from a directory to a file 579 # $1 - File to compute the relative path to 580 # $2 - Directory to compute the relative path from 581 RelativePath = \ 582 $(eval $1_prefix := $(call FindCommonPathPrefix, $1, $2)) \ 583 $(eval $1_dotdots := $(call DirToDotDot, $(patsubst $($(strip $1)_prefix)/%, %, $2))) \ 584 $(eval $1_suffix := $(patsubst $($(strip $1)_prefix)/%, %, $1)) \ 585 $($(strip $1)_dotdots)/$($(strip $1)_suffix) 586 587 ################################################################################ 588 # link-file-* works similarly to install-file but creates a symlink instead. 589 # There are two versions, either creating a relative or an absolute link. Be 590 # careful when using this on Windows since the symlink created is only valid in 591 # the unix emulation environment. 592 define link-file-relative 593 $(call MakeDir, $(@D)) 594 $(RM) '$(call DecodeSpace, $@)' 595 $(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)' 596 endef 597 598 define link-file-absolute 599 $(call MakeDir, $(@D)) 600 $(RM) '$(call DecodeSpace, $@)' 601 $(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' 602 endef 603 604 ################################################################################ 605 # Filter out duplicate sub strings while preserving order. Keeps the first occurance. 606 uniq = \ 607 $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) 608 609 # Returns all whitespace-separated words in $2 where at least one of the 610 # whitespace-separated words in $1 is a substring. 611 containing = \ 612 $(strip \ 613 $(foreach v,$(strip $2),\ 614 $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v))))) 615 616 # Returns all whitespace-separated words in $2 where none of the 617 # whitespace-separated words in $1 is a substring. 618 not-containing = \ 619 $(strip $(filter-out $(call containing,$1,$2),$2)) 620 621 # Return a list of all string elements that are duplicated in $1. |