继续翻译

6.1 Basics of Variable References
=================================To substitute a variable's value, write a dollar sign followed by the
name of the variable in parentheses or braces: either `$(foo)' or
`${foo}' is a valid reference to the variable `foo'.  This special
significance of `$' is why you must write `$$' to have the effect of a
single dollar sign in a file name or recipe.Variable references can be used in any context: targets,
prerequisites, recipes, most directives, and new variable values.  Here
is an example of a common case, where a variable holds the names of all
the object files in a program:objects = program.o foo.o utils.oprogram : $(objects)cc -o program $(objects)$(objects) : defs.hVariable references work by strict textual substitution.  Thus, the
rulefoo = cprog.o : prog.$(foo)$(foo)$(foo) -$(foo) prog.$(foo)could be used to compile a C program `prog.c'.  Since spaces before the
variable value are ignored in variable assignments, the value of `foo'
is precisely `c'.  (Don't actually write your makefiles this way!)A dollar sign followed by a character other than a dollar sign,
open-parenthesis or open-brace treats that single character as the
variable name.  Thus, you could reference the variable `x' with `$x'.
However, this practice is strongly discouraged, except in the case of
the automatic variables (*note Automatic Variables::).

6.1 变量参照的基本
=================================

为了替换一个变量的值,要写一个美元符号后面跟着括号或者大括号,里面是变量名成:或者$(foo) 或者 ${foo}是一个对变量 foo的有效参照。这个$的特殊重要性就是为什么你必须写 $$来在文件名或者片段中来代表$符号本身。

变量参照可以用在任何上下文中:目的,前提条件,片段,大多数的指令,还有几个变量值中。这里有一个一般情况的例子,此处变量持有在一个程序中的所有的目标文件名:

objects = program.o foo.o utils.o
program : $(objects)
cc -o program $(objects)

$(objects) : defs.h

变量参照采用严格的文本替换因此,下列规则

foo = c
prog.o : prog.$(foo)
$(foo)$(foo) -$(foo) prog.$(foo)

可以被用来编译一个C 程序 prog.c, 因为变量前的空格会被在变量赋值的时候被忽略,foo的值就是精确的c(当然,实际上不要像这样来写你的makefile)。

一个非美元符号,非开放括号或者非开放打括号前面有一个美元符号的,被当作一个变量对待。因此你你可以用$X来参照x,但是这个实践是强烈不推荐的。除了在自动变量的场合(*note Automatic Variables::)。

后文待续

本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/10/03/2710715.html,如需转载请自行联系原作者

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

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

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

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

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

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

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

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

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

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

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

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

    继续翻译 4.10 Multiple Targets in a Rule ===============================A rule with multiple targets is ...

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

    继续翻译 The only restriction on this sort of use of nested variable references is that they cannot spec ...

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

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

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

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

最新文章

  1. 计算机视觉(AI)的算法有哪些,具体都有哪些特点?
  2. print_r php encode,详细介绍PHP在调试时echo print() print_r() var_dump()的区别分享
  3. 支付业务流程图--扫码付
  4. windows10自动填充密码开机自动登陆
  5. mysql+sqlplus命令找不到_bash: sqlplus: command not found 解决方法
  6. C++11-long long
  7. 理解并实施:VRRP(200-120新增考点)
  8. javascript基本功
  9. 图片服务 - thumbor过滤器
  10. MyBatis使用MySQL存储过程
  11. 自己的本事比领导大,对自己有利还是有弊?
  12. TP框架控制器的空操作
  13. win2003系统自动登录两法
  14. LSTM 手动实现车牌识别 Pytorch代码
  15. ffmpeg【百度百科】
  16. Vue组件动态(异步)传值
  17. 设计模式 - 桥接模式 ( Bridge ) 平时用的少
  18. 计算机无线模块怎样关闭,台式机无线上网设置_台式电脑如何关闭WIFI?
  19. gin-binding参数效验
  20. 外星人做系统logo_外星人开机logo win10

热门文章

  1. python pandas DataFrame 修改数据
  2. python 字符串转字典,字典转字符串 Expecting property name enclosed in double quotes
  3. 决策树算法详解(2)
  4. 模型量化--TBN:Convolutional Neural Network with Ternary Inputs and Binary Weights
  5. 有方向的CNN--Oriented Response Networks
  6. rtk服务器协议,rtk的服务器ip地址
  7. @NotNull-JSR-303验证
  8. vim command(vim命令)
  9. 软件测试员,你该如何快速提高自己的测试技术?
  10. Python matplotlib 绘制散点图 还不收藏起来