zoukankan      html  css  js  c++  java
  • GNU make manual 翻译( 一百五十四)

    继续翻译

    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.o
         program : $(objects)
                 cc -o program $(objects)
    
         $(objects) : defs.h
    
       Variable references work by strict textual substitution.  Thus, the
    rule
    
         foo = c
         prog.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::)。

    后文待续

  • 相关阅读:
    Luogu P4727 [HNOI2009]图的同构记数
    ARC 101 E
    JSOI2019 Round2 游记
    JSOI2019 Round1(十二省联考)游记
    Technocup 2019
    Codeforces Round #533 (Div. 2)比赛总结
    学习链接
    2018.12.29-2018.1.9安师大附中集训
    关于考试
    NOIP2018提高组 游记
  • 原文地址:https://www.cnblogs.com/gaojian/p/2710715.html
Copyright © 2011-2022 走看看