help-make
[Top][All Lists]
Advanced

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

Re: #include in a C file


From: ali hagigat
Subject: Re: #include in a C file
Date: Sat, 4 Dec 2010 14:00:20 +0330

Thank you for the reply. When i was reading the section 4.13 of the
manual, first i learned that if we use -M option,  compiler will
generate some prerequisites for each #include of the C source file.
But then the manual talks about having one makefile for each C source
file. I am wondering what is the relationship of -M and having one
makefile for every C file?
-M is doing the job, it is creating some extra rules to show the
dependency of C file to the files it has included, so what is the role
of second technique?(having one makefile for each C source file) (This
technique also adds new rules to our makefile?)
That was my question......


On 12/1/10, Paul Smith <address@hidden> wrote:
> 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 deps.mk:
>
>       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:
>  http://www.gnu.org                      http://make.mad-scientist.net
>  "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]