From edwin@cgmd76206.chello.nl  Sat Apr 21 04:24:05 2001
Return-Path: <edwin@cgmd76206.chello.nl>
Received: from cgmd76206.chello.nl (d9168.upc-d.chello.nl [213.46.9.168])
	by hub.freebsd.org (Postfix) with ESMTP id 630A837B422
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 21 Apr 2001 04:24:04 -0700 (PDT)
	(envelope-from edwin@cgmd76206.chello.nl)
Received: by cgmd76206.chello.nl (Postfix, from userid 1001)
	id BBD1D34C; Sat, 21 Apr 2001 13:24:02 +0200 (CEST)
Message-Id: <20010421112402.BBD1D34C@cgmd76206.chello.nl>
Date: Sat, 21 Apr 2001 13:24:02 +0200 (CEST)
From: edwin@mavetju.org
Reply-To: edwin@mavetju.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: developers-handbook: makefiles and depend
X-Send-Pr-Version: 3.2

>Number:         26743
>Category:       docs
>Synopsis:       developers-handbook: makefiles and depend
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-doc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 21 04:30:01 PDT 2001
>Closed-Date:    Sun May 13 09:34:49 PDT 2001
>Last-Modified:  Sun May 13 09:35:00 PDT 2001
>Originator:     Edwin Groothuis
>Release:        FreeBSD 4.2-RELEASE i386
>Organization:
-
>Environment:

$FreeBSD: doc/en_US.ISO_8859-1/books/developers-handbook/tools/chapter.sgml,v 1.3 2001/04/09 09:26:16 nik Exp $

>Description:

My experience on mailing-lists is that people not fully understand
that if you change an include-file you also should recompile the
C-file. To prevent makefiles from growing larger and unmaintainable,
gcc has the option to create dependancies automaticly. This text
informs people about the traps you could fall into if you're not
carefully maintaining your include-file dependancies and on how to
prevent this from happening.

>How-To-Repeat:

n/a

>Fix:


--- chapter.sgml.old	Fri Apr 20 14:50:17 2001
+++ chapter.sgml	Sat Apr 21 13:15:35 2001
@@ -1146,6 +1146,55 @@
     </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>
 
       <para>Makefiles can be rather complicated to write.  Fortunately,

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: nik 
State-Changed-When: Sun May 13 09:34:49 PDT 2001 
State-Changed-Why:  
Committed, thanks. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=26743 
>Unformatted:
