Shell – How to append some text to a variable in makefile

makeshellvariable

I have a Makefile. Somewhere in the makefile there is a variable defined:

FOO=hello

Later on I need to append some text to FOO's content. I tried it like this:

FOO=$(FOO)_world

I suggested that echo $(FOO) would output hello_world. Instead I get an error:

*** Recursive variable 'FOO' references itself (eventually).  Stop.

Using the += operator is no option, because this would add a space in between.

Best Answer

You need the := in place of the recursive =:

FOO := hello
FOO := $(FOO)_world
$(info FOO=$(FOO))

hello_world