如何使用多行变量 [英] How to use multiple-line variable

查看:133
本文介绍了如何使用多行变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在配方中使用多行变量?

How to use multiple-line variable in recipe?

文件名:多行变量

define foo =
echo welcome
endef

export foo

all:
    echo $(foo)

我得到以下输出.但我希望打印出欢迎"的字样.

I get following output. But i expect 'welcome' print.

$ make -f multiple-line-variable
echo 

推荐答案

SunEric的答案不能正确解释正在发生的事情.是否添加@绝对为零,与您没有看到欢迎"字样的原因有关.

SunEric's answer didn't correctly explain what was happening. Adding, or not, the @ has absolutely zero to do with the reason you're not seeing "welcome" printed.

您的原始示例未按预期运行的原因是,您正在使用在线手册阅读最新版本的GNU make的GNU make手册(当前为GNU make 4.0),但是您正在使用GNU make的较旧版本.这不是一个好主意,因为在您使用的GNU版本中不存在手册中讨论的功能.

The reason your original example did not work as expected is because you're reading the GNU make manual for the latest version of GNU make (which is currently GNU make 4.0), probably using the online manual, but you're using a much older version of GNU make. This is not a good idea, because features discussed in the manual do not exist in the version of GNU make you're using.

在这种情况下,变量定义的样式会在名称后添加赋值运算符:

In this case, the style of variable definition that adds the assignment operator after the name:

define foo =
  ...

在GNU make 3.82之前不可用.在此之前的make版本中,此语法定义了一个名为foo =的变量.因此,打印$(foo)不会显示任何内容,因为未定义变量foo.

is not available before GNU make 3.82. In versions of make before that, this syntax defines a variable named, literally, foo =. So printing $(foo) will not show anything because the variable foo is not defined.

GNU make提供了其用户手册作为发行版的一部分:您应该始终阅读所使用的GNU make版本附带的手册版本,而不是其他版本.

GNU make provides its user manual as part of the distribution: you should always read the version of the manual that comes with the version of GNU make you're using, rather than some other version.

此外,在任何一种方法中都不需要export foo变量,因为在配方中使用了make语法,因此外壳永远不会看到对foo变量的引用.

Also, you don't need to export the foo variable in either method, because you're using make syntax in your recipe so the shell never sees any reference to a foo variable.

这篇关于如何使用多行变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