加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 如何在makefile中使用eval函数?

发布时间:2020-12-13 18:31:08 所属栏目:Linux 来源:网络整理
导读:在手册中: The eval function is very special: it allows you to define new makefile constructs that are not constant; which are the result of evaluating other variables and functions. The argument to the eval function is expanded,then the r
在手册中:

The eval function is very special: it allows you to define new
makefile constructs that are not constant; which are the result of
evaluating other variables and functions. The argument to the eval
function is expanded,then the results of that expansion are parsed as
makefile syntax.

It’s important to realize that the eval argument is expanded twice;
first by the eval function,then the results of that expansion are
expanded again when they are parsed as makefile syntax. This means you
may need to provide extra levels of escaping for “$” characters when
using eval.

“扩大两次”让我感到困惑.

例如,我创建一个makefile:

define func
    tmp = $(OBJPATH)/$(strip $1)
    objs += $$(tmp)
    $$(tmp) : $2
        gcc $$^ -o $$@
endef

all : foo

$(eval $(call func,foo,1.c))

如何扩展评估功能?

解决方法

理解它的最简单方法是用信息替换eval:
$(info $(call func,1.c))

这将显示第一次扩展的结果作为输出,因此您可以看到make将实际解析的内容.您没有提供OBJPATH变量的值,但如果它是obj,那么在您的情况下,第一个扩展(调用函数)会导致:

tmp = obj/foo
objs += $(tmp)
$(tmp) : 1.c
    gcc $^ -o $@

然后make解析器将对此进行评估,并在此过程中它将再次展开它,因此扩展了$(tmp)之类的东西.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读