bug-make
[Top][All Lists]
Advanced

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

Re: Shorter and less error-prone rule for automatic prerequisite genera


From: Mike Shal
Subject: Re: Shorter and less error-prone rule for automatic prerequisite generation in the GNU Make manual
Date: Wed, 28 Apr 2010 09:47:37 -0400

On 4/28/10, Robert Jørgensgaard Engdahl <address@hidden> wrote:
>
> Hello GNU Make bug-list subscribers
>
> On
>
> http://www.gnu.org/software/make/manual/make.html#Automatic-Prerequisites
>
> The rule for automatically generating prerequisites is
>
>  %.d: %.c
>              @set -e; rm -f $@; \
>               $(CC) -M $(CPPFLAGS) $< > address@hidden; \
>               sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < address@hidden > $@; \
>               rm -f address@hidden
>
> but could be replaced with
>
> %.d : %.c
>         @$(CC) -MT $@ -MT $*.o -MM $(CPPFLAGS)  $< > $@
>
> This is simpler.

It's also unnecessary - you don't need a rule for %.d at all. You can
just generate the dependencies as a side-effect of compilation using
-MMD or similar. Then use '-include' to grab all the deps if they
exist. By providing a rule for the .d files you'll cause make to
re-execute itself, so you'll just end up parsing the Makefile twice.

-Mike




reply via email to

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