From owner-freebsd-doc Sat Apr 21 4:30:13 2001 Delivered-To: freebsd-doc@freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 6AD2B37B424 for ; Sat, 21 Apr 2001 04:30:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f3LBU2X15138; Sat, 21 Apr 2001 04:30:02 -0700 (PDT) (envelope-from gnats) Received: from cgmd76206.chello.nl (d9168.upc-d.chello.nl [213.46.9.168]) by hub.freebsd.org (Postfix) with ESMTP id 630A837B422 for ; 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 X-Send-Pr-Version: 3.2 Subject: docs/26743: developers-handbook: makefiles and depend Sender: owner-freebsd-doc@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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 @@ + Make and include-files + + 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: + + + #include <stdio.h> +#include "foo.h" + +int main(.... + + To make sure that this file is recompiled the moment + foo.h is changed, you have to add it in + your Makefile: + + foo: foo.c foo.h + + 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. gcc + has an option to analyze your files and to produce a list + of include-files and their dependencies: . + + + If you add this to your Makefile: + + depend: + gcc -E -MM *.c > .depend + + and run make depend, the file + .depend will appear with a list of + object-files, C-files and the include-files: + + foo.o: foo.c foo.h + + If you change foo.h, next time + you run make all files depending on + foo.h will be recompiled. + + Don't forget to run make depend each + time you add an include-file to one of your files. + + + FreeBSD Makefiles 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