<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC	'-//OASIS//DTD DocBook XML V4.1.2//EN'
								'http://docbook.org/docbook/xml/1.4/db3xml.dtd'>
<book id="fastdep-manual" lang="en">

<title>fastdep manual</title>

<bookinfo>
   <authorgroup>
		<author>
			<firstname>Bart</firstname>
			<surname>
				Vanhauwaert
			</surname>
			<affiliation>
				<address>
					<email>bvh-cplusplus@irule.be</email>
					<otheraddr>
						<ulink url="http://www.irule.be/bvh/">
							http://www.irule.be/bvh/
						</ulink>
					</otheraddr>
				</address>
			</affiliation>
		</author>
	</authorgroup>
	<revhistory>
		<revision>
			<revnumber>1</revnumber>
			<date>2002-10-28</date>
			<authorinitials>bvh</authorinitials>
			<revremark>Initial version</revremark>
		</revision>
	</revhistory>

	<legalnotice>
		<para>This document can be freely translated and distributed. 
		It is released·under the LDP License.</para>
	</legalnotice>

	<releaseinfo>
		I am not a native English speaker, nor an experienced
		documentation writer.
		Thus it should not come as a surprise to you if this text contains·
		typographical,
		grammatical or even simple spelling errors. To overcome this
		problem I am
		actively looking for help, suggestions or improvements to this document
		from my readers. If you are willing to do so, send email to
		<ulink url="mailto:bvh-cplusplus@irule.be">bvh-cplusplus@irule.be</ulink>·
		to make this guide a great resource
		for everyone trying to learn fastdep.
	</releaseinfo>
</bookinfo>

<chapter>
<title>About fastdep and this manual</title>

<para>
Fastdep generates dependency information for C of C++ files suitable
for inclusion in makefiles. There are two main advantages in using
it instead of the normal programs.</para>

<itemizedlist>
	<listitem>
		<para>It's fast due to a unique parse-once technology.</para>
	</listitem>
	<listitem>
		<para>It has special provision for robust dependency regeneration.</para>
	</listitem>
</itemizedlist>

<para>This manual assumes basic knowledge of make and the build process
for C or C++ programs.</para>

<para>
	I am not a native English speaker, nor an experienced
documentation writer.
Thus it should not come as a surprise to you if this text contains·
typographical,
grammatical or even simple spelling errors. To overcome this
problem I am
actively looking for help, suggestions or improvements to this document
from my readers. If you are willing to do so, send email to
<ulink url="mailto:bvh-cplusplus@irule.be">bvh-cplusplus@irule.be</ulink>·
to make this guide a great resource
for everyone trying to learn fastdep.
</para>

</chapter>

<chapter>
<title>Basic usage</title>

<para>The commandline synopsis for basic usage is</para>

<cmdsynopsis>
	<command>fastdep</command>
	<arg>--version</arg>
	<arg rep="repeat" choice="plain"><replaceable>sourcefile</replaceable></arg>
</cmdsynopsis>

<para><command>fastdep --version</command> will show version information
and a short copyright statement and exit immediatly.</para>

<para>To produce dependency information for two files
	named file1.cc and file2.cc, execute 
	<command>fastdep file1.cc file2.cc</command> from the shell.</para>

<para>The result will be written to standard output. For example 
it could be</para>

<screen>
file1.o: file1.cc \
	header1.h \
	header2.h \
	header3.h
file2.o: file2.cc \
	header1.h \
	header3.h \
	header4.h
</screen>

<para>To save the output, use your shell to redirect standard output 
	to a file which you can include in a makefile.
	</para>

</chapter>


<chapter>
<title>Writing a make-rule to generate dependency information</title>

<para>In general it is much more convenient to let your makefiles
	generate their own dependency information instead of doing it by hand
	as described in the previous chapter.</para>
	
<para>Let's say we have a variable in our makefile that lists all
	source files, <varname>SOURCES</varname>. We also want
	to save dependency information to a file named <filename>.depend</filename>.
	Here is how to write a make rule to accomplish just that.
</para>

<example>
	<title>Makefile fragment to generate dependencies from
		a number of sources</title>
	<programlisting>
.depend:
	fastdep $(SOURCES) > .depend

-include .depend
	</programlisting>
</example>

<para>It adds a new target <filename>.depend</filename>, 
	which is file to hold the dependency information generated by fastdep
	for all files listed in <varname>SOURCES</varname>. The fragment
also includes this file in the Makefile itself when it exist. If not
make will generate it first (using the rule
we specified), restart itself and include it next.</para>

<para>Now each time we want to regenerate dependencies, all we
	have to do is delete the <filename>.depend</filename> file and launch
	make.</para>

</chapter>


<chapter>
	<title>Automatically regenerating dependency information</title>

	<para>
