.TH makedepend "" "" "X Utility"
.PC "Generate list of dependencies for a makefile"
.fi
\fBmakedepend
[\-D\fIname\^\fB=\fIdef\^\fB]
[\-D\fIname\^\fB]
[\-I\fIincludedir\^\fB]
[\-Y\fIincludedir\^\fB]
[\-a]
[\-f\fImakefile\^\fB]
[\-o\fIobjsuffix\^\fB]
[\-p\fIobjprefix\^\fB]
[\-s\fIstring\^\fB]
[\-w\fIwidth\^\fB]
[\-v]
[\-m]
[\-\^-\fIotheroption ...\fB\-\^\-]
\fIsourcefile ...\fR
.PP
.HS
.SH Options:
.IC "\fB\-D\fIsymbol\^\fB[=\fIdef\^\fB]\fR"
Define
.I symbol
within
.BR makedepend 's
internal symbol table
.IC \fB\-I\fIincludedir\fR
Tell
.B makedepend
to prefix
.I includedir
onto the list of directories to search when it encounters a
.B #include
directive
.IC \fB\-Y[\fIincludedir\^\fB]\fR
Search
.I includedir
for header files instead of all of the standard header-file directories
.IC \fB\-a\fR
Append the dependencies to the end of the file instead of replacing them
.IC \fB\-f\fIfile\fR
Write output into
.I file
instead of into
.B makefile
.IC \fB\-o\fIobjsuffix\fR
Append
.I objectsuffix
to a
.IR filename
instead of the default
.B .o
.IC \fB\-p\fIobjprefix\fR
Prefix the name of each object file with
.I objprefix
.IC \fB\-s\fIstring\fR
Use
.I string
as the starting-string delimiter within a
.B makefile
.IC \fB\-w\fIwidth\fR
Set the width of a line of output to
.I width
.IC \fB\-v\fR
Verbose operation
.IC \fB\-m\fR
Warn about multiple inclusion
.IC "\fB\-\^\- \fIoption ... \fB\-\^\-\fR"
.B makedepend
ignores every
.I option
that it does not recognize and that is bracketed by two hyphens `\-\^\-'
.HE
.B makedepend
reads each
.IR sourcefile ,
and parses it as the C preprocessor does.
It processes every
.BR #include ,
.BR #define ,
.BR #undef ,
.BR #ifdef ,
.BR #ifndef ,
.BR #endif ,
.BR #if ,
and
.B #else
directives so that it can correctly tell which
.B #include
directives should be used in a compilation.
Any
.B #include
directive can reference a file that has other
.B #include
directives, and
.B makedepend
parses these files as well.
.PP
Every file that a
.I sourcefile
includes, directly or indirectly, is what
.B makedepend
calls a
.IR dependency .
It writes these dependencies into a
.B makefile
in such a way that
.B make
will know which object files must be recompiled when a dependency has changed.
.PP
By default,
.B makedepend
writes its output into a file named
.BR makefile ,
if it exists; otherwise, it writes its output into
.BR Makefile .
You can specify an alternate makefile with the option
.BR \-f .
.B makedepend
first searches the makefile for the line
.DM
	# DO NOT DELETE THIS LINE -- make depend depends on it.
.DE
.PP
or one provided with the option
.B \-s
as a delimiter for the dependency output.
If it finds the line, it deletes everything
after after this line to the end of the makefile,
and writes its output after this line.
If
.B makedepend
does not find this line, it appends the string to the end of the makefile
and writes the output after that.
For each
.IR sourcefile ,
.B makedepend
writes into the makefile  a line of the form
.DM
	sourcefile.o: dfile ...
.DE
.PP
where
.B sourcefile.o
is the name of the
.I sourcefile
with its suffix replaced
.BR .o ,
and
.B dfile
is a dependency that
.B makedepend
discovered in a
.B #include
directive as it parsed
.I sourcefile
or one of the files it includes.
.SH "Command-line Options"
.B makedepend
ignores any option it does not understand, so you can use
the same arguments that you would for
.BR cc .
It does recognize the following command-line options:
.IP "\fB\-D\fIsymbol\^\fB[=\fIdef\^\fB]\fR"
Define
.I symbol
within
.BR makedepend 's
internal symbol table.
Without \fB=\fIdef\fR,
.B makedepend
defines it as
.BR 1 .
.IP \fB\-I\fIincludedir\fR
Tell
.B makedepend
to prefix
.I includedir
onto the list of directories to search when it encounters a
.B #include
directive.
By default,
.B makedepend
only searches only
.BR /usr/include .
.IP "\fB\-Y[\fIincludedir\^\fB]\fR"
Search
.I includedir
for header files instead of all of the standard header-file directories.
If you omit to name an
.IR includedir ,
this option prevents searching of the standard header-file directories.
.IP \fB\-a\fR
Append the dependencies to the end of the file instead of replacing them.
.IP \fB\-f\fIfile\fR
Write output into
.I file
instead of into
.BR makefile .
.IP \fB\-o\fIobjsuffix\fR
Append
.I objectsuffix
to a
.IR filename
instead of the default
.BR .o .
.IP \fB\-p\fIobjprefix\fR
Prefix the name of each object file with
.IR objprefix .
This usually is used to designate a different directory for the object file.
The default is the empty string.
.IP \fB\-s\fIstring\fR
Use
.I string
as the starting-string delimiter within a
.BR makefile .
.IP \fB\-w\fIwidth\fR
Set the width of a line of output to
.IR width .
By default,
.B makedepend
limits a line of output to 78 characters.
.IP \fB\-v\fR
Verbose:
tell
.B makedepend
to write onto the standard output the list of files that each
input file includes.
.IP \fB\-m\fR
Warn about multiple inclusion.
This option tells
.B makedepend
to warn if any input file includes another file more than once.
In previous versions of
.BR makedepend ,
this was the default behavior; the default has been changed to better
match the behavior of the C compiler, which does not consider multiple
inclusion to be an error.
This option is provided for backward 
compatibility, and to aid in debugging problems related to multiple
inclusion.
.IP "\fB\-\^\- \fIoption ... \fB\-\^\-\fR"
.B makedepend
ignores every
.I option
that it does not recognize and that is bracked by two hyphens `\-\^\-'.
In this way, you can safely tell
.B makedepend
to ignore esoteric compiler arguments that might normally be found in a
.B CFLAGS
macro.
.B makedepend
processes normally all options between the pair of double hyphens
that recognizes.
.SH Algorithm
To speed its performance,
.B makedepend
makes two assumptions about the programs whose dependency it is mapping:
first, that all files compiled by a single
.B makefile
will be compiled with roughly the same
.B \-I
and
.B \-D
options;
and second, that most files in a directory include largely the same files.
Given these assumptions,
.B makedepend
expects to be called once for each makefile, with all source files that that
.B makefile
maintains appearing on its command line.
.PP
.B makedepend
parses each source and header file exactly once,
and maintains 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.
However, on subsequent files, if
.B makedepend
encounters a header file that it has already parsed, it does not parse it again.
.PP
For example, imagine you are compiling two files,
.B file1.c
and
.BR file2.c .
Assume, further, that each includes the header file
.BR header.h ,
and
.B header.h
in turn includes the files
.B def1.h
and
.BR def2.h .
When you run the command
.DM
	makedepend file1.c file2.c
