makedepend

NAME

makedepend - create dependencies in makefiles

SYNOPSIS

makedepend [-Dname=def] [-Dname] [-Iincludedir]
		 [-a] [-fmakefile] [-oobjsuffix]
		 [-pobjprefix] [-sstring] [-wwidth]
		 [- -otheroptions - -]sourcefile ...

DESCRIPTION

The makedepend(1) utility reads each sourcefile in sequence and parses it like a C-preprocessor, processing all #include, #define, #undef, #ifdef, #ifndef, #endif, #if and #else directives so that it can determine which #include, directives would be used in a compilation. Any #include, directives can reference files having other #include directives, and parsing will occur in these files as well.

Every file that a sourcefile includes, directly or indirectly, makedepend(1) calls a "dependency". These dependencies are written to a makefile in such a way that make(1) will know which object files must be recompiled when a dependency has changed.

By default, makedepend(1) places its output in makefile if such a file exists. Otherwise, makedepend(1) places the output in Makefile. An alternate makefile can be specified with the -f option. The makedepend(1) utility first searches the makefile for the line:

# DO NOT DELETE THIS LINE -- make depend depends on it.
or one provided with the -s option, as a delimiter for the dependency output. If makedepend(1) finds such a line, it will delete everything following the line to the end of the makefile and put the output after this line. If makedepend(1) does not find such a line, the program will append the string to the end of the makefile and place the output after the string. For each sourcefile appearing on the command line, makedepend(1) puts lines in the makefile of the form:
 sourcefile.o: dfile ...

In this line, "sourcefile.o" is the name from the command line with its suffix replaced by ".o"; "dfile" is a dependency that was discovered in an #include directive while parsing sourcefile or one of the files it included.

EXAMPLE

Normally, makedepend(1) will be used in a makefile target so that typing "make depend" will bring the dependencies up-to-date for the makefile. For example,

SRCS = file1.c file2.c ...
CFLAGS = -O -DHACK -I../catdog -xyz
depend:
		makedepend -- $(CFLAGS) -- $(SRCS)

OPTIONS

The makedepend(1) utility will ignore any option that it does not understand so that you can use the same arguments that you would for cc(1).

-Dname=def
-Dname
Define. This places a definition for name in the makedepend(1) symbol table. Without =def, the symbol becomes defined as "1".
-Iincludedir
Include directory. This option tells makedepend(1) to prepend includedir to its list of directories to search when it encounters a #include directive. By default, makedepend(1) only searches $INTERIX_ROOT/usr/include.
-a
Append the dependencies to the end of the file instead of replacing them.
-fmakefile
File name. This allows you to specify an alternate makefile in which makedepend(1) can place its output.
-oobjsuffix
Object file suffix. Some systems can have object files with a suffix other than ".o". This option allows you to specify another suffix, such as ".b" with -o.b or ":obj" with -o:obj and so forth.
-pobjprefix
Object file prefix. The prefix is prepended to the name of the object file. This is usually used to designate a different directory for the object file. The default is the empty string.
-sstring
Starting string delimiter. This option permits you to specify a different string for makedepend(1) to look for in the makefile.
-wwidth
Line width. Normally, makedepend(1) ensures that every output line that it writes is no wider than 78 characters for the sake of readability. This option enables you to change this width.
-- options --
If makedepend(1) encounters a double hyphen (--) in the argument list, then any unrecognized argument following it will be silently ignored; a second double hyphen terminates this special treatment. In this way, makedepend(1) can be made to safely ignore esoteric compiler arguments that might normally be found in a CFLAGS make(1) macro (see the EXAMPLE section). All options that makedepend(1) recognizes and which appear between the pair of double hyphens are processed normally.

ALGORITHM

The approach used in this program enables it to run an order of magnitude faster than any other "dependency generator" I have ever seen. Central to this performance are two assumptions: that all files compiled by a single makefile will be compiled with roughly the same -I and -D options; and that most files in a single directory will include mostly the same files.

Given these assumptions, makedepend(1) expects to be called once for each makefile, with all source files that are maintained by the makefile appearing on the command line. It parses each source and include file exactly once, maintaining an internal symbol table for each. Thus, the first file on the command line will take an amount of time proportional to the amount of time that a normal C preprocessor takes. On subsequent files, however, if it encounters an include file that it has already parsed, it does not parse it again.

For example, imagine you are compiling two files, file1.c and file2.c. They each include the header file header.h, and the file header.h in turn includes the files def1.h and def2.h. When you run the command

makedepend file1.c file2.c
makedepend(1) will parse file1.c and consequently, header.h, and then def1.h and def2.h. It then decides that the dependencies for this file are
file1.o: header.h def1.h def2.h

But when the program parses file2.c and discovers that it, too, includes header.h, it does not parse the file, but simply adds header.h, def1.h and def2.h to the list of dependencies for file2.o

SEE ALSO

cc

make

BUGS

If you do not have the source for cpp(1), the Berkeley C preprocessor, makedepend(1) will be compiled in such a way that all #if directives will evaluate to "false" regardless of their actual value. This can cause the wrong #include directives to be evaluated. The makedepend(1) utility should simply have its own parser written for #if expressions.

Imagine you are parsing two files, file1.c and file2.c. Each includes the file def.h. The list of files that def.h includes might truly be different when def.h is included by file1.c from when it is included by file2.c But once makedepend(1) arrives at a list of dependencies for a file, it cannot be changed.

AUTHOR

Todd Brunhoff, Tektronix, Inc. and MIT Project Athena