Makefile excluding files
Solution 1
If the elements in NEWSRC
necessarily start with
../sources/filesystem/SomePath
, how about adding suffix to EXCLUDES
as
the following?
$(filter-out $(addsuffix /%,$(EXCLUDES)),$(NEWSRC))
Solution 2
If you're allowed to modify the ..._exclude.txt
files, you could use patterns.
foo.exclude.txt:
badFile.cc anotherBadFile.cc \
../sources/filesystem/SomePath/% \
yetAnotherBadFile.cc
Just slap a '%' on the end of every directory you want to exclude.
If you're not allowed to modify foo_exclude.txt
, you can do the same thing within the makefile, but it's kind of ugly:
EXCLUDES := $(shell cat ./$(TARGET12)_exclude.txt | sed -e 's|\/ |\/% |' -e 's|\/$$|\/%|')
Related videos on Youtube
Nikola
Updated on June 04, 2022Comments
-
Nikola almost 2 years
I am creating a GNU Makefile and I have a following problem:
I have a list of exclude files (and directories) that need to be excluded from source list. Now, removing listed files from list isn't to big of a problem. I just do the following:
NEWSRC := $(shell find $(SOURCEDIR) -name '*.c') EXCLUDES := $(shell cat ./$(TARGET12)_exclude.txt) #TARGET12 is a Makefile parameter CSRC := $(filter-out $(EXCLUDES),$(NEWSRC))
The problem is when EXCLUDES contain directory (not the file name), and all the file names under the same directory should be also excluded. For example, if the one member of EXCLUDES variable is ../sources/filesystem/SomePath, then all the files under that directory should be excluded from CSRC also. For example, those files could be:
../sources/filesystem/SomePath/something.c ../sources/filesystem/SomePath/src/something.c ../sources/filesystem/SomePath/Some1/src/something.c
Do you know how this could be solved inside Makefile?
Thank you in advance!
-
eriktous about 13 yearsI'm confused by the slash in
/%
. I can see how it works for the directories, but wouldn't this prevent the files in$(EXCLUDES)
from being filtered out? -
Ise Wisteria about 13 years@eriktous: Yes, you are right. I suppose the above code will be used in combination with OP's code.
-
Idelic about 13 yearsYou can handle both cases if instead of
$(addsuffix ...)
you add/%
only for directories:$(foreach i,$(EXCLUDES),$(if $(wildcard $i/.),$i/%,$i))
-
Ise Wisteria about 13 years@Idelic: Interesting solution! As of this writing, OP seems not to have accepted an answer yet. How about posting it as your answer?