Append value to variable in make file

16,689

You can't use a shell-style "if" statement in a Makefile. You need to use the GNU make conditional syntax.

Something like:

ifneq ($(wildcard some_file),)
# File exists
MYVAR += text_to_append
endif

Also, do not use tabs for indentation in your Makefile, they have special meaning to Make.

Share:
16,689
Liz
Author by

Liz

Updated on June 09, 2022

Comments

  • Liz
    Liz almost 2 years

    I have a definitions.mk file with some definitions:

    define some-method
    
    if [ ! -f <some file> ] ; then
        MYVAR += text_to_append
    

    It is the line with MYVAR that is my problem. It thinks MYVAR is a command. How can I make it realize that it is the variable MYVAR (which also exists in other make files) that I am referring to?

    Thanks in advance for any input!