我有一个 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)
但我更愿意将脚本保留在同一个文件中。任何帮助表示赞赏。
最佳答案
我认为您有一些小问题:
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
多行定义并不总是需要在末尾添加 \
,只需要 then 内的各个多行命令(如 if 语句)。另外,我认为您需要使用 call
而不是 value
make 命令 - 例如使用 like (我添加了您可以传入参数的示例 - 您可能不想要/不需要):
var := $(call get_file,some_parameter)
some_rule:
@echo $(var)
关于linux - 生成文件: executing a multiline function not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58740201/