[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: i need some smart rule
From: |
Paul D. Smith |
Subject: |
Re: i need some smart rule |
Date: |
Wed, 6 Mar 2002 22:35:31 -0500 |
%% Maciej Walezak <address@hidden> writes:
mw> Hello,
mw> I need several rules that would link binary files and each of them
mw> with different commands, i.e. one for binaries from objects from C
mw> sources, one for binaries from objects from C++ sources and one
mw> for Fortran.
In general, if you can't distinguish between the lists of object files
to tell which executables should be built using what commands, then
there's no way make can do so either.
mw> My current solution is
mw> $(bin)/$(cbin):
mw> command1
mw> $(bin)/$(ccbin):
mw> command2
mw> $(bin)/$(fbin):
mw> command3
mw> I do not like this solution as it requires that appropriate
mw> variable is defined and it prevents me from linking more that one
mw> binary in single makefile (cbin is set to a concrete file).
mw> Is there a way to write these rules in more flexible way?
Well, you can do something like this:
$(cbins:%=$(bin)/%):
...build from .c files...
$(ccbins:%=$(bin)/%):
...build from .cc files...
$(fbins:%=$(bin)/%):
...build from .f files...
Now you can set "cbins" to a list of executables, like this:
cbins = foo bar baz
foo: foo.o biz.o
bar: bar.o bong.o
baz: baz.o bloz.o
Note that a rule that has an empty target is ignored, so you won't get
errors if one or more of the variables doesn't have a value. But, if
you don't want to rely on this you can always do something like:
ifdef cbins
$(cbins:%=$(bin)/%):
...build from .c files...
endif
ifdef ccbins
$(ccbins:%=$(bin)/%):
...build from .cc files...
endif
ifdef fbins
$(fbins:%=$(bin)/%):
...build from .f files...
endif
or whatever.
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://www.paulandlesley.org/gmake/
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist