Makefile dependencies
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
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
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
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
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
Searching on Google for "automatic dependencies make" I found:
http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_43.html
So yeah, it seems it is normal to use gcc with a -M option.
You might also want to look into Automake:
http://www.gnu.org/software/automake/
http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_43.html
So yeah, it seems it is normal to use gcc with a -M option.
You might also want to look into Automake:
http://www.gnu.org/software/automake/
-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel
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.
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.
October 31, 2004 04:40 AM
I'm in love with scons (www.scons.org). It's portable between windows and linux, and handles dependencies automatically. Scons uses python scripts, not a special-purpose language like make does, and thus it is easy to adjust to any situation.
Here's a small example (as you can see, there's no need to specify dependencies):
Here's a small example (as you can see, there's no need to specify dependencies):
libs = Split(""" SDL_net SDL_ttf SDL_gfx""")sources = Split(""" main.cpp GameBoard.cpp Controller.cpp View.cpp NetworkManager.cpp MessageQueue.cpp Statistics.cpp""")env = Environment()env.ParseConfig('sdl-config --cflags --libs')env.Append(LIBS = libs)env.Program('tictactoe', sources)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement