[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Prime Mover v0.1
- From: Ralph Hempel <rhempel@...>
- Date: Mon, 16 Oct 2006 17:41:43 -0400
David Given wrote:
All right, try this: I have fifty files in directory A, all with .c
extensions, that need to be built with one particular set of compilation
options. I also have fifty files in directory B, all with .c extensions, that
need to be built with *another* set of compilation options. How do you write a
single makefile that deals with this cleanly?
The answer is, you can't. make automatically determines what rule to apply to
each file based on the file extension. (Actually, a file pattern. It might be
possible to use patterns of the form 'A/%.c' and 'B/%.c', but I'd be hesitant
to use it.) However, it only allows you to specify a *single* rule for each
pattern. In order to solve the above problem, you have two options: firstly,
you can specify manually which files each rule should apply to --- which
rather defeats the purpose of make's automatic rule mechanism --- or else you
write two makefiles, which is much less effort, but which blows a big hole in
the dependency management.
First, dump all of the built in rules - they are for simple default
build scenarios, which yours is clearly not :-)
Then, learn to use the 'A/%.c' and 'B/%.c' patterns, and specify
what you want to do to build the .o files, and what compiler options,
like this:
CCFLAGS_A = some flag settings for scenario A
CCFLAGS_B = some flag settings for scenario B
A/%.o : %.c
$(COMPILER_BIN)/$(CC) $(CFLAGS_A) $<
B/%.o : %.c
$(COMPILER_BIN)/$(CC) $(CFLAGS_B) $<
I've got specific definitions for COMPILER_BIN and CC because
I use toolchains for multiple processors in my project. Talk
about flags for this set of files vs files for that set!
It gets even worse when your two sets of files are all in *one* directory. It
gets an order of magnitude worse when you try to bolt in automatic C
dependency management. It gets *another* order of magnitude worse when you try
to add support for cross-compilation. And if you try to add support for
multi-stage compilation, make curls up in a corner and cries.
Yes, but if you talk in a quiet voice and lower yourself to its level
it will eventually come out, and then you can hit it over the head
and make it do what you want :-)
Trust me. I know how to use make.
I think you do too, and I think we all would like a better general
purpose scripting ability for or alternative to make. But there's
a lot of inertia behind that tool....
Cheers, Ralph