Makefile: Filter out strings containing a character

Steve picture Steve · May 26, 2011 · Viewed 23.5k times · Source

I'm trying to filter out strings that contain a particular character, but it doesn't work. I guess make does not support multiple % patterns?

.PHONY: test
test:
    echo $(filter-out %g%, seven eight nine ten)

Gives:

$ make test
echo seven eight nine ten
seven eight nine ten

It doesn't filter out "eight"? Actually what I want to do is filter out from a list of filenames those containing "$". (In a Java context.)

Any hope, or do I have to use $(shell)?

Thanks.

Answer

Ise Wisteria picture Ise Wisteria · May 27, 2011

Does the following function meet the purpose?

FILTER_OUT = $(foreach v,$(2),$(if $(findstring $(1),$(v)),,$(v)))
$(call FILTER_OUT,g, seven eight nine ten)