Nikola
Nikola

Reputation: 231

Makefile excluding files

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!

Upvotes: 11

Views: 17405

Answers (3)

user2609108
user2609108

Reputation: 1

you can use

EXCLUDES := $(shell cat ./$(TARGET12)_exclude.txt)
EXCLUDES_FILE := { notdir $(EXCLUDES )}
CSRC := $(filter-out $(EXCLUDES_FILE),$(NEWSRC))

Let me know if it works

Upvotes: 0

Beta
Beta

Reputation: 99094

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|\/$$|\/%|')

Upvotes: 2

Ise Wisteria
Ise Wisteria

Reputation: 11669

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))

Upvotes: 9

Related Questions