[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating an advanced build system
From: |
John Graham-Cumming |
Subject: |
Re: Creating an advanced build system |
Date: |
Thu, 26 May 2005 16:56:56 -0400 |
On Thu, 2005-05-26 at 21:44 +0100, Brendan Heading wrote:
> That was interesting, your proposal is to avoid recursion by including
> the makefiles. Unfortunately I suspect there'll be trouble if the
> included Makefiles happen to redefine variables. For example it might be
> useful for two different libraries to be compiled with different CFLAGS;
> how would you handle that ?
(I copied the mailing list on this reply because the answer may be
useful to others).
So that's probably the #1 objection to non-recursive Make, but I think
it's fairly simple to handle using GNU Make's pattern-specific
variables.
If you look at how I define special rules to put the output in the right
place for each module:
$($(X_MODULE)_OUTPUT)/%.o: $(X_MODULE)/%.c
@$(COMPILE.c) -o '$@' '$<'
$($(X_MODULE)_OUTPUT)/$(BINARY).a: $($(X_MODULE)_OBJS)
@$(AR) r '$@' $^
@ranlib '$@'
$($(X_MODULE)_OUTPUT)/$(BINARY)$(X_EXEEXT): $($(X_MODULE)_OBJS)
@$(LINK.cpp) $^ -o'$@'
Then it's pretty easy to give a specific CFLAGS for the creation of .o's
in a specific module because the module is encoded in the full path of
the .o.
For example, suppose that you want CFLAGS to have the -W option set just
for the library and not the executable. All you need to do is add
$($(X_MODULE)_OUTPUT)/%.o: CFLAGS += -W
To the Makefile in the library/ directory. Running an -n on this shows
the effect (I made X_OUTTOP be /tmp):
cc -W -c -o '/tmp/Linux_i686/library/lib1.o' 'library/lib1.c'
cc -W -c -o '/tmp/Linux_i686/library/lib2.o' 'library/lib2.c'
ar r
'/tmp/Linux_i686/library/lib.a' /tmp/Linux_i686/library/lib1.o
/tmp/Linux_i686/library/lib2.oranlib '/tmp/Linux_i686/library/lib.a'
cc -c -o '/tmp/Linux_i686/executable/foo.o' 'executable/foo.c'
cc -c -o '/tmp/Linux_i686/executable/bar.o' 'executable/bar.c'
g+
+ /tmp/Linux_i686/executable/foo.o /tmp/Linux_i686/executable/bar.o
/tmp/Linux_i686/library/lib.a -o'/tmp/Linux_i686/executable/exec'
Now suppose that you want the exectuable to be built with -g in CFLAGS.
Just add
$($(X_MODULE)_OUTPUT)/%.o: CFLAGS += -g
to the executable/ Makefile and now the output looks like this:
cc -W -c -o '/tmp/Linux_i686/library/lib1.o' 'library/lib1.c'
cc -W -c -o '/tmp/Linux_i686/library/lib2.o' 'library/lib2.c'
ar r
'/tmp/Linux_i686/library/lib.a' /tmp/Linux_i686/library/lib1.o
/tmp/Linux_i686/library/lib2.oranlib '/tmp/Linux_i686/library/lib.a'
cc -g -c -o '/tmp/Linux_i686/executable/foo.o' 'executable/foo.c'
cc -g -c -o '/tmp/Linux_i686/executable/bar.o' 'executable/bar.c'
g+
+ /tmp/Linux_i686/executable/foo.o /tmp/Linux_i686/executable/bar.o
/tmp/Linux_i686/library/lib.a -o'/tmp/Linux_i686/executable/exec'
So the two definitions of CFLAGS are independent of each other.
John.
--
John Graham-Cumming
Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/
GNU Make Standard Library: http://gmsl.sf.net/