|
1. Recursive Makefile
|
|
Sun Dec 26, 2004 [6:40 PM]
|
Rhaelar
rhaelar@sdmud.com
member since: Aug 22, 2004
|
Reply
|
|
Hi again.
I'm trying to make my Makefile recurse into all subdirs from the Makefile dir and compile from what it finds. This example below works if the C files are in the same folder as the Makefile, what I want to do is, make the wildcard recurse into subdirectories like 'main', you know what I mean.
This works if C files are in same folder:
C_FILES := $(wildcard *.c) O_FILES := $(patsubst *.c, %.o, $(C_FILES)) H_FILES := $(wildcard *.h)
|
|
|
|
|
2. RE: Recursive Makefile
|
|
Sun Dec 26, 2004 [7:02 PM]
|
Tyche
Email not supplied
member since: Apr 4, 2000
|
In Reply To
Reply
|
You're actually describing non-recursive make if you'd like to do this from a single makefile in the main project directory. This article may help: Recursive Make Considered HamfulAlso this next article describes some excellent techniques to do automated dependencies: Autodependencies with GNU make Recursive makes do something like the following. Your main makefile would do something like this...
DIRS=foo bar baz
all clean test:
for subdir in $(DIRS); do \
( cd $$subdir; echo 'making $@ in `pwd`'; make $@ ); \
done
Then each subdirectory (foo, bar, baz) would have a Makefile that would do stuff for that directory and maybe descend into their subdirectories. But if you read the article above you might conclude that the common way of doing recursive make it may not be all that great. It describes make in a single makefile, which sounds like what you'd prefer. You might consider using an alternative like jam instead of make. I like jam over make.
|
|
|
|
|
3. RE: Recursive Makefile
|
|
Sun Dec 26, 2004 [7:10 PM]
|
Rhaelar
Email not supplied
member since: Aug 22, 2004
|
In Reply To
Reply
|
|
Hmm, yes. I mean non-recursive make then, I just want it to include the ofiles from all the subdirs in O_FILES. I'm looking into Jam right now, you know a simple way to do this though?
|
|
|
|
|
4. RE: Recursive Makefile
|
|
Sun Dec 26, 2004 [10:02 PM]
|
Razzer_9
Email not supplied
member since: Mar 5, 2001
|
In Reply To
Reply
|
|
Why not:
O_FILES = subdir/*.o subdir2/*.o
...
mud: gcc -o mud O_FILES
|
|
|
|
|
5. RE: Recursive Makefile
|
|
Mon Dec 27, 2004 [8:07 AM]
|
Tyche
Email not supplied
member since: Apr 4, 2000
|
In Reply To
Reply
|
Well it was on page 11 of that link. Anyway here's a simplest example.
$ d -T
/home/tyche/tmake/:
|-bar/:
| `-bar.c
|-foo/:
| `-foo.c
|-Makefile
`-main.c
$ cat Makefile
SRC := $(wildcard foo/*.c bar/*.c *.c)
OBJ := $(patsubst %.c,%.o, $(SRC))
main: $(OBJ)
$(CC) -o $@ $(OBJ)
$ make
gcc -c -o foo/foo.o foo/foo.c
gcc -c -o bar/bar.o bar/bar.c
gcc -c -o main.o main.c
gcc -o main foo/foo.o bar/bar.o main.o
Howto point to the proper include files, and generate depencies is also in the doc I linked to.
|
|
|
|
|
6. RE: Recursive Makefile
|
|
Mon Dec 27, 2004 [9:44 AM]
|
Rhaelar
Email not supplied
member since: Aug 22, 2004
|
In Reply To
Reply
|
|
Ok it's working fine now. Thanks ya'll.
Another question, how do I make the Makefile dump all the compiled o files into another folder instead of just the same folder as the Makefile?
|
|
|
|
|