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
后文待續
轉載于:https://www.cnblogs.com/gaojian/archive/2012/10/04/2711261.html
總結
以上是生活随笔為你收集整理的GNU make manual 翻译( 一百六十)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: visual studio 正则表达式
- 下一篇: FileLocator Pro:强大高效