🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3775

Re: Dependencies in makefile

#3775
From: Jonathan Kamens
Date: Wed, 09 May 2001 13:45
60 lines
2695 bytes
In article <3AF90198.CE0A2ED8@webmaster.com>,
 David Schwartz <davids@webmaster.com> writes:
>> I am using GNU make.
>> 
>> Can I write in makefile dependencies as following :
>> xxx.o : *.h
>> instead of
>> xxx.o: aaa.h bbb.h
>> ?
>
>	What would that mean? Which header files?

Um, it would mean all of the files which match the wildcard, i.e., all
the header files in the directory, obviously.  In other words,
"Rebuild this object if any of the header files changes."

To answer the original poster's question, yes, in GNU Make you can use
wildcards in dependencies, but you need to make sure that at least one
file matching the wildcard actually exists, or you'll get an error. 
For example:

/tmp> mkdir test-make
/tmp> cd test-make
/tmp/test-make> cat > Makefile
foo: *.h
	touch foo
/tmp/test-make> make foo
make: *** No rule to make target `*.h', needed by `foo'.  Stop.
/tmp/test-make> touch a.h
/tmp/test-make> make foo
touch foo
/tmp/test-make> make foo
make: `foo' is up to date.
/tmp/test-make> touch b.h
/tmp/test-make> make foo
touch foo
/tmp/test-make> make foo
make: `foo' is up to date.
/tmp/test-make> touch a.h
/tmp/test-make> make foo
touch foo
/tmp/test-make> make foo
make: `foo' is up to date.
/tmp/test-make> 

You can alo use $(wildcard *.h) instead of *.h in your dependency, in
which case you won't get an error if there aren't any *.h files:

/tmp/test-make> cat > Makefile2
foo: $(wildcard *.h)
        touch foo
/tmp/test-make> rm *.h
/tmp/test-make> make -f Makefile2 foo
make: `foo' is up to date.
/tmp/test-make> touch a.h
/tmp/test-make> make -f Makefile2 foo
touch foo
/tmp/test-make> make -f Makefile2 foo
make: `foo' is up to date.
/tmp/test-make> 
Technical Details
Message-ID: <9dbhlf$tn2$1@jik.kamens.brookline.ma.us>
Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news.isc.org!jik.kamens.brookline.ma.us!jik
References: <3AF90A5B.BAB9D265@bigfoot.com> <3AF90198.CE0A2ED8@webmaster.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109f73,7c88a878fd5a1a6f
X-Google-Attributes: gid109f73,public
X-Google-Thread: fc89c,7c88a878fd5a1a6f
X-Google-Attributes: gidfc89c,public
X-Google-ArrivalTime: 2001-05-09 07:01:02 PST
Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news.isc.org!jik.kamens.brookline.ma.us!jik
From: jik@kamens.brookline.ma.us (Jonathan Kamens)
Newsgroups: comp.unix.programmer,gnu.utils.help
Subject: Re: Dependencies in makefile
Date: 9 May 2001 13:45:19 GMT
Organization: jik's Linux box
Lines: 60
Message-ID: <9dbhlf$tn2$1@jik.kamens.brookline.ma.us>
References: <3AF90A5B.BAB9D265@bigfoot.com> <3AF90198.CE0A2ED8@webmaster.com>
NNTP-Posting-Host: jik-0.dsl.speakeasy.net
X-Trace: jik.kamens.brookline.ma.us 989415919 30434 216.254.78.45 (9 May 2001 13:45:19 GMT)
X-Complaints-To: usenet@kamens.brookline.ma.us
NNTP-Posting-Date: 9 May 2001 13:45:19 GMT
X-Newsreader: xrn 9.03-beta-5