< prev index next >

make/common/Utils.gmk

Print this page




  53 # This macro translates $ into $$ to protect the string from make itself.
  54 DoubleDollar = $(subst $$,$$$$,$(strip $1))
  55 
  56 ################################################################################
  57 # Creates a sequence of increasing numbers (inclusive).
  58 # Param 1 - starting number
  59 # Param 2 - ending number
  60 sequence = \
  61     $(wordlist $1, $2, $(strip \
  62         $(eval SEQUENCE_COUNT :=) \
  63         $(call _sequence-do,$(strip $2))))
  64 
  65 _sequence-do = \
  66     $(if $(word $1, $(SEQUENCE_COUNT)),, \
  67       $(eval SEQUENCE_COUNT += .) \
  68       $(words $(SEQUENCE_COUNT)) \
  69       $(call _sequence-do,$1))
  70 
  71 ################################################################################
  72 # Replace question marks with space in string. This macro needs to be called on
  73 # files from FindFiles in case any of them contains space in their file name,
  74 # since FindFiles replaces space with ?.
  75 # Param 1 - String to replace in
  76 DecodeSpace = \
  77     $(subst ?,$(SPACE),$(strip $1))
  78 
  79 EncodeSpace = \
  80     $(subst $(SPACE),?,$(strip $1))
  81 
  82 ################################################################################
  83 # Assign a variable only if it is empty
  84 # Param 1 - Variable to assign
  85 # Param 2 - Value to assign
  86 SetIfEmpty = \
  87     $(if $($(strip $1)),,$(eval $(strip $1) := $2))
  88 
  89 ################################################################################
  90 # Take two paths and return the path of the last common directory.
  91 # Ex: /foo/bar/baz, /foo/bar/banan -> /foo/bar
  92 #     foo/bar/baz, /foo/bar -> <empty>
  93 #
  94 # The x prefix is used to preserve the presence of the initial slash


 105     $(if $(call equals, $(firstword $1), $(firstword $2)), \
 106       $(firstword $1) \
 107       $(call FindCommonPathPrefixHelper, \
 108           $(wordlist 2, $(words $1), $1), $(wordlist 2, $(words $2), $2) \
 109       ) \
 110     )
 111 
 112 # Convert a partial path into as many directory levels of ../, removing
 113 # leading and following /.
 114 # Ex: foo/bar/baz/ -> ../../..
 115 #     foo/bar -> ../..
 116 #     /foo -> ..
 117 DirToDotDot = \
 118     $(subst $(SPACE),/,$(foreach d, $(subst /,$(SPACE),$1),..))
 119 
 120 # Computes the relative path from a directory to a file
 121 # $1 - File to compute the relative path to
 122 # $2 - Directory to compute the relative path from
 123 RelativePath = \
 124     $(eval $1_prefix := $(call FindCommonPathPrefix, $1, $2)) \
 125     $(eval $1_dotdots := $(call DirToDotDot, $(patsubst $($(strip $1)_prefix)%, %, $2))) \
 126     $(eval $1_dotdots := $(if $($(strip $1)_dotdots),$($(strip $1)_dotdots),.)) \
 127     $(eval $1_suffix := $(patsubst $($(strip $1)_prefix)/%, %, $1)) \
 128     $($(strip $1)_dotdots)/$($(strip $1)_suffix)
 129 
 130 ################################################################################
 131 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
 132 uniq = \
 133     $(strip $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))))
 134 
 135 # Returns all whitespace-separated words in $2 where at least one of the
 136 # whitespace-separated words in $1 is a substring.
 137 containing = \
 138     $(strip \
 139         $(foreach v,$(strip $2),\
 140           $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v)))))
 141 
 142 # Returns all whitespace-separated words in $2 where none of the
 143 # whitespace-separated words in $1 is a substring.
 144 not-containing = \
 145     $(strip $(filter-out $(call containing,$1,$2),$2))
 146 




  53 # This macro translates $ into $$ to protect the string from make itself.
  54 DoubleDollar = $(subst $$,$$$$,$(strip $1))
  55 
  56 ################################################################################
  57 # Creates a sequence of increasing numbers (inclusive).
  58 # Param 1 - starting number
  59 # Param 2 - ending number
  60 sequence = \
  61     $(wordlist $1, $2, $(strip \
  62         $(eval SEQUENCE_COUNT :=) \
  63         $(call _sequence-do,$(strip $2))))
  64 
  65 _sequence-do = \
  66     $(if $(word $1, $(SEQUENCE_COUNT)),, \
  67       $(eval SEQUENCE_COUNT += .) \
  68       $(words $(SEQUENCE_COUNT)) \
  69       $(call _sequence-do,$1))
  70 
  71 ################################################################################
  72 # Replace question marks with space in string. This macro needs to be called on
  73 # files from CacheFind in case any of them contains space in their file name,
  74 # since CacheFind replaces space with ?.
  75 # Param 1 - String to replace in
  76 DecodeSpace = \
  77     $(subst ?,$(SPACE),$(strip $1))
  78 
  79 EncodeSpace = \
  80     $(subst $(SPACE),?,$(strip $1))
  81 
  82 ################################################################################
  83 # Assign a variable only if it is empty
  84 # Param 1 - Variable to assign
  85 # Param 2 - Value to assign
  86 SetIfEmpty = \
  87     $(if $($(strip $1)),,$(eval $(strip $1) := $2))
  88 
  89 ################################################################################
  90 # Take two paths and return the path of the last common directory.
  91 # Ex: /foo/bar/baz, /foo/bar/banan -> /foo/bar
  92 #     foo/bar/baz, /foo/bar -> <empty>
  93 #
  94 # The x prefix is used to preserve the presence of the initial slash


 105     $(if $(call equals, $(firstword $1), $(firstword $2)), \
 106       $(firstword $1) \
 107       $(call FindCommonPathPrefixHelper, \
 108           $(wordlist 2, $(words $1), $1), $(wordlist 2, $(words $2), $2) \
 109       ) \
 110     )
 111 
 112 # Convert a partial path into as many directory levels of ../, removing
 113 # leading and following /.
 114 # Ex: foo/bar/baz/ -> ../../..
 115 #     foo/bar -> ../..
 116 #     /foo -> ..
 117 DirToDotDot = \
 118     $(subst $(SPACE),/,$(foreach d, $(subst /,$(SPACE),$1),..))
 119 
 120 # Computes the relative path from a directory to a file
 121 # $1 - File to compute the relative path to
 122 # $2 - Directory to compute the relative path from
 123 RelativePath = \
 124     $(eval $1_prefix := $(call FindCommonPathPrefix, $1, $2)) \
 125     $(eval $1_dotdots := $(call DirToDotDot, $(patsubst $($(strip $1)_prefix)/%, %, $2))) \

 126     $(eval $1_suffix := $(patsubst $($(strip $1)_prefix)/%, %, $1)) \
 127     $($(strip $1)_dotdots)/$($(strip $1)_suffix)
 128 
 129 ################################################################################
 130 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
 131 uniq = \
 132     $(strip $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))))
 133 
 134 # Returns all whitespace-separated words in $2 where at least one of the
 135 # whitespace-separated words in $1 is a substring.
 136 containing = \
 137     $(strip \
 138         $(foreach v,$(strip $2),\
 139           $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v)))))
 140 
 141 # Returns all whitespace-separated words in $2 where none of the
 142 # whitespace-separated words in $1 is a substring.
 143 not-containing = \
 144     $(strip $(filter-out $(call containing,$1,$2),$2))
 145 


< prev index next >