Add some information about using "make depend" to help automatically

maintain dependencies between include files and source files.

PR:		docs/26743
Submitted by:	Edwin Groothuis <edwin@mavetju.org>
This commit is contained in:
Nik Clayton 2001-05-13 16:34:42 +00:00
parent 6895e948d5
commit 407706f4b8
Notes: svn2git 2020-12-08 03:00:23 +00:00
svn path=/head/; revision=9421
2 changed files with 100 additions and 2 deletions

View file

@ -1,7 +1,7 @@
<!--
The FreeBSD Documentation Project
$FreeBSD: doc/en_US.ISO_8859-1/books/developers-handbook/tools/chapter.sgml,v 1.3 2001/04/09 09:26:16 nik Exp $
$FreeBSD: doc/en_US.ISO_8859-1/books/developers-handbook/tools/chapter.sgml,v 1.4 2001/04/20 12:09:40 murray Exp $
-->
<chapter id="tools">
@ -1156,6 +1156,55 @@ install:
it.</para>
</sect2>
<sect2>
<title>Make and include-files</title>
<para>C code often starts with a list of files to include, for
example stdio.h. Some of these files are system-include
files, some of them are from the project you're now working
on:
</para>
<programlisting>#include &lt;stdio.h&gt;
#include "foo.h"
int main(....</programlisting>
<para>To make sure that this file is recompiled the moment
<filename>foo.h</filename> is changed, you have to add it in
your <filename>Makefile</filename>:</para>
<programlisting>foo: foo.c foo.h</programlisting>
<para>The moment your project is getting bigger and you have
more and more own include-files to maintain, it will be a
pain to keep track of all include files and the files which
are depending on it. If you change an include-file but
forget to recompile all the files which are depending on
it, the results will be devastating. <command>gcc</command>
has an option to analyze your files and to produce a list
of include-files and their dependencies: <option>-MM</option>.
</para>
<para>If you add this to your Makefile:</para>
<programlisting>depend:
gcc -E -MM *.c &gt; .depend</programlisting>
<para>and run <userinput>make depend</userinput>, the file
<filename>.depend</filename> will appear with a list of
object-files, C-files and the include-files:</para>
<programlisting>foo.o: foo.c foo.h</programlisting>
<para>If you change <filename>foo.h</filename>, next time
you run <command>make</command> all files depending on
<filename>foo.h</filename> will be recompiled.</para>
<para>Don't forget to run <command>make depend</command> each
time you add an include-file to one of your files.</para>
</sect2>
<sect2>
<title>FreeBSD Makefiles</title>

View file

@ -1,7 +1,7 @@
<!--
The FreeBSD Documentation Project
$FreeBSD: doc/en_US.ISO_8859-1/books/developers-handbook/tools/chapter.sgml,v 1.3 2001/04/09 09:26:16 nik Exp $
$FreeBSD: doc/en_US.ISO_8859-1/books/developers-handbook/tools/chapter.sgml,v 1.4 2001/04/20 12:09:40 murray Exp $
-->
<chapter id="tools">
@ -1156,6 +1156,55 @@ install:
it.</para>
</sect2>
<sect2>
<title>Make and include-files</title>
<para>C code often starts with a list of files to include, for
example stdio.h. Some of these files are system-include
files, some of them are from the project you're now working
on:
</para>
<programlisting>#include &lt;stdio.h&gt;
#include "foo.h"
int main(....</programlisting>
<para>To make sure that this file is recompiled the moment
<filename>foo.h</filename> is changed, you have to add it in
your <filename>Makefile</filename>:</para>
<programlisting>foo: foo.c foo.h</programlisting>
<para>The moment your project is getting bigger and you have
more and more own include-files to maintain, it will be a
pain to keep track of all include files and the files which
are depending on it. If you change an include-file but
forget to recompile all the files which are depending on
it, the results will be devastating. <command>gcc</command>
has an option to analyze your files and to produce a list
of include-files and their dependencies: <option>-MM</option>.
</para>
<para>If you add this to your Makefile:</para>
<programlisting>depend:
gcc -E -MM *.c &gt; .depend</programlisting>
<para>and run <userinput>make depend</userinput>, the file
<filename>.depend</filename> will appear with a list of
object-files, C-files and the include-files:</para>
<programlisting>foo.o: foo.c foo.h</programlisting>
<para>If you change <filename>foo.h</filename>, next time
you run <command>make</command> all files depending on
<filename>foo.h</filename> will be recompiled.</para>
<para>Don't forget to run <command>make depend</command> each
time you add an include-file to one of your files.</para>
</sect2>
<sect2>
<title>FreeBSD Makefiles</title>