An easier way to calculate C source dependencies
Those who follow the single makefile approach outlined by Peter Miller in his excellent paper Recursive Make Considered Harmful may be interested in the -MT option to the GCC preprocessor, introduced after Peter wrote the paper.
This switch allows the target name to be explicitly defined, multiple times if required, instead of being derived from the source file name. An sample command to be inserted into the makefile (instead of using depend.sh in Peter’s example) is
$(CC) $(CFLAGS) -MM -MG -MT $(OBJ_DIR)/$(*).o -MT $(DEP_DIR)/$(*).d -MF $@ $<
Notice that I keep my dynamic dependency files in a separate directory to the source code.
powered by performancing firefox
No comments yet.
Leave a comment
What’s it all about
Alec’s warped view on the world of software and sometimes life in general.
Pithy, germane, comments are always welcome.

This content on this site is copyright Alec Clews and licensed under a Creative Commons Attribution-ShareAlike 3.0 License unless otherwise stated.
N.B. Postings on this site represent my personal opinion only and many factors specific to your environment may invalidate this information. You should check before relying on anything I say or quote here.
-
Archives
- October 2008 (2)
- September 2008 (1)
- August 2008 (12)
- July 2008 (11)
- June 2008 (11)
- May 2008 (15)
- April 2008 (11)
- March 2008 (4)
- February 2008 (12)
- January 2008 (13)
- December 2007 (10)
- November 2007 (7)
-
Categories
-
RSS
Entries RSS
Comments RSS