[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to create "re-entrant" makefiles?
From: |
Paul Smith |
Subject: |
Re: How to create "re-entrant" makefiles? |
Date: |
Tue, 02 Jan 2007 21:13:22 -0500 |
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 $(address@hidden) > $@
all: $(MY_VAR)
Of course, you can use other automatic variables as necessary.
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> 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