Re: GNU make: recursive make vs single makefile



On 11 Dec 2006 11:13:21 -0800, Dmitry Chumack <saint.d.a@xxxxxxxxx> wrote:

http://www.canb.auug.org.au/~millerp/rmch/recu-make-cons-harm.html

I'm interested in are there anybody who is experienced in such a
technics of using single makefile and who knows in practice about
advantages and disadvantages of this two methods.

I have built a make system for a smallish project based more or less on
the ideas in that article. The project has six source subdirectories
and about 14,000 lines of C (not including headers). It creates about a
dozen executables and three static libraries. It builds natively for
i386 Linux and also cross compiles to PowerPC Linux using ELDK and on
Solaris 10 using the GNU toolchain.

As suggested, I split the makefiles up into sub-makes that get included
by the main makefile. I also made a set of macros so you could add new
targets to a sub-make using some simple syntax, for example:

TGT := orient
SRC := orient.c \
orient_nav.c \
orient_proc.c \
orient_sim.c \
orient_xbow.c

include $(scriptdir)/module_add.mk


These macros were probably the hardest part, but they save a lot of
duplication and make it almost trivial to add a new build target or
remove an unneeded one.

The method has some advantages:

1. If you change a function way over there in a library, only the
changed files (and dependencies in the case of headers) get rebuilt.
The programs that depend on the library just get re-linked. This works
reliably.

2. No worries about including header files across subtrees. The
dependencies are handled automatically.

3. You learn a lot about make syntax and features getting it working
the first time.

4. The sub-makefiles are pretty simple and it is easy for developers
who are not familiar with make to work with them.

5. Builds work correctly no matter where in the tree you are when you
invoke make, no matter what has been changed.

6. The ideas about automated dependency handling are very useful and
make the build a lot more robust against changes to buried dependencies.
It has been a while since I had to do "make clean" just to get a build
to work.

7. Despite all of the macros & stuff, I actually know what my makefile
is doing and can troubleshoot it. Autotools makefiles seem very obscure
to me, but I'm also not very experienced with them.


Disadvantages include:

1. The sub-makefiles are included rather than run by themselves. This
can lead to odd behavior when you define some variable and some other
sub-make defines the same variable. You quickly learn to use a prefix
or suffix scheme so variables are unique.

2. You don't get all the nifty feature-detection and cross-compile
macros that autotools gives you. You get to do that yourself.

3. You learn more than you wanted to know about make syntax and
features getting it to work the first time. There are no automated
tools as there are for automake.

4. Getting feature #5 above working involved a lot of tricky macros and
some GNU extensions.

All in all I'm pretty happy with the way the system turned out. There
are two other developers working with it, we have about four branches of
the project going right now for different hardware platforms, and so far
nobody is yelling about builds not working.


--
-| Bob Hauck
-| Hooray for San Fancisco values!
-| http://www.haucks.org/
.



Relevant Pages

  • nmake building what it shouldnt?!
    ... I have an app that is made with one solution and several projects ... The way this is currently handled, with VS6, is with nmake makefiles. ... There is a separate file containing macros, ... into the main makefile for the solution. ...
    (microsoft.public.vc.ide_general)
  • Re: 68008 co-processor board complete working design available ...
    ... Uses 4 simple macros. ... All-h.txt = All .h files needed by the makefile run together into ... I do note that having the coprocessor interface with the 6502 CPU by a ... dedicated 512x9 FIFO in each direction allows some really nice things, ...
    (comp.sys.apple2)
  • Re: newbie has linker error
    ... > Here are the abridged listings of the base class declaration and the ... > makefile for library: ... >>Provide some sample code please. ... the 'C' macros for C++ usage, rather than using the C++ macros, ...
    (comp.os.linux.development.apps)
  • Re: nmake building what it shouldnt?!
    ... The way this is currently handled, with VS6, is with nmake makefiles. ... There is a separate file containing macros, ... into the main makefile for the solution. ...
    (microsoft.public.vc.ide_general)
  • Re: Define feature flags for use in Makefiles and C code?
    ... avoid having to keep each thing in sync. ... Chances are you won't be using FEATURES for anything else in your ... If you are then your makefile has room for improvement. ...
    (comp.unix.programmer)