help-make
[Top][All Lists]
Advanced

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

Re: Usage of "eval" inside if


From: Brian Dessent
Subject: Re: Usage of "eval" inside if
Date: Mon, 01 Dec 2008 21:53:25 -0800

kalyan wrote:

> define test_var
>         if [ 1 = 0 ];then \
>                 DUMMY=$(eval $(change_value)); \
>         fi; \
>         echo $(VAR)
> endef
> [...]
> I expected the output on my console to be 0 but i got 1 ?
> Any hints on what might be going wrong here are appreciated.

As the others have said make is performing exactly what is asked of it,
namely substituting variables found in the command before invoking it. 
Perhaps what is confusing you is that the $(eval) was in an 'if' clause
that is never true, so you expected it not to be evaluated.  But that is
an incorrect view of how make treats the contents of commands.

The list of commands (i.e. everything that begins with a TAB) might as
well be complete gibberish to make.  It is a payload which is shipped
off wholesale to the shell for execution.  Make has no comprehension[1]
of its semantics, except that before it sends it to the shell it expands
every $(variable) that it sees in the block.  It does not have any
notion of what that text might mean to the shell, it's just text.  It is
only after the shell has been invoked and make is out of the picture
that the 'if' has any meaning.

Brian

[1] This is not entirely true, as make does have an optimization whose
purpose is to detect whether the command is a simple invocation of one
program or whether the shell is in fact required to perform some
function like redirection or control flow.  But that's just an
optimization for speed, it doesn't change the fact that make doesn't
fundamentally understand anything of the semantics of what it's
invoking.




reply via email to

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