[Top][All Lists]

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

Re: $i not working in $(word n, list)

From: Paul Smith
Subject: Re: $i not working in $(word n, list)
Date: Tue, 15 Nov 2011 08:42:08 -0500

On Tue, 2011-11-15 at 09:44 +0800, baumann Pan wrote:
> I want to use $(word ) and $(words) function to do sth.
> Makefile:
> all:
>     for (( i=0 ; i <= $(words a b c d e f) ; ++i )) ; do echo $$i ;
> echo $(word $$i, a b c d e f) ; done;
> the output is:
> makefile:2: *** non-numeric first argument to `word' function: '$i'.
> Stop.
> what's wrong with the line 2?

You have to fully grasp the idea that the shell (which runs the for
loop) is a completely separate process from make (which evaluates the
$(word ...) and $(words ...) functions).  You can't have control go back
and forth between them like this, where first you run some shell for
loop, then the iterator of that loop is somehow used internally by make
inside the shell loop.

That's fundamentally not possible.

The way make works is that the ENTIRE recipe script is first evaluated
by make, ONCE up-front.  Then the result of that evaluation is passed to
the shell ONCE.  Then make waits for the shell to finish.  Then the rule
is done.

So in your example above you get this error because make evaluates the
$(word ...) function before it invokes the shell and the count is "$i"
which is not a number.

Your example above is obviously contrived so I'm not going to attempt to
rewrite it; it would make no sense.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "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]