Makefile: how to apply a filter equivalent to multiple wildcards

I am writing a Makefile and I am stuck in restricting the filter function. Indeed, a filter accepts only one pattern.

What I would like to do is: I have a list of files, some correspond to regexp blabla, and some do not. But for this I need 2 wildcards, so I cannot use the filter function.

I would like to split my initial list into 2 lists, one of which contains the whole element containing the blabla string (filter equivalent), and the other is inappropriate (filter equivalent).

thank you for your help.

+5
source share
3 answers

You can do this without any external commands. Define two macros

containing = $(foreach v,$2,$(if $(findstring $1,$v),$v))
not-containing = $(foreach v,$2,$(if $(findstring $1,$v),,$v))

LIST := a_old_tt x_old_da a_new_da q_ty_we
LIST_OLD := $(call containing,old,$(LIST))
LIST_NOT_OLD := $(call not-containing,old,$(LIST))
+7

- . filter filter-out "" . :

NOT_OLD = $(shell echo $(LIST) | sed 's/[^ ]*old[^ ]* *//g')
OLD = $(filter-out $(NOT_OLD), $(LIST))
+1

. , bash, makefile:

LIST := a_old_tt x_old_da a_new_da q_ty_we
LIST_NOT_OLD := $(shell l=($(LIST)); echo $${l[@]//*old*})
LIST_OLD := $(filter-out $(LIST_NOT_OLD),$(LIST))

bash . $ $ .

0

All Articles