gpt4 book ai didi

makefile - 使用 GNU Make 将多行变量输出到文件

转载 作者:行者123 更新时间:2023-12-02 20:47:24 24 4
gpt4 key购买 nike

我很难编写在文件中输出多行变量的 makefile 规则。

这是我的代码:

define VAR1
/dev d 755 - - - - -
endef

define VAR2
/test d 777 - - - - -
/test2 d 777 - - - - -
endef

VARS += $(VAR1)
VARS += $(VAR2)

all:
echo "$(VARS)" > test

但是,由于我未知的原因,回显未能告知“未终止的引号字符串”。我怎样才能将文件中的每一行声明在单独的行上?

最佳答案

如果将变量导出到 shell 并将其作为 shell 变量而不是 make 变量引用,那么您的运气会更好:

define VAR1
/dev d 755 - - - - -
endef

define VAR2
/test d 777 - - - - -
/test2 d 777 - - - - -
endef

define VARS
$(VAR1)
$(VAR2)
endef
export VARS

all:
echo "$$VARS" > test

请注意对 makefile 的以下调整:

  • 我使用 define 来创建 VARS,而不是一系列 += 赋值,这样可以更轻松地在VAR1VAR2 的值。
  • 我将 export VARS 添加到您的 makefile 中,以将变量推送到 shell 调用的环境中。
  • 我使用 $$VARS 而不是 $(VARS) 来取消引用它——这将扩展留给 shell,而不是 make,这将避免“未终止的引号字符串”错误。

关于makefile - 使用 GNU Make 将多行变量输出到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7281395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com