继续翻译

The only restriction on this sort of use of nested variable
references is that they cannot specify part of the name of a function
to be called. This is because the test for a recognized function name
is done before the expansion of nested references. For example,

ifdef do_sort
func := sort
else
func := strip
endif

bar := a d b g q c

foo := $($(func) $(bar))

attempts to give `foo' the value of the variable `sort a d b g q c' or
`strip a d b g q c', rather than giving `a d b g q c' as the argument
to either the `sort' or the `strip' function. This restriction could
be removed in the future if that change is shown to be a good idea.

You can also use computed variable names in the left-hand side of a
variable assignment, or in a `define' directive, as in:

dir = foo
$(dir)_sources := $(wildcard $(dir)/*.c)
define $(dir)_print =
lpr $($(dir)_sources)
endef

This example defines the variables `dir', `foo_sources', and
`foo_print'.

Note that "nested variable references" are quite different from
recursively expanded variables (*note The Two Flavors of Variables:
Flavors.), though both are used together in complex ways when doing
makefile programming.

 

对于这种对嵌套式变量参照使用的唯一的限制是他们不能指定一个要调用的函数名称的部分。这是因为对一个被认识的函数名称的测试已经在嵌套参照之前完成了。例如,

ifdef do_sort

  func := sort
else
  func := strip
endif

bar := a d b g q c

foo := $($(func) $(bar))

试图给出 `foo' 变量值为 `sort a d b g q c' 或 `strip a d b g q c', 而不是给出`a d b g q c' 作为 `sort' 或者 `strip' 函数的参数。如果未来考虑到改变此限制会更好,也许未来会进行改变。

你可以在一个变量赋值或define指令的左边得左边使用被计算的变量名,就像是这样:

dir = foo

$(dir)_sources := $(wildcard $(dir)/*.c)
define $(dir)_print =
lpr $($(dir)_sources)
endef

这个例子定义了变量 `dir', `foo_sources', 和`foo_print'。

要注意这个 "嵌套变量参照" 是和 递归式扩展变量很不一样的。(*note The Two Flavors of Variables: Flavors.) 尽管它们都在 makefile 编程时以复杂的方式进行使用。

这里我插入一句,

dir = foo

$(dir)_sources := $(wildcard $(dir)/*.c)

相当于 把  foo目录下的 所有的.c 文件名 获得后,赋值为 foo_sources

后文待续

转载于:https://www.cnblogs.com/gaojian/archive/2012/10/04/2711261.html

GNU make manual 翻译( 一百六十)相关推荐

  1. GNU make manual 翻译( 一百六十四)

    继续翻译 When you add to a variable's value with `+=', `make' acts essentially as if you had included th ...

  2. GNU make manual 翻译( 一百六十二)

    继续翻译 6.5 Setting Variables =====================To set a variable from the makefile, write a line st ...

  3. GNU make manual 翻译( 一百五十五)

    继续翻译 6.2 The Two Flavors of Variables ================================There are two ways that a vari ...

  4. GNU make manual 翻译( 一百二十四)

    继续翻译 Note that such a prerequisite constitutes mentioning `main.o' in a makefile, so it can never be ...

  5. GNU make manual 翻译( 一百五十四)

    继续翻译 6.1 Basics of Variable References =================================To substitute a variable's v ...

  6. GNU make manual 翻译( 一百五十九)

    继续翻译 A computed variable name need not consist entirely of a single variable reference. It can conta ...

  7. GNU make manual 翻译( 一百七十五)

    继续翻译 `.DEFAULT_GOAL' Sets the default goal to be used if no targets were specified onthe command lin ...

  8. GNU make manual 翻译( 一百八十二)

    继续翻译 `ifdef VARIABLE-NAME' The `ifdef' form takes the _name_ of a variable as its argument, not a re ...

  9. GNU make manual 翻译( 一百六十三)

    继续翻译 6.6 Appending More Text to Variables ====================================Often it is useful to ...

最新文章

  1. 使用slice和concat对数组的深拷贝和浅拷贝
  2. jsonp跨域ajax跨域get方法
  3. 【synchronized底层原理之4】锁的升级过程及比较
  4. 036_Unicode对照表二
  5. mysql 热切换_热备服务器中,切换master中切换SQL
  6. 惊呆了!这篇论文全文都是脏话,可编辑部居然对它评价极佳并发表了!
  7. python错误提示库没有注册_SpringBoot实现登录注册常见问题解决方案
  8. 4.7 什么是深度卷积网络?
  9. java 单例加锁方法的讨论
  10. Qt QTimer在线程的应用与思考
  11. mysql order by 自定义
  12. pycharm控制台打印时显示内容,不用省略号代替
  13. C语言错题锦集(持续更新)
  14. 新建网站的长尾词应该如何去做优化
  15. 做对了什么与留下了什么 小米上市的背后
  16. 磁力计校正和数据处理
  17. 大学生如何学习c语言!
  18. DNS NoteBook
  19. autocomplete触发事件_如何防止onSelect事件在DevBridge jQuery Autocomplete中触发两次
  20. 机器学习推导中常用的求导公式

热门文章

  1. 【NLP】语言模型和迁移学习
  2. Rails文件上传file_field报错Encoding::UndefinedConversionError
  3. 使用栈实现队列 Implement Queue using Stacks
  4. 《企业级ios应用开发实战》一2.2 iOS框架介绍
  5. Linux系统(五)负载均衡LVS集群之DR模式
  6. eclipse启动失败:An internal error occurred during: reload maven project
  7. CentOS 下安装xdebug
  8. Yii2.0 ActiveForm Input Fields
  9. leetcode1319. 连通网络的操作次数(并查集)
  10. leetcode1482. 制作 m 束花所需的最少天数(二分法)