next up previous
Next: Useful to know Up: How to make a Previous: Compilation failures

Generating dependencies

The last few lines in figure 10 were used to declare the dependencies. For programs with less than five source files, this is manageable, but for larger programs it is not. Each time the #include structure of a program changes, the dependencies change and the Makefile has to be changed by hand, which is a nuisance for the programmer and extremely error-prone.

Basically, there are a number of ways to automate the process of keeping dependencies up to date. The one most easy to use (although not very flexible) will be explained in this section. There is a tool makedepend that automatically updates the dependencies in our Makefile.

  
Figure 12: A modified Makefile that uses makedepend.

In Figure 12 we specify another target depend and omit the hand written dependencies at the bottom lines. If the user types make depend, the program makedepend runs the preprocessor to find out which dependencies exists for each object file. It keeps a copy of our original Makefile in Makefile.bak and appends the dependencies to our Makefile. Each time we change our #include structure, we should run ``make depend'' prior to doing a plain ``make''. An example of what is appended is shown in Figure 13.

  
Figure 13: A modified Makefile that uses makedepend.



Megens SA
Thu Jun 20 11:26:28 MET DST 1996