Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Apr 2001 13:24:02 +0200 (CEST)
From:      edwin@mavetju.org
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   docs/26743: developers-handbook: makefiles and depend
Message-ID:  <20010421112402.BBD1D34C@cgmd76206.chello.nl>

next in thread | raw e-mail | index | archive | help

>Number:         26743
>Category:       docs
>Synopsis:       developers-handbook: makefiles and depend
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-doc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 21 04:30:01 PDT 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-doc" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010421112402.BBD1D34C>