• GNU make manual 翻译( 一百六十)


    继续翻译

    
    

    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

    后文待续

  • 相关阅读:
    fpm 打包教程
    fpm 打包工具安装调试
    kubernetes 容器挂载 ceph rbd 卷的平滑扩容方法
    kubernetes ceph-rbd挂载步骤 类型PersistentVolume
    ceph 块设备
    kubernetes 外部访问集群暴露端口服务
    kubernetes job的原理
    国内GIT托管服务
    Euclidean Space
    Struct Member Default Value
  • 原文地址:https://www.cnblogs.com/gaojian/p/2711261.html
Copyright © 2020-2023  润新知