makfile 中 $$ 变量的含义

原文地址:makfile 中 $$ 变量的含义 作者:lc0060305

例子:

dep:
    sed '/\#\#\# Dependencies/q' < Makefile > tmp_

dep:
    sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
    (for i in init/*.c;do echo -n "init/";$(CPP) -M $$i;done) >> tmp_make    #
    cp tmp_make Makefile
    (cd fs; make dep)
    (cd kernel; make dep)
    (cd mm; make dep)


其中的 $$i 好长时间让我无法理解,最近看到一个关于 makefile 的文档, 它的解释是这样的:

出现在规则命令行中 shell 变量(一般为执行命令过程中的临时变量,它不属于 Makefile 变量,而是一个 shell 变量)引用使用 shell 的“ $tmp ”格式。

这也就是说, 在
(for i in init/*.c;do echo -n "init/";$(CPP) -M $$i;done) >> tmp_make
中的 i 是一个 shell 临时变量。在 shell 是引用变量与makefile中引用变是一样也是用 $符。所以 $i也就代表的是一个 shell 对i变量的引用。

那么再在makefile中引用这个 shell变量,所以就成了 $($i)。而在makefile中可以将()去掉,最终就变成了 $$i.

希望对 $$i 这种方式迷惑的人有所帮助 :)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值