Macro evaluation order in 3.79.1

2000-09-11 Thread jim . campbell

Hello,

Consider the following Makefile:

   clean: GOAL= clean

   ifneq ($(GOAL),clean)
   include foo.mk
   endif

   clean:
   echo $(GOAL)

If I type make clean, I would expect the Makefile to skip inclusion of
foo.mk.  However, it does not, and the make reaches an error.

I tried changing GOAL = to GOAL :=, but this did not help.

Is this by intention?  I noticed the same behavior in version 3.75.

If I do make GOAL=clean clean, the problem goes away.

- Jim
--
Jim Campbell
[EMAIL PROTECTED]
716/424-3560, x206 (direct)
716/424-4554, x206 (switchboard)




Re: Macro evaluation order in 3.79.1

2000-09-11 Thread jim . campbell


Yes, I made that change and it worked, even before I got your message.
Thank you for the clarification.

- Jim
--
Jim Campbell
[EMAIL PROTECTED]
716/424-3560, x206 (direct)
716/424-4554, x206 (switchboard)


   
  
"Paul D. Smith"
  
<[EMAIL PROTECTED]>   To: 
[EMAIL PROTECTED]  
Sent by: "Paul D.  cc: [EMAIL PROTECTED]
  
Smith" Subject: Re: Macro evaluation order 
in 3.79.1 
 
  
   
  
   
  
09/11/00 02:05 PM  
  
Please respond to  
  
"Paul D. Smith"
  
   
  
   
  



%% [EMAIL PROTECTED] writes:

  jc> Consider the following Makefile:

  jc>clean: GOAL= clean

  jc>ifneq ($(GOAL),clean)
  jc>include foo.mk
  jc>endif

  jc>clean:
  jc>echo $(GOAL)

  jc> If I type make clean, I would expect the Makefile to skip inclusion
of
  jc> foo.mk.

No.

You've assigned the variable GOAL with a target-specific variable.  That
means that the variable has that value _within the context of that
target_.  That is, when make is actually in the process of invoking that
target's commands.

The if-statement is evaluated while reading the makefile, long before
make even starts to build any targets, much less the clean target.  So,
the value of GOAL is empty.

Check the section on target-specific variables more carefully; this is
stated explicitly there.  Also helpful may be the chapter on `How `make'
Reads a Makefile'.

You want to use the builtin variable MAKECMDGOALS, and test that to see
if it's "clean".

--
---

 Paul D. Smith <[EMAIL PROTECTED]>  Find some GNU make tips at:
 http://www.gnu.org
http://www.paulandlesley.org/gmake/
 "Please remain calm...I may be mad, but I am a professional." --Mad
Scientist