Makefile:执行多行功能不起作用

问题描述 投票:0回答:1

我的Makefile很少有常规目标。该makefile应该下载另一个makefile.include并将其包含在exec目标之前。我试图做到如下。但是它不起作用。

define get_file =
@echo "test echo" ;\
if [ -a ./Makefile.include ] ; \
then  \
    echo "Makefile.include present" ; \
else \
    curl -o Makefile.include https://www.blah.com/myfile ;\
fi;
endef

D := $(value get_file)

include Makefile.include

我试图以各种不同的方式执行get_file函数,但这是行不通的。我可以使它起作用的唯一方法是将函数放在另一个foo.sh中,然后执行以下操作。

D := $(shell bash -x foo.sh)

但是我希望将脚本保存在同一文件中。任何帮助表示赞赏。

linux makefile centos gnu-make
1个回答
0
投票

我认为您有一些小问题:

define get_file
echo "the parameter is: $1 - this could be the filename passed in"
if [ -a ./Makefile.include ] ; then \
    echo "Makefile.include present"; \
else \
    curl -o Makefile.include https://www.blah.com/myfile; \
fi
endef

多行定义不一定总是最后需要一个\,然后只需要其中的单个多行命令(如if语句)。另外,我认为您需要使用call而不是value make命令-例如使用(我添加了可以传递参数的示例-您可能不需要/不需要):

var := $(call get_file,some_parameter)

some_rule:
    @echo $(var)
© www.soinside.com 2019 - 2024. All rights reserved.