On Wed, 2007-01-03 at 01:48 +0000, David Wuertele wrote:

> MY_VAR := one
> include variabletest.mk
> 
> MY_VAR := two
> include variabletest.mk
> 
> variabletest.mk
> ---------------
> $(MY_VAR):
>       echo $(MY_VAR) > $(MY_VAR)
> 
> all: $(MY_VAR)

As Mike points out, target-specific variables are the new fancy way to
do what you want.  But, there are other ways as well... that I actually
prefer (althoug target-specific variables have more power so sometimes
you need them).

First, note that the situation above was _exactly_ why automatic
variables were created: use $@ in your rule and you're done:

  variabletest.mk
  ---------------
  $(MY_VAR):
          echo $@ > $@

  all: $(MY_VAR)

Other useful automatic variables are $< and $*; see the GNU make manual.
Of course, sometimes the value you want isn't directly derivable from
the target or prerequisites; in that case you can use constructed
variable names:

  variabletest.mk
  ---------------
  $(MY_VAR)_VALUE := foobar

  $(MY_VAR):
          echo $([EMAIL PROTECTED]) > $@

  all: $(MY_VAR)

Of course, you can use other automatic variables as necessary.

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


_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to