bug-make
[Top][All Lists]
Advanced

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

Shorter and less error-prone rule for automatic prerequisite generation


From: Robert Jørgensgaard Engdahl
Subject: Shorter and less error-prone rule for automatic prerequisite generation in the GNU Make manual
Date: Wed, 28 Apr 2010 09:04:55 +0200


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.
This fixes disagreements about object file names between the sed command and the cc command, should the c file not be found in the current directory.

Perhaps it would be time to make this rule part of the default rules in GNU Make? In that case, the -MG option should also be considered for avoiding errors when auto generated headers are included, perhaps via an CCMFLAGS variable.

Best regards Robert

-------
Robert Jørgensgaard Engdahl
Cum Laude MSc. C.S.
SW-Developer, R&D
Video Services & Applications

Bang & Olufsen A/S
Peter Bangs Vej 15
DK-7600 Struer
Denmark

Phone: (+45)  96 84 44 05
Internal phone: 454405
e-mail: address@hidden
Location: Factory 1 - West

reply via email to

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