help-make
[Top][All Lists]
Advanced

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

Re: some question about automatic variables


From: Paul Smith
Subject: Re: some question about automatic variables
Date: Mon, 25 Apr 2011 15:53:02 -0400

On Tue, 2011-04-26 at 03:44 +0800, loody wrote:
> 2011/4/25 Paul Smith <address@hidden>:
> > On Mon, 2011-04-25 at 22:17 +0800, loody wrote:
> >> 1. There is a section, 10.5.3 Automatic Variables, which explain the
> >> meaning and usage of automatic variables.
> >> But I cannot find the usage of $< in the manual.
> >> Would anyone tell me where it is?
> >
> > It's right there, in that section:
> >
> it seems I look for quite older make document that I cannot find the
> explanation you mentioned.
> Now I found it in the latest one. :)

Hm.  I did a check and this part of the manual hasn't changed since
before 2002, which is the start of the current location of the manual.

> BTW, what is the "The name of the first prerequisite"
> suppose the rule is as below:
> $(obj)/%.o : $(src)/%.c
>     $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
> 
> every *.c file in $(src) will apply the rule one by one, right?
> if so, why we should emphasis the "first prerequisite"?

Because if you have multiple prerequisites, $< is just the first one.

For example if you say:

        foo.o : foo.c foo.h bar.h biz.h baz.h
                <compile>

then $< is set to "foo.c".

> Does that mean if we have such rule:
> $(obj)/%.o : $(src)/%.c $(src)/%.cpp
>     $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
> 
> the above recipe will only work for *.c files below $(src)?

That rule doesn't make sense.  Maybe you are thinking it's a shorthand
way to define two rules, one which builds .o's from .c's and another
which builds .o's from .cpp's?

It's not that.  There's no shorthand for that: you have to write two
rules.

What that rule means is that in order to build $(obj)/xxx.o, you must
have BOTH $(src)/xxx.c and $(src)/xxx.cpp and both are used to create
the single .o.  This is almost certainly not what you want.

In the rule you've shown yes, $< will be set to $(src)/xxx.c only.





reply via email to

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