How to arrange many files of C source code

J

Jorgen Grahn

I strongly recommend against that. Google "recursive make considered
harmful". That paper does a good job of explaining why.

There may be working recursive Makefiles ... but I have never seen
one. I have seen the harm described in the paper, though!

/Jorgen
 
S

Seebs

I strongly recommend against that. Google "recursive make considered
harmful". That paper does a good job of explaining why.
There may be working recursive Makefiles ... but I have never seen
one. I have seen the harm described in the paper, though!

Not really directly C-related, but I've done fine with it for cases where the
things being built are NOT a single unified app, but rather, a selection of
logically-independent things. Even then, it's not awesome, and it's not clear
to me that there isn't a better way.

Come to think of it, I have some code that uses recursive make for packaging
because some of the things in it contain sub-things. And it's not bug-free or
hassle-free, but it's been better than the alternatives I thought of in terms
of "that took five minutes and now I can get back to code".

-s
 
J

Jorgen Grahn

Not really directly C-related, but I've done fine with it for cases where the
things being built are NOT a single unified app, but rather, a selection of
logically-independent things. Even then, it's not awesome, and it's not clear
to me that there isn't a better way.

I think I'd reason like this:

- If they really /are/ independent things, they should be built
separately, each with its own Makefile, and no top-level one.

- If they aren't, I write a single Makefile which treats directory
components as part of the filename. No VPATH or anything like that.
I use libraries to divide and conquer if the number of files gets
too high:

libfoo.a: foo/bar.o
libfoo.a: foo/baz.o
libfoo.a: foo/bat.o
Come to think of it, I have some code that uses recursive make for packaging
because some of the things in it contain sub-things. And it's not bug-free or
hassle-free, but it's been better than the alternatives I thought of in terms
of "that took five minutes and now I can get back to code".

The cost of broken dependency tracking comes (if it comes) much later,
when you start debugging faulty builds, or develop the habit "I'll
do another 'make clean' just to be sure".

Also, with the small--medium projects I've been in, it's not really
harder to write one Makefile than one per directory. Not with Gnu
Make, anyway.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top