zoukankan      html  css  js  c++  java
  • 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

    后文待续

  • 相关阅读:
    leetcode 122. Best Time to Buy and Sell Stock II
    leetcode 121. Best Time to Buy and Sell Stock
    python 集合(set)和字典(dictionary)的用法解析
    leetcode 53. Maximum Subarray
    leetcode 202. Happy Number
    leetcode 136.Single Number
    leetcode 703. Kth Largest Element in a Stream & c++ priority_queue & minHeap/maxHeap
    [leetcode]1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree
    正则表达式
    十种排序算法
  • 原文地址:https://www.cnblogs.com/gaojian/p/2711261.html
Copyright © 2011-2022 走看看