I have a directory with a lot of subdirectories which are containing source-files. Therefore I am looking in every subdirectoy for.c-files: cSources = $(shell dir /s /b *.c)
However there are subdirectories with source-files I do not want to compile. If I have a variable dirToExclude = dirName
how can I remove every string in cSources
that contains 'dirName'?
I know that there is the findstring
-function. But I can't figure out how to use findstring
on every string in the array. I am looking for some way to get a nested loop like (pseudo code):
foreach (var in cSources)
if (var.contains(dirToExclude))
cSources -= var
endif
If you know dirToExclude
is always at the beginning of the string you can just write:
cSources := $(filter-out $(dirToExclude)%,$(cSources))
If you want to remove any filename where the string appears anywhere, you can use:
cSources := $(foreach S,$(cSources),$(if $(findstring $(dirToExclude),$(S)),,$(S)))
See https://www.gnu.org/software/make/manual/html_node/Functions.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.