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!
makefile Variables Appending Text To an Existing Variable The += operator is a common extension that adds the specified content to the end of the variable, separated by a space. Variable references in the right-hand side will be expanded if and only if the original variable was defined as a simply-expanded variable.
+= is used for appending more text to variables e.g. objects=main.o foo.o bar.o. objects+=new.o. which will set objects to 'main.o foo.o bar.o new.o' = is for recursively expanded variable.
The ifeq directive begins the conditional, and specifies the condition. It contains two arguments, separated by a comma and surrounded by parentheses. Variable substitution is performed on both arguments and then they are compared.
In python, to append a string in python we will use the ” + ” operator and it will append the variable to the existing string.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With