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: Sam Ravnborg
Subject: Re: #include in a C file
Date: Sun, 5 Dec 2010 15:00:05 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

On Sun, Dec 05, 2010 at 02:41:09PM +0330, ali hagigat wrote:
> Hello Sam, thank you to respond. I have copied part of the make manual:
> ---------------------------------------------------------------------------------
> 4.13 Generating Prerequisites Automatically
> This makes each ‘.d’ file depend on all the source and header files
> that the corresponding
> ‘.o’ file depends on. make then knows it must regenerate the
> prerequisites whenever any of
> the source or header files changes.
> ---------------------------------------------------------------------------------
> I guess you have the make manual. So if you read the section 4.13, you
> will face with those statements as I have copied above.
> My question is that when the source or header files changes what
> prerequisites will be generated??
> Would you please just read the section 4.13? I fear to copy the whole of it...

I think I got your point here.
the syntax for a rule is:

target: prerequisites
        command

The manual here refer to the "file of prerequisites" and not the prerequisite 
in the rule.
The following replacement for the sentance should make things more clear IMO:

- make then knows it must regenerate the prerequisites whenever any of the 
source or header files changes.
+ make then knows it must regenerate the file of prerequisites whenever any of 
the source or header files changes.
                                         ^^^^^^^
                                         added.

> My second question is that:
> cc -M will generate some extra rules for our original makefile, isn't
> it?
Yes.
> so why we need to write that implicit rule(%.d:%.c and sed....) to
> create a new makefile and then include it? We have the rules, GCC is
> generating them, the manual said so , but why the manual changes its
> word and start talking about creating a new makefile and including it
> inside our original makefile?

You seem to be rather confused on the subject here.
The intent here is to automatically generate the rules so you do not need
to update your Makefile each time you change your source code.

The format generated by for eaxmple "gcc -m" may not fit the need of your 
Makefile.
The make manual outline a way where you have the file of prerequisites 
regenerated on-demand.

You write in the above "We have the rules". But please realize that we do NOT 
have
the rule we require as the gcc generated rule do not mention the .d file.
This is why the manual suggest to use sed to add the .d file to the rule.

Try it out and see if it works as described. Sometimes a bit hands on really 
helps!

        Sam



reply via email to

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