Every time you change a dependency relationship (for example when
you include an extra header in some source file), you have to regenerate
the dependency information manually by executing
<command>make .depend</command>
(as mentioned in the previous chapter deleting <filename>.depend</filename>
also works)</para>

<para>Off course this is very error-prone. Why don't we let make regenerate
	the dependencies everytime one of the source files changes? Easy
	enough :</para>

<example>
	<title>Makefile fragment to generate dependencies each time a source
		file changes (wrong).</title>
<programlisting>
.depend: $(SOURCES)
	fastdep $(SOURCES) > .depend

-include .depend
</programlisting>
</example>

<para>This seems to work fine, but in fact doesn't. Suppose
	one (or more) of our source files in <varname>SOURCES</varname>
	includes a certain header <filename>foo.h</filename>. Now imagine
	that during an edit-compile cycle we don't change
	anything in the source files, but we added a new include
	of <filename>bar.h</filename> in <filename>foo.h</filename>.
	This means that the dependencies for each source file that
	includes <filename>foo.h</filename> must change. However since
	none of the source files themself change, make will find
	that <filename>.depend</filename> is still up to date
	and not regenerate it.
	The end result is incorrect dependency information.</para>

<para>To summarize, the dependency information of a source file
	not only depends on the source file itself, but also on all
	files it includes. Hence the earlier makefile fragment is
	incorrect.</para>

<para>To solve this problem, the info manual of GNU make proposes
	a solution where the output of the dependency generator is
	modified by piping it through sed. While this works for
	normal dependency generators like the GNU C/C++ compiler
	(and still works with fastdep), there is a much more elegant
	solution in <application>fastdep</application>.
	By adding the <command>--remakedeptarget=file</command>
	command line option fastdep will also emit a suitable
	dependency line for its own output.</para>

<example>
	<title>Makefile fragment to generate dependencies each time a source
		or included file changes (right).</title>
<programlisting>
.depend:
	fastdep --remakedeptarget=.depend $(ALLSOURCES) > .depend

-include dependinfo
</programlisting>
</example>
		
<para>The <filename>.depend</filename> file will now look like this : </para>

<screen>
file1.o: file1.cc \
	header1.h \
	header2.h \
	header3.h
file2.o: file2.cc \
	header1.h \
	header3.h \
	header4.h \
.depend: \
	file1.cc \
	header1.h \
	header2.h \
	header3.h \
	file2.cc \
	header4.h \
</screen>

<para>which is exactly how we want it to be.</para>
</chapter>

<chapter>
	<title>Adding an external dependency</title>

	<para>
Suppose you change your Makefile. For example you add -O2 to the CFLAGS
variable, because finally it's release time. Of course all object files
have to be regenerated. The classical way to do that is</para>

<screen>
make clean
make
</screen>

<para>But isn't it easier to let all .o files depend on the Makefile itself? 
	So that once you touch the makefile, all objects are immediatly out of
	date and thus regenerated.
	That's what the --extraremakedep= option is for.</para>

<example>
	<title>Adding an extra dependency to all targets</title>
<programlisting>
.depend:
	fastdep --extraremakedep=Makefile \
			  --remakedeptarget=.depend $(SOURCES) > .depend

-include .depend
</programlisting>
</example>

<para>Here is a possible result</para>

<screen>
file1.o: file1.cc \
	header1.h \
	header2.h \
	header3.h
file2.o: file2.cc \
	header1.h \
	header3.h \
	header4.h \
.depend: \
	file1.cc \
	header1.h \
	header2.h \
	header3.h \
	file2.cc \
	header4.h \
	Makefile
</screen>

</chapter>

<chapter>
	<title>Links and references</title>

	<variablelist>
		<varlistentry>
			<term>fastdep</term>
			<listitem><para>Homepage (news and download) : 
					<ulink url="http://www.irule.be/bvh/c++/fastdep/">http://www.irule.be/bvh/c++/fastdep/</ulink>
				</para>
			</listitem>
		</varlistentry>
		<varlistentry>
			<term>GNU compiler collection (gcc)</term>
			<listitem>
				<para>Homepage : 
					<ulink url="http://www.gnu.org/software/gcc/gcc.html">http://www.gnu.org/software/gcc/gcc.html</ulink></para>
				<para>Manual : 
					<ulink url="http://www.gnu.org/software/gcc/onlinedocs/">http://www.gnu.org/software/gcc/onlinedocs/</ulink>
				</para>
			</listitem>
		</varlistentry>
		<varlistentry>
			<term>GNU make</term>
			<listitem>
				<para>Homepage : 
					<ulink url="http://www.gnu.org/software/make/make.html">http://www.gnu.org/software/make/make.html</ulink></para>
				<para>Manual : 
					<ulink url="http://www.gnu.org/manual/make/html_chapter/make_toc.html">http://www.gnu.org/manual/make/html_chapter/make_toc.html</ulink>
				</para>
			</listitem>
		</varlistentry>
</variablelist>

</chapter>
</book>