help-make
[Top][All Lists]
Advanced

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

Re: Some questions about make


From: Paul Smith
Subject: Re: Some questions about make
Date: Sun, 12 Jul 2009 15:17:24 -0400

On Fri, 2009-07-10 at 00:37 -0700, 雷 高 wrote:
> I am learning GNU make by the make manual. I have some questions about
> make:

You should be using the normal make help mailing list; sending email to
me directly just means it will take that much longer to get a response.

> 1. When a file doesn't exist as the prerequisite and can't be made by
> implicit rules,make will stop and output an error. But when the file
> doesn't exist as the target and the command for that rule can't create
> the file, such as “foo : ;echo hello”, the file is considered as
> existing files.My question is that how does make treat none existing
> files..

I don't understand this question.

> 2. Can I imagine that the rules in makefile descripte a dependence
> chain, the default goal is the top node of the chain. The make uses
> depth-first traversal to create the chain.
> For example:
> 
> a : a1 a2
>        command
> a1 : b1 b2
>        command
> a2 : c1 c2
>        command
> b1: d1
>        command
> c2: e1
>        command
> The depth-first traversal dependence chain is b1-b2-a1-c1-c2-a2-a.

Basically, except your forgot the prerequisites.  Make also checks those
to be sure they're up to date.  The full ordered list of targets checked
would be:

        d1-b1-b2-a1-c1-e1-c2-a2-a

Also note that if you enable parallel mode (make -jN) then, while make
will still check these in this order, they may not execute in that order
because some commands will run faster and some will run more slowly.

> 3. I want to know something about the expand of construct. In page 18
> of make manual, it says that "Expansion of deferren construct is not
> performed until either the construct appears later in an immediate
> context, or until the second phast". If a expansion construct appears
> in an immediate context, it is a immediate expansion construct and is
> not the deferred construct.

Not true.  A recursive variable:

        FOO = bar

is ALWAYS a deferred variable, in that the value is not computed when
the variable is set but instead when the variable is expanded.  It might
appear multiple times.  When it appears in an immediate context, it is
expanded there (as everything in an immediate context is).  But that
doesn't mean it's not deferred; it's still deferred because it can also
appear in deferred contexts and there, it is not expanded yet.

I think you might be confused, and thinking that when a recursive
variable is expanded the first time it's expanded for good and never
expanded again.  That's not how it works.  A recursive variable is
expanded EVERY TIME the variable is expanded.

For example, in this situation:

        FOO = foo
        X = $(FOO)
        Y := $(X)
        FOO = bar
        Z := $(X)

It's obvious that $(Y) has the value "foo".  But, $(Z) has the value
"bar", NOT "foo"; when $(X) was expanded for Y that didn't change the
value of X to be the expanded string "foo".  X always has the value
$(FOO), so depending on what the value of $(FOO) is when $(X) is
expanded the result will be different.

> I think the description in the manual is not suitable. The another
> question is that can I consider that the deferred constructs all
> expand in the second phase.

I'm not sure what you mean by "all".  Make never expands deferred
constructs until the moment they are needed.  If a deferred variable is
never needed during a particular invocation of make, then it will never
be expanded.

That means that, for example, if a rule is never run then the variables
used in the recipe will not be expanded.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.us
 "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]