Article View: gnu.misc.discuss
Article #2339Re: problem with gnu make's static pattern rules
From: Larry Morris
Date: Fri, 24 Sep 1993 20:54
Date: Fri, 24 Sep 1993 20:54
102 lines
3645 bytes
3645 bytes
In <27u2v6$gqc@TAMUTS.TAMU.EDU> vamsee@abgen.tamu.edu (Vamsee) writes: >Newsgroups: gnu.gcc.help,gnu.misc.discuss >Hi, >I am using GNU make (3.68) on a SPARCclassic running SunOS 4.1.3C. >I am trying to use the feature described on page 37 of the GNU make >manual. My makefile looks like this: >---------------- ># >SHELL = /bin/sh >a.d b.d: %.d: %.c > @echo $* $< $@ >----------------- >When I type make I got the following output: >a a.c a.d >instead of the expected: >a a.c a.d >b b.c b.d >Am I missing something here? Is this a bug or a problem with our >installation? I came across this problem when I was trying to >generate dependencies for a bunch of source files using : >DEPS = $(SRCS:.c=.d) Well, you have it almost right. The rule is doing what you asked. I think the part that is confusing you is what target gets built. If you specify no target, gmake builds the first one it finds. In your case, that is a.d. If you had typed "gmake b.d" you would have made the other rule. And to actually make use of the .d files, you must include them. See the following example: ---------------- Cut Here ----------------------- # Makefile with Auto Dependency Generation SHELL = /bin/sh include a.d b.d a.d b.d: %.d: %.c @echo $* $< $@ ---------------- Cut Here ----------------------- Or a more realistic example: ---------------- Cut Here ----------------------- # SHELL = /bin/sh SOURCES = a.c b.c #******* Put default rule first ************* all : main #****************************************************************************** # Rule to update dependency list and include those dependencies # The first sed script adds the .d file to the dependency rule. The second # sed script removes the leading path information from the dependencies so # that vpath can work its magic. Damn this is fun # Note: the -I- is because we don't want to use any system include files #****************************************************************************** %.d: %.c @ gcc -MM -nostdinc -I- $(INCLFLG) $< | sed 's/$*.o/& $@/g' | \ sed 's/: .*\/.*\//: /g' > $@ include $(SOURCES:.c=.d) main: $(addsuffix .o,$(basename $(SOURCES) )) @ echo ---- Here is the a.d file ----- @ cat a.d @ echo ---- Here is the b.d file ----- @ cat b.d @ echo ---- Ready to do some cool things like compile now ----- ---------------- Cut Here ----------------------- Anyway, give this a spin. It is a really nice feature. P.S. I am also using 3.68 on a Sparc. -- Internet: <lmorris@mdd.comm.mot.COM> | Larry Morris ...uw-beaver!sunup-----\ | Motorola/Mobile Data Division ...uunet-----------------!mdisea!lmorris | 19807 North Creek Parkway ...van-bc!mdivax1------/ | Bothell, WA (206) 487-5810
Technical Details
Message-ID:
<1993Sep24.205414.11019@mdd.comm.mot.com>Path:
arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!mdisea!lmorrisReferences:
<27u2v6$gqc@TAMUTS.TAMU.EDU>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,130fd7041a66f0c1 X-Google-Attributes: gid11318c,public X-Google-Thread: 1025b4,130fd7041a66f0c1 X-Google-Attributes: gid1025b4,public X-Google-ArrivalTime: 1993-09-24 15:51:27 PST Newsgroups: gnu.misc.discuss,gnu.gcc.help Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!mdisea!lmorris From: lmorris@mdd.comm.mot.com (Larry Morris) Subject: Re: problem with gnu make's static pattern rules Message-ID: <1993Sep24.205414.11019@mdd.comm.mot.com> Sender: news@mdd.comm.mot.com Organization: Motorola, Wireless Data Group - Seattle, WA References: <27u2v6$gqc@TAMUTS.TAMU.EDU> Distribution: na Date: Fri, 24 Sep 1993 20:54:14 GMT Lines: 102