[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: #include in a C file

From: Paul Smith
Subject: Re: #include in a C file
Date: Wed, 01 Dec 2010 10:22:27 -0500

On Tue, 2010-11-30 at 11:54 +0330, ali hagigat wrote:
> If compiler generates the necessary prerequisites automatically by -M
> option why we need to have one makefile for each source file?

I don't understand the relationship between the first part of the
sentence and the second part.

The reason we recommend having one makefile per source file is that it's
very difficult to update the makefile with a new set of prerequisites
for a single file that's changed, if you concatenate them all together
into one big makefile.

If you have foo.c, bar.c, and baz.c and you write all the dependencies
into one makefile, say

        foo.o: foo.c foo.h bar.h
        bar.o: bar.c bar.h baz.h \
                stdio.h stdlib.h
        baz.o: baz.c bar.h foo.h baz.h

Now say you edit "bar.c" and so the build system wants to regenerate its
prerequisite list... it's a lot harder to write a rule to update just
those lines for "bar.o" in that combined makefile than it would be to
overwrite the entire contents of a single file "bar.deps" or whatever.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

[Prev in Thread] Current Thread [Next in Thread]