views:

234

answers:

4

Is there a way to exclude some files from the compilation process? Or even whole directories?

I believe the makefile is using find to find all the source files inside the src directory. Is there a way to specify the directories to ignore from find? Like some switch, or something?

A: 

Sure - do not specify them in your Makefile.

fpmurphy
A: 

You can create separate targets that are the same except for what you want to exclude.

Nathan Fellman
+2  A: 

That depends entirely how your makefile is written. You can use conditionals to avoid adding files given certain conditions hold:

 ifeq ($(OS),win32)
 SOURCES += foo_win32.cpp
 else
 SOURCES += foo_posix.cpp
 endif
 ...
 foo: $(SOURCES)

If you elaborated a little on exactly you want to do, you may get a better answer.

EDIT: If the files are determined by running find, you can exclude files/directories from find like this:

SOURCES:=$(shell find srcdir -type f | grep -v dirtoexclude)
JesperE
How would they be filtered from the `find` command?
Geo
The find command has syntax for excluding files, but it is rather convoluted. I usually pass the find output through grep in these cases: "find ... | grep -v somedir".
JesperE
BTW: using find to determine which source files to compile is bad practise, since any file which happens to reside in your source tree will be included. You should consider a static list instead.
JesperE
Add that to your answer and I'll accept it.
Geo
+2  A: 

Makepp (a replacement for Make) can do this:

http://makepp.sourceforge.net/1.19/makepp_cookbook.html#Matching%20all%20files%20except%20a%20certain%20subset

DavidM