comparison make/common/MakeBase.gmk @ 1642:382d23edebb6

8136383: Improve make utilities containing and not-containing Reviewed-by: ihse
author erikj
date Tue, 15 Sep 2015 18:00:21 +0200
parents 8b56a0ce50f0
children 216f63a10515 c800f2919a1f
comparison
equal deleted inserted replaced
30:0f64bc2b1a8e 31:ac2bde25d8e6
565 $(MKDIR) -p '$(@D)' && $(CP) -fP '$<' '$@' 565 $(MKDIR) -p '$(@D)' && $(CP) -fP '$<' '$@'
566 endef 566 endef
567 endif 567 endif
568 568
569 ################################################################################ 569 ################################################################################
570 # Convenience functions for working around make's limitations with $(filter ).
571 containing = \
572 $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),$v)))
573 not-containing = \
574 $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v)))
575
576 # Filter out duplicate sub strings while preserving order. Keeps the first occurance. 570 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
577 uniq = \ 571 uniq = \
578 $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) 572 $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
573
574 # Returns all whitespace-separated words in $2 where at least one of the
575 # whitespace-separated words in $1 is a substring.
576 containing = \
577 $(strip \
578 $(foreach v,$(strip $2),\
579 $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v)))))
580
581 # Returns all whitespace-separated words in $2 where none of the
582 # whitespace-separated words in $1 is a substring.
583 not-containing = \
584 $(strip $(filter-out $(call containing,$1,$2),$2))
579 585
580 # Return a list of all string elements that are duplicated in $1. 586 # Return a list of all string elements that are duplicated in $1.
581 dups = \ 587 dups = \
582 $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \ 588 $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
583 $(words $(filter $v, $1))), $v))) 589 $(words $(filter $v, $1))), $v)))