next up previous
Next: A more complicated sample Up: Lots of tips Previous: Lots of tips

Automating dependency creation

 

There is a neat utility called makedepend which can go through your source code and see which files #include which other ones. It's used like this: makedepend [options] source-files. For options, -Idirectory tells it to look in directory for include files, and -Ydirectory tells it not to look in directory. Just -Y by itself means not to look at any of the system include directories. You can give as many -I and -Y options as you need. Makedepend ignores any options it doesn't understand; this is useful as you'll see below.

If you give it -Y, it will probably spit out a bunch of stuff about not being able to find iostream.h and so on. Just ignore these messages.

After makedepend scans your source code, it tacks the resulting dependency rules onto the end of your makefile and saves you a ton of typing.

It's very useful to have a ``depend'' target in your makefile which does this automatically:

depend:
   ->   makedepend $(CXXFLAGS) -Y $(SRC)

We give makedepend the CXXFLAGS because that macro contains -I commands which are normally passed to g++ to tell it where the tapestry .h files are, but those same commands are useful here. Makedepend happily ignores any other options in CXXFLAGS such as debugging flags.



Garrett
Fri Jan 24 17:04:25 EST 1997