help-make
[Top][All Lists]
Advanced

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

Re: Problem with phony target


From: Philip Guenther
Subject: Re: Problem with phony target
Date: Sat, 18 Sep 2010 21:07:05 -0700

On Sat, Sep 18, 2010 at 5:17 PM, Sergio Belkin <address@hidden> wrote:
> I have a Makefile that even when issuing for the first time the PHONY
> target clean wants to recompile as you can see below:
>
> Makefile:218: UpLog.d: No existe el fichero o el directorio
...

Hmm, ".d" suffix.  Sounds like you're using the original style of
auto-dependency generation where there are rules for the dependency
files (the .d files).  That works, but you'll want to wrap the
'include' line that pulls them into the makefile with a conditional so
that make doesn't include them (and therefore try to build them) if
you're doing "make clean".  An example of this can be found in the GNU
make info pages, section "Arguments to Specify the Goals":
-----
   `Make' will set the special variable `MAKECMDGOALS' to the list of
goals you specified on the command line.  If no goals were given on the
command line, this variable is empty.  Note that this variable should
be used only in special circumstances.

   An example of appropriate use is to avoid including `.d' files
during `clean' rules (*note Automatic Prerequisites::), so `make' won't
create them only to immediately remove them again:

     sources = foo.c bar.c

     ifneq ($(MAKECMDGOALS),clean)
     include $(sources:.c=.d)
     endif
------

So, find the 'include' line in your makefile and wrap it with an
ifneq/endif as shown above.


(If there are other targets that, like 'clean', shouldn't trigger
building of dependencies, then you may want to use a conditional that
uses $(filter) to match the involved targets, ala:

ifneq ($(filter clean clean-%,$(MAKECMDGOALS)),)
include ....whatever
endif

That example would skip including dependencies if there's a target on
the make command line of "clean" or anything beginning with "clean-".)


That's the fast solution.  The more complicated solution is to change
to a newer style of auto-dependency generation where the .d files are
generated as a side-effect of the compilation instead of separately.
For information on doing that, read Paul's webpage about it at:
    http://make.paulandlesley.org/autodep.html


Philip Guenther



reply via email to

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