A2: Part 2 -- Tracking include dependencies

One of the things that make can do is track all of the include dependencies of your files. This means that it must figure out all of the files that are included by your files and by the files that your files include.

You are to write a Perl program called trackinclude that will print out all of the files included by the file or files given as command line arguments. It will do this recursively.

Your program will print out the name of the file given on the command line argument. The names of any include files found in the command line argument will be printed below indented by 2 spaces. Each time you read a file to look for includes, you will indent the output by 2 spaces.

Recall that #include "x.h" means that x.h will be found in the current directory. (Depending on the compile flags, we may look elsewhere also, but for the purposes of this assignment, you may assume that we only look in the current working directory.)

Recall that #include <stdio.h> means that stdio.h will be found in /usr/include/. However, #include <iostream.h> will be found in /usr/include/g++-3. Your program must check these two directories when looking for an include file of this format.

If we have seen a file before we don't need to read through it again to find the includes inside it, so we will mark it with the number of times that we have seen it, and not print out the subtree of its includes again.

Suppose we run trackinclude test.c and the contents of the relevant files are given below:

/* Contents of x.c */
#include "x.h"
#include "y.h"
#include <stdio.h>

/*Contents of x.h */
#include "y.h"

/*Contents of y.h */
/* no include files here */

The output is for this example is shown in trackout. Notice the following formating features of the output that your program must mimic:

Tips


Last modified: Thu Oct 10 15:12:53 EDT 2002