+ -
当前位置:首页 → 问答吧 → 懂 Makefile 的同志进来下

懂 Makefile 的同志进来下

时间:2010-07-10

来源:互联网

本帖最后由 shi_wen_qiang 于 2010-07-10 12:10 编辑

#target1 target2 target3: $@_config
#   @echo "Build$@"

#target1_config target2_config target3_config:
#   @echo "$@"


target1 target2 target3:
    @make $@_config
    @echo "Build$@"

target1_config target2_config target3_config:
    @echo "$@"


上面的代码是我自己试验的.

(1) 上面用 '#' 注释掉的代码是不能 work 的
(2) 下面没有注释的代码是可以 work 的

大家能解释下为什么注释的代码不能 work ?

tks

作者: shi_wen_qiang   发布时间: 2010-07-10

It's very important that you recognize the limited scope in which
automatic variable values are available: they only have values within
the command script.  In particular, you cannot use them anywhere within
the target list of a rule; they have no value there and will expand to
the empty string.  Also, they cannot be accessed directly within the
prerequisite list of a rule.  A common mistake is attempting to use
`$@' within the prerequisites list; this will not work. However, there
is a special feature of GNU `make', secondary expansion (*note
Secondary Expansion:, which will allow automatic variable values to
be used in prerequisite lists.


这个问题挺有意思,以前没关注过,翻了半天手册。

作者: 帅绝人寰   发布时间: 2010-07-10

@是用来干吗?

作者: nhuczp   发布时间: 2010-07-10

可以写成:

target1 target2 target3: % : %_config
     @echo "Build$@"

作者: drangon   发布时间: 2010-07-10

回复 帅绝人寰


谢谢大家的回复.

原来很多东西在 manual 里面都可以找到.

作者: shi_wen_qiang   发布时间: 2010-07-10

是info手册,不是man手册。 GNU的东西, man手册基本都是小儿科, info才是王道。

ps, 推荐一个看info手册的利器:pinfo。

作者: 帅绝人寰   发布时间: 2010-07-10

只是了解一点,没写过复杂的mailefile,在此帮顶。。。

作者: surpass_li   发布时间: 2010-07-10

我想问一下,大家英文都那么好吗。 看成篇的英文资料都很轻松?

作者: peijue   发布时间: 2010-07-10