vinoth kumar
vinoth kumar

Reputation: 323

How to use multiple-line variable

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 

Upvotes: 1

Views: 76

Answers (2)

MadScientist
MadScientist

Reputation: 100856

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.

Upvotes: 1

Sunil Bojanapally
Sunil Bojanapally

Reputation: 12658

Try this,

define foo  
welcome
endef
export foo
all:
      @echo $(foo) // Change is here

Upvotes: 0

Related Questions