linux - 生成文件: executing a multiline function not working

标签 linux makefile centos gnu-make

我有一个 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/

相关文章:

正则表达式 [[ :digit:]] showing a row with a letter between digits

makefile - 编译源子集时应用不同的标志

c++ - 中间目标文件抛出的对函数 c++ 的 undefined reference

linux - TZ(时区)在 "/etc/crontab"中不起作用

linux - Git Bash 与 Oracle VM VirtualBox

apache - trac 通知不发送电子邮件

c# - Windows 开发环境值得付出代价吗?

linux - linux中的作业调度

mysql - 无法远程连接到MySQL服务器

c++ - 根据 Cmake 中的条件包含目录