Skip to main content
GameDev.net gamedev.net
🔒 Locked

Makefile dependencies

Started by chedburgh Oct 29, 2004 at 7:42 AM 5 replies 900+ views
Original Post
chedburgh
chedburgh
Hi folks, An easy question, i hope. I'm converting my project to linux at the moment, currently writing the Makefiles. I want to auto generate dependencies because i have a large number of source/headers. I've seen a number of scripts, and read about doing it with the gcc compiler (-MM,-MD etc). I am curious to whats the most common way to auto generate dependencies (the gcc method seems the most portable as it does not rely on outside programs). What do you folks use and why? Cheers ched
oddbot
oddbot
Hiya,

On my last project we used perforce jam which automatically figures out the dependencies, which is nice. http://www.perforce.com/jam/jam.html

I'm reading up on another called scons at the moment which also looks good. The quote on the site says that doom3 linux team uses it for their builds, so it must be alright :) http://www.scons.org/

-oddbot
chedburgh
chedburgh
Thanks for the reply oddbot. They both look good, especially scons. I’m going to read up a little on scons myself I think.

I’ve found a Makefile rule on the net today that produces a .d dependency rule file for each source file. These .d files are then included in the Makefile to provide the rules and keep dependencies up to date. It works ok, looks like:

%.d: %.cpp
$(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< | sed '\"s/\($*\)\.o[ :]*/\1 $@/g'\" > $@'

Do many people use this approach?

Cheers
ched
jdhardy
jdhardy
There's some pretty good examples of this sort of thing in the GNU Make manual. I don't know how portable it would be to other makes, however.

The key part is to use gcc -MMD ... to generate the .d depdency files, and then include them in the makefile. You can generate the include list automatically from the .c/.cpp files with patsubst, which is a built in function of make.

EDIT: You want Section 4.14.
chedburgh
chedburgh
I've got the makefile method working now, but i think i'm going to move to scons soon (soon as i've learnt enough about makefiles to keep me happy). Thanks for the replies and advice :)

cheers
ched

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.