Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile: Filter out strings containing a character

Tags:

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.

like image 633
Steve Avatar asked May 26 '11 21:05

Steve


People also ask

What is $@ in Makefile?

$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.

What does Patsubst do in Makefile?

Finds whitespace-separated words in TEXT that match PATTERN and replaces them with REPLACEMENT. Here PATTERN may contain a % which acts as a wildcard, matching any number of any characters within a word.

What is Makefile_list?

MAKEFILE_LIST. Contains the name of each makefile that is parsed by make , in the order in which it was parsed. The name is appended just before make begins to parse the makefile. Thus, if the first thing a makefile does is examine the last word in this variable, it will be the name of the current makefile.


2 Answers

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) 
like image 124
Ise Wisteria Avatar answered Sep 24 '22 11:09

Ise Wisteria


I recently did something similar using two wildcards functions for excluding some files

.PHONY: test test:     echo $(filter-out $(wildcard *g*.c),$(wildcard *.c)) 
like image 35
bltavares Avatar answered Sep 25 '22 11:09

bltavares