help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: recusrive make or include make files


From: Philip Guenther
Subject: Re: recusrive make or include make files
Date: Mon, 15 Jan 2007 02:46:47 -0700

On 1/15/07, sharan basappa <address@hidden> wrote:
...
Problem : In the process I have gone through both the options of doing this
using recursive make option or including these submakes into main make file.
 The issue that I forsee in case of including submake file is that individuals 
who
create these submakes have to be aware from where their make files will be
called, whereas in case of resursive make, once the make works in their
directory it will always work if top level make executes these make files.

The solution I used when I moved a non-trivial project (~50
directories containing source) over to a set of non-recursive
makefiles ran something like this:
1) the variable 'TOP' is defined to be the path of the top of the source tree
2) the variable 'THIS' is defined to be the path of the current
directory relative
  to ${TOP}
3) the above are accomplished by the following:
    - the toplevel GNUmakefile conditionally (?=) sets TOP to '.' and
THIS to the
      empty string
    - each subdirectory contains a GNUmakefile that sets TOP and THIS and then
      includes ${TOP}/GNUmakefile
4) all other files included by make perform all their actions relative to ${TOP}
5) ${THIS} is used to control the dependencies of the default target,
so that simply
  type 'gmake'  in a directory will end up compiling all objects and
programs in
  all the directories below the current directory
6) the 'real' actions for a given directory are not in the GNUmakefile for that
   directory but rather in a file "Makefile.inc", which is included
by its parent
   directory's Makefile.inc, up to the toplevel where the
Makefile.inc is included
  by the GNUmakefile.


The key item is #4.  If you can drill in that *everything* is done
relative to ${TOP} (or particular variables derived from ${TOP}) then
things Just Work.  I was on a small enough team that that my teammates
would just ask for help when they had doubts.  Having an extended
discussion ahead of the changeover to make sure they all were
comfortable that the new setup would express the dependencies properly
and otherwise support them during development was important too.

It also helped that the actions for a given directory were almost
completely factored out into a single file, so that the Makefile.inc
for almost all directories containing source simply sets six variables
and then includes that common file.  You need to add a source file?
Just add the resulting object to the list of objects for the directory
and let the pattern rules do the rest.  Need another compiler flag?
Add it to another variable.  Only a few directories are different
enough to need more than that.


Philip Guenther




reply via email to

[Prev in Thread] Current Thread [Next in Thread]