Skip to content
Advertisement

make: how to append text to beginning and end of list?

In the makefile I’m writing, I am using the shell command find to build a list of source files to compile. In particular, I’m using the line:

SRCS := $(shell find $(SOURCES) '*.[cs]')

Now this works just fine. However, I would like to add support for excluding files that have a pattern that appears in a list called EXCLUDE. I’d like to use the prune option of find.

Something like this works if there is only one item in EXCLUDE

SRCS := $(shell find $(SOURCES) -name ${EXCLUDE} -prune -o -name '*.[cs]' -print)

To make this work with multiple excludes, I need to repeat the -name exclude -prune -o for each element in the exclude list.

TLDR: I need a way to transform the list EXCLUDE which may for example be a b c into -name a -prune -o name b -prune -o name c -prune -o. How can I achieve this?

Thanks.

Advertisement

Answer

$(patsubst %,-name % -prune -o,$(EXCLUDE)) should work.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement