C语言][Make]对makefile中 $+ 与 $^ 的理解

啥也别说了,上例子:

复制代码
foo: foo1.bar foo2.bar
    echo $+ 

foo1.bar: 
    echo "foo1"

foo2.bar: 
    echo "foo2"
复制代码
输出为:

foo1

foo2

foo1.bar foo2.bar  

改变为:

复制代码
foo: foo1.bar foo2.bar foo2.bar
    echo $+
    echo $^
foo1.bar:
    echo "foo1"

foo2.bar: 
    echo "foo2"

foo3.bar:
    echo "foo3"
复制代码
输出为:

foo1

foo2

foo1.bar foo2.bar foo2.bar

foo1.bar foo2.bar

也就是说,

对 $+而言,就是将 前提条件中的内容原样输出

对 $^ 而言,前提条件中的内容输出是,要过滤掉重复的部分。

复制代码
$^    The names of all the prerequisites, with spaces between them. For prerequisites which are archive members, only the member named is used (see Archives). A target has only one prerequisite on each other file it depends on, no matter how many times each file is listed as a prerequisite. So if you list a prerequisite more than once for a target, the value of $^ contains just one copy of the name. This list does not contain any of the order-only prerequisites; for those see the `$|' variable, below.

$+    This is like `$^', but prerequisites listed more than once are duplicated in the order they were listed in the makefile. This is primarily useful for use in linking commands where it is meaningful to repeat library file names in a particular order
复制代码
说法真的是很怪异,话让他们给倒过来说,很别扭。

其实不是 duplicated ,而是 $^ 作了点额外工作,清除了多余部分。

 后文待续 


本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/09/17/2688871.html,如需转载请自行联系原作者

上一篇:无限极分类


下一篇:[转]Embed WebView in Fragment