At 01:53 PM 8/20/2004, David Wuertele wrote:
The reason I chose recursive in the first place was for a couple of
reasons:

1.  I want to be able to run make in the sub-directory and have it
    work

2.  I want to use the same variable namespace for all the makefiles.
    For example, I don't want one of my users to have to create
    variable names like:

      my_program_OBJ := this.o that.o

    I want them to be able to write:

      OBJ := this.o that.o

    This is an oversimplified example for the purposes of making the
    point.  I want them to be able to copy their neighbor's Makefile
    and not have to change all the variable names.

Is there a way to write makefiles in a non-recursive fashion that will
enable me to acheive both goals?

I've had success with a circular-include design. E.g. there's a Makefile per directory, just like in the recursive model. Each Makefile includes the "base makefile", and the base makefile in turn includes all subtree Makefiles (this takes a bit of macro/ifdef logic to prevent infinite include loops). The net result is a single logical Makefile accessible via a different physical "entry point" in each subdir.


This preserves two of the major benefits of the recursive model: (1) the user can simply type "make" in any directory (as opposed to "make -f ../../../Makefile") and (2) a developer adding a new source file need only modify the Makefile in the same dir, which usually is just a list of object files, without having to delve into the arcanities of the full build system.

Since slashes are a legal part of a variable name in make, I tend to prefix local variables with the subdir path, e.g. "my/sub/dir_OBJS=obj1.o obj2.o". At the time I did this it had to be compatible with GNU make 3.75 or so; it's quite possible that newer versions offer help with generating unique names, similar to what Noel Yap mentioned.

Though the ability of a non-recursive system to detect and deal with out-of-dateness in other parts of the tree is generally considered a feature, a colleague subsequently added a feature such that "make local" would build only objects local to the cwd and thus emulate recursive behavior.

-David Boyce



_______________________________________________
Help-make mailing list
[EMAIL PROTECTED]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to