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!
The makefile is a text file that contains the recipe for building your program. It usually resides in the same directory as the sources, and it is usually called Makefile . Each one of these commands should be a separate rule in a makefile.
4.4. 3 The Function wildcard $(wildcard pattern …) This string, used anywhere in a makefile, is replaced by a space-separated list of names of existing files that match one of the given file name patterns. If no existing file name matches a pattern, then that pattern is omitted from the output of the wildcard function.
The $@ and $< are called automatic variables. The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.
some projects put their makefile in src/ subdirectory of the root directories of the projects, some projects put their makefiles in the root directory of the project.
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))
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|\/$$|\/%|')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With