Pregunta

How to use multiple-line variable in recipe?

file-name: multiple-line-variable

define foo =
echo welcome
endef

export foo

all:
    echo $(foo)

I get following output. But i expect 'welcome' print.

$ make -f multiple-line-variable
echo 
¿Fue útil?

Solución

SunEric's answer didn't correctly explain what was happening. Adding, or not, the @ has absolutely zero to do with the reason you're not seeing "welcome" printed.

The reason your original example did not work as expected is because you're reading the GNU make manual for the latest version of GNU make (which is currently GNU make 4.0), probably using the online manual, but you're using a much older version of GNU make. This is not a good idea, because features discussed in the manual do not exist in the version of GNU make you're using.

In this case, the style of variable definition that adds the assignment operator after the name:

define foo =
  ...

is not available before GNU make 3.82. In versions of make before that, this syntax defines a variable named, literally, foo =. So printing $(foo) will not show anything because the variable foo is not defined.

GNU make provides its user manual as part of the distribution: you should always read the version of the manual that comes with the version of GNU make you're using, rather than some other version.

Also, you don't need to export the foo variable in either method, because you're using make syntax in your recipe so the shell never sees any reference to a foo variable.

Otros consejos

Try this,

define foo  
welcome
endef
export foo
all:
      @echo $(foo) // Change is here
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top