开发者

Append value to variable in make file

开发者 https://www.devze.com 2023-04-01 09:55 出处:网络
I have a definitions.mk file with some definitions: define some-method if [ ! -f <some file> ] ; then

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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消