help-make
[Top][All Lists]
Advanced

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

Re: Probems building a project after moving header files


From: Darin Johnson
Subject: Re: Probems building a project after moving header files
Date: Sun, 14 Aug 2005 16:30:00 -0700 (GMT-07:00)

Angel Tsankov writes:
> Of course, the main makefile includes all the dependency (make)files.
> This is done at the end of the main makefile.

Step one is to include the dependency files with a "-" prefix, as in
   -include somefiles.dep
This causes make to continue without an error if the included file
does not exist.

> make said it does not know how to build the header file I'd
> just moved (this header file was a prerequisite of a dependency
> file).

Of course, you can always just settle for the "rebuild everything"
approach, since moving files around is typically rare.  But it can
help to have make know to avoid the header files if they move.
Just having a single line like:
   header.h:
causes make to ignore it if it can't be built.  If you want to do this
automatically then there are two approaches.  First, use a perl
script to rewrite the dependency file to add this line.  Second, if you
use GNU C then it can be done for you.  Where you would normally
add a "-MMD" flag to automatically create a dependency file, you just
change that to "-MMD -MP".

This GNU C approach, if you can use it, is very nice and very clean.
Combine it with a "-include *.d" and almost all of the old Makefile
ugliness about creating dependencies can go away.  No more
"make depend" or embedded "sed" expressions.

> This led to another problem: cleaning a project more than once in
> succession causes the dependency files to be regenerated on each
> cleaning after the first one (which I do not find very appropriate).

Again, a solution.  Wrap the "-include" line around a conditional that
tests your build target so that they aren't included on maintenance
targets.  The target being built is stored in the MAKECMDGOALS
variable.  For instance, I do something like this so that dependencies
aren't included if the targets are "clean" or "clobber":
    ifeq ($(filter clean clobber,$(MAKECMDGOALS)),)
    -include *.d
    endif





reply via email to

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