< prev index next >

make/common/MakeBase.gmk

Print this page




 518   # attributes when they are present, failing on this is avoided.
 519   #
 520   # If copying a soft link to a directory, need to delete the target first to avoid
 521   # weird errors.
 522   define install-file
 523         $(MKDIR) -p '$(@D)'
 524         $(RM) '$@'
 525         $(CP) -fRP '$<' '$@'
 526         if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi
 527   endef
 528 else
 529   # Running mkdir and cp in the same shell speeds up copy intensive tasks in Cygwin
 530   # significantly.
 531   define install-file
 532         $(call MakeDir, $(@D))
 533         $(CP) -fP '$<' '$@'
 534   endef
 535 endif
 536 
 537 ################################################################################





























































 538 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
 539 uniq = \
 540     $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
 541 
 542 # Returns all whitespace-separated words in $2 where at least one of the
 543 # whitespace-separated words in $1 is a substring.
 544 containing = \
 545     $(strip \
 546         $(foreach v,$(strip $2),\
 547           $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v)))))
 548 
 549 # Returns all whitespace-separated words in $2 where none of the
 550 # whitespace-separated words in $1 is a substring.
 551 not-containing = \
 552     $(strip $(filter-out $(call containing,$1,$2),$2))
 553 
 554 # Return a list of all string elements that are duplicated in $1.
 555 dups = \
 556     $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
 557         $(words $(filter $v, $1))), $v)))




 518   # attributes when they are present, failing on this is avoided.
 519   #
 520   # If copying a soft link to a directory, need to delete the target first to avoid
 521   # weird errors.
 522   define install-file
 523         $(MKDIR) -p '$(@D)'
 524         $(RM) '$@'
 525         $(CP) -fRP '$<' '$@'
 526         if [ -n "`$(XATTR) -l '$@'`" ]; then $(XATTR) -c '$@'; fi
 527   endef
 528 else
 529   # Running mkdir and cp in the same shell speeds up copy intensive tasks in Cygwin
 530   # significantly.
 531   define install-file
 532         $(call MakeDir, $(@D))
 533         $(CP) -fP '$<' '$@'
 534   endef
 535 endif
 536 
 537 ################################################################################
 538 # Take two paths and return the path of the last common directory.
 539 # Ex: /foo/bar/baz, /foo/bar/banan -> /foo/bar
 540 #     foo/bar/baz, /foo/bar -> <empty>
 541 #
 542 # The x prefix is used to preserve the presence of the initial slash
 543 #
 544 # $1 - Path to compare
 545 # $2 - Other path to compare
 546 FindCommonPathPrefix = \
 547     $(patsubst x%,%,$(subst $(SPACE),/,$(strip \
 548         $(call FindCommonPathPrefixHelper, \
 549             $(subst /,$(SPACE),x$(strip $1)), $(subst /,$(SPACE),x$(strip $2))) \
 550     )))
 551 
 552 FindCommonPathPrefixHelper = \
 553     $(if $(call equals, $(firstword $1), $(firstword $2)), \
 554       $(firstword $1) \
 555       $(call FindCommonPathPrefixHelper, \
 556           $(wordlist 2, $(words $1), $1), $(wordlist 2, $(words $2), $2) \
 557       ) \
 558     )
 559 
 560 # Convert a partial path into as many directory levels of ../, removing
 561 # leading and following /.
 562 # Ex: foo/bar/baz/ -> ../../..
 563 #     foo/bar -> ../..
 564 #     /foo -> ..
 565 DirToDotDot = \
 566     $(subst $(SPACE),/,$(foreach d, $(subst /,$(SPACE),$1),..))
 567 
 568 # Computes the relative path from a directory to a file
 569 # $1 - File to compute the relative path to
 570 # $2 - Directory to compute the relative path from
 571 RelativePath = \
 572     $(eval $1_prefix := $(call FindCommonPathPrefix, $1, $2)) \
 573     $(eval $1_dotdots := $(call DirToDotDot, $(patsubst $($(strip $1)_prefix)/%, %, $2))) \
 574     $(eval $1_suffix := $(patsubst $($(strip $1)_prefix)/%, %, $1)) \
 575     $($(strip $1)_dotdots)/$($(strip $1)_suffix)
 576 
 577 ################################################################################
 578 # link-file-* works similarly to install file but creates a symlink instead on
 579 # platforms that support it. There are two versions, either creating a relative
 580 # or an absolute link.
 581 ifeq ($(OPENJDK_BUILD_OS), windows)
 582   link-file-absolute = $(install-file)
 583   link-file-relative = $(install-file)
 584 else
 585   define link-file-relative
 586         $(call MakeDir, $(@D))
 587         $(RM) $@
 588         $(LN) -s $(call RelativePath, $<, $(@D)) $@
 589   endef
 590 
 591   define link-file-absolute
 592         $(call MakeDir, $(@D))
 593         $(RM) $@
 594         $(LN) -s $< $@
 595   endef
 596 endif
 597 
 598 ################################################################################
 599 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
 600 uniq = \
 601     $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
 602 
 603 # Returns all whitespace-separated words in $2 where at least one of the
 604 # whitespace-separated words in $1 is a substring.
 605 containing = \
 606     $(strip \
 607         $(foreach v,$(strip $2),\
 608           $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v)))))
 609 
 610 # Returns all whitespace-separated words in $2 where none of the
 611 # whitespace-separated words in $1 is a substring.
 612 not-containing = \
 613     $(strip $(filter-out $(call containing,$1,$2),$2))
 614 
 615 # Return a list of all string elements that are duplicated in $1.
 616 dups = \
 617     $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
 618         $(words $(filter $v, $1))), $v)))


< prev index next >