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 <[email protected]>          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


_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to