Unni
Unni

Reputation: 5794

How to use GNU Make filter-out a list of files from a directory?

I have a list of cpp files that I want to exclude from my Makefile. I can't apply a wildcard as in this question; instead, I want to exclude a list of specific file names. How do I do that?

This doesn't seem to work.

SRCDIR = ../src

EXCLUDE := file1.cpp,file2.cpp,file3.cpp
SRCS    = $(shell find $(SRCDIR) -name '*.cpp')
SRCS := $(filter-out $(SRCDIR)/$(EXCLUDE) , $(SRCS))

Looking at the documentation, multiple files can be filtered as:

objects=main1.o foo.o main2.o bar.o
mains=main1.o main2.o

$(filter-out $(mains),$(objects))

So my question pretty much becomes whether there is a way to exclude ../src/file1.cpp, ../src/file2.cpp, ../src/file3.cpp by loading value from the variable SRCDIR?

Upvotes: 2

Views: 1979

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136286

You probably want something like:

SRCS := $(filter-out $(EXCLUDE:%=$(SRCDIR)/%),$(SRCS))

Upvotes: 1

Related Questions