Re: gmake $(eval()) question.

Pascal Bourguignon <[email protected]>
Newsgroups gmane.comp.gnu.utils
Organization Informatimago
Message-ID <[email protected]>
[email protected] writes:

> Hi,
>
> I have the following Makefile which demonstrates my problem:
>
> ---------Begin Makefile------------
> HI=$(eval HELLO=Hello)
>
> all:server client
>
> server:
> <tab>@echo "HELLO: $(HELLO)"
> <tab>@echo "HI: $(HI)"
>
> client:
> <tab>@echo "HELLO: $(HELLO)"
> <tab>@echo "HI: $(HI)"
> -----------End Makefile------------
>
> If I run gmake, I get this output:
> HELLO:
> HI:
> HELLO: Hello
> HI:
>
> This thing that puzzles me is why the first line only contains
> "HELLO:".  As per my understanding, it should be the same as line 3.

This is not possible. When it execute the first echo "HELLO:
$(HELLO)", $(HI) has not been evaluated yet, so HELLO is not a
variable defined yet.


> If I run "gmake server" or "gmake client", I get:
> HELLO:
> HI:
>
> Again, I think the first line of output should be "HELLO: Hello"

Impossible, as above.


> So can anyone explain why this is happening?  I am running gmake 3.81
> on Fedora Core 6.

info gmake

= is a textual definition. You can substitute all occurence of HI with
$(eval HELLO=Hello).  Your makefile is equivalent to:


---------Begin Makefile------------


all:server client

server:
    @echo "HELLO: $(HELLO)"
    @echo "HI: $(eval HELLO=Hello)"

client:
    @echo "HELLO: $(HELLO)"
    @echo "HI: $(eval HELLO=Hello)"
-----------End Makefile------------

So you see, there's no variable named HELLO defined before you execute
one of the echo HI lines.


In info gmake, you should be able to read about := which may do what you want.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.