bug-make
[Top][All Lists]
Advanced

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

[bug #44308] combination of $(call ...) and $(value ...) functions


From: Christian Boos
Subject: [bug #44308] combination of $(call ...) and $(value ...) functions
Date: Sun, 22 Feb 2015 18:42:48 +0000
User-agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36

Follow-up Comment #4, bug #44308 (project make):

Your example reminded me similar constructions I use a lot in my own
Makefiles.

I use a technique which I call the eval/value style which allows me to
generate parametric Make code without having to deal with annoying levels of $
quoting.

Here's how I would write your example:
{{{

code = $(eval $(value code.mk))

define code.mk
x_$1 = some value
y_$1 = $(x_$1) append value
echo-$1: 1 := $1
echo-$1:
        @echo x = $(x_$1)
        @echo y = $(y_$1)
endef
$(call code,foo)
$(call code,bar)
all: echo-foo echo-bar

}}}

It then works as you expected.

Well, I actually won't recommend the `1 := $1` hack, use rather some
expressive name here ;-)

A better example:
{{{

x_foo = some FOO value
x_bar = some BAR value

code = $(eval $(value code.mk))

define code.mk
y_$1 = $(x_$(param)) append value
echo-$1: param := $1
echo-$1:
        @echo x = $(x_$(param))
        @echo y = $(y_$(param))
endef

$(call code,foo)
$(call code,bar)
all: echo-bar

}}}

Gives:
{{{
$ make all
x = some FOO value
y = some FOO value append value
x = some BAR value
y = some BAR value append value
}}}

That being said, you have to be extra careful about where you place your
numerical parameters.
If you don't want to rely on the fact that your `$(y_$1)` variable gets only
used within rules where `$(param)` is defined, then you should use an `:=`
assignment (e.g. `y_$1 := $(x_$1) append value`). 


So having a special kind of variable which would expand only the numerical
parameters like Paul suggested would avoid the need to think too hard about
what happens when that code is executed, as the parameters would no longer be
there at this point.

Since these variables would probably only be useful when defining Make code,
it wouldn't be a big limitation to reserve them to multiline variable
definition, something like:

{{{
defmacro code
x_$1 = some value
y_$1 = $(x_$1) append value
echo-$1:
        @echo x = $(x_$1)
        @echo y = $(y_$1)
endef
$(call code,foo)
$(call code,bar)
all: echo-foo echo-bar
}}}


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?44308>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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