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

    继续翻译

    6.3 Advanced Features for Reference to Variables
    ================================================
    
    This section describes some advanced features you can use to reference
    variables in more flexible ways.
    
    6.3.1 Substitution References
    -----------------------------
    
    A "substitution reference" substitutes the value of a variable with
    alterations that you specify.  It has the form `$(VAR:A=B)' (or
    `${VAR:A=B}') and its meaning is to take the value of the variable VAR,
    replace every A at the end of a word with B in that value, and
    substitute the resulting string.
    
       When we say "at the end of a word", we mean that A must appear
    either followed by whitespace or at the end of the value in order to be
    replaced; other occurrences of A in the value are unaltered.  For
    example:
    
         foo := a.o b.o c.o
         bar := $(foo:.o=.c)
    
    sets `bar' to `a.c b.c c.c'.  *Note Setting Variables: Setting.
    
       A substitution reference is actually an abbreviation for use of the
    `patsubst' expansion function (*note Functions for String Substitution
    and Analysis: Text Functions.).  We provide substitution references as
    well as `patsubst' for compatibility with other implementations of
    `make'.
    
       Another type of substitution reference lets you use the full power of
    the `patsubst' function.  It has the same form `$(VAR:A=B)' described
    above, except that now A must contain a single `%' character.  This
    case is equivalent to `$(patsubst A,B,$(VAR))'.  *Note Functions for
    String Substitution and Analysis: Text Functions, for a description of
    the `patsubst' function.
    
    For example:
    
         foo := a.o b.o c.o
         bar := $(foo:%.o=%.c)
    
    sets `bar' to `a.c b.c c.c'.

    6.3 变量参照的高级功能
    ================================================

    这一节描述你可以用来更加灵活地参照变量的高级功能。

    6.3.1 替换参照
    -----------------------------

    一个替换参照用你指定的变化,来替换一个变量的值。它的格式是 $(VAR: A=B) (或 ${VAR:A=B}),并且它的含义是把变量 VAR的值,在其中所有单词末尾A的值换成B的值,然后替换整个结果字符串。

    当我们说 在单词的末尾,我们指的是 A 必须出现在空格之后或则会再一个要替换的值得末尾;其他位置不处理,例如:

    foo := a.o b.o c.o
    bar := $(foo:.o=.c)

    设置 bar 的值为 a.c b.c c.c ,*Note Setting Variables:  Setting.

    一个替换参照实际上是patsubst 扩展函数的缩略词(*note Functions for String Substitution and Analysis: Text Functions.)。我们提供patsubst ,也提供替换参照是为了和其他版本make的兼容性。

    另一个类型的替换参照让你使用patsubst 函数的完整威力。它有着和 $(VAR:A=B) 一样的格式,除了现在A 必须包含一个单独的 %符号。这个场合下等同于 $(patsubst A,B,$(VAR))。 想要查看patsubst 函数的说明,参照 *Note Functions for String Substitution and Analysis: Text Functions.

    例如:

    foo := a.o b.o c.o
    bar := $(foo:%.o=%.c)

    把 `bar' 设置为 'a.c b.c c.c'.

    后文待续

  • 相关阅读:
    Javascript操作cookie
    上传文件-layui+ashx
    Mysql对查询结果添加序列号
    Maven详解
    解决 go iris ReadJSON 无法获取 json,并提示 unexpected end of JSON input 的错误
    Archlinux 最新安装方法 (2020.07.01-x86_64)之虚拟机 BIOS 安装
    Oracle APEX 发送邮件
    包管理Go module的使用
    Golang 解决 Iris 被墙的依赖包
    解决 Nginx 代理Apex慢的问题
  • 原文地址:https://www.cnblogs.com/gaojian/p/2710849.html
Copyright © 2011-2022 走看看