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

前端之家收集整理的这篇文章主要介绍了linux – 如何在makefile中使用eval函数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在手册中:

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)之类的东西.

原文链接:https://www.f2er.com/linux/394611.html

猜你在找的Linux相关文章