.DE
.PP
.B makedepend
parses
.B file1.c
and, therefore,
.B header.h
followed by
.B def1.h
and
.BR def2.h .
It then decides that the dependencies for this file are
.DM
	file1.o: header.h def1.h def2.h
.DE
.PP
When
.B makedepend
parses
.B file2.c
and discovers that it, too, includes
.BR header.h ,
it does not re-parse that file, but simply adds
.BR header.h ,
.BR def1.h ,
and
.B def2.h
to the list of dependencies for
.BR file2.o .
.SH Example
.B makedepend
normally is used within a
.B makefile
target, so that typing the command
.DM
	make depend
.DE
.PP
brings the dependencies up to date for the
.BR makefile .
For example,
.DM
	SRCS = file1.c file2.c ...
	CFLAGS = -O -DHACK -I../foobar -xyz
	depend:
        	makedepend -- $(CFLAGS) -- $(SRCS)
.DE
.SH "See Also"
.Xr "cc," cc
.Xr "commands," commands
.Xr "make" make
.br
X Windows Manual:
.B
imake
.R
.SH Notes
.\"If you do not have the source for
.\".BR cpp ,
.\" the Berkeley C preprocessor,
.\"then
.\".B makedepend
.\"will be compiled in such a way that all
.\".I #if
.\"directives will evaluate to "false" regardless of their actual value.
.\"This may cause the wrong
.\".I #include
.\"directives to be evaluated.
.\".B Makedepend
.\"should simply have its own parser written for
.\".I #if
.\"expressions.
.\".PP
.\"Imagine you are parsing two files,
.\"say
.\".I file1.c
.\"and
.\".I file2.c,
.\"each includes the file
.\".I def.h.
.\"The list of files that
.\".I def.h
.\"includes might truly be different when
.\".I def.h
.\"is included by
.\".I file1.c
.\"than when it is included by
.\".I file2.c.
.\"But once
.\".B makedepend
.\"arrives at a list of dependencies for a file,
.\"it is cast in concrete.
.II "Brunhoff, Todd"
.B makedepend
was written by Todd Brunhoff of Tektronix, Inc., and MIT Project Athena.
