如何使用Make改善$(call $(eval $(call)))范例? [英] how to improve $(call $(eval $(call))) paradigm in using Make?

查看:84
本文介绍了如何使用Make改善$(call $(eval $(call)))范例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为方便用户,我编写了通用的makefile和函数,因此它们自然应该具有最简单的接口.在定义函数时,我使用以下范例:

I write general makefiles and functions for users' convenience, so naturally they should have the simplest interfaces possible . When defining functions, I use this paradigm:

define FUNCTION
target: $1
endef

FUNCTION2 = $(eval $(call FUNCTION,$1))

现在,不要告诉他们这样做

Now, instead of telling them to do this

$(eval $(调用FUNCTION, argument ))

$(eval $(call FUNCTION,argument))

我可以告诉他们这样做

$(调用FUNCTION2,自变量)

更简单.

这一直很吸引人,直到有人决定使用 .EXPORT_ALL_VARIABLES ,这样我们的总代码(SSCCE)如下所示:

This worked like a charm until somebody decided to use .EXPORT_ALL_VARIABLES, so that we have the total code (SSCCE) look like this:

define FUNCTION
target: $1
endef

FUNCTION2 = $(eval $(call FUNCTION,$1))

.EXPORT_ALL_VARIABLES:

all:    
    echo OK

现在,当您 make 这样做时,您会得到:

Now when you make this, you get:

Makefile:5: *** prerequisites cannot be defined in recipes.  Stop.

好吧,我想这是因为配方 echo 子进程评估了变量" FUNCTION2 ,然后意外地将必备行放入了配方中.或类似的东西.

Well, I guess this is because the recipe echo subprocess evaluates the "variable" FUNCTION2, which then unexpectedly puts the prerequisite line into the recipe. Or something like that.

所以我的问题是,应该责怪谁?

So my question is, who is to blame?

我的范例是否有误,我不应该使用它,因为用户随后无法使用 .EXPORT_ALL_VARIABLES ?如果是这样,是否有办法解决问题,以便用户仍可以调用简单的 FUNCTION2 ?

Is my paradigm faulty and I should not be using it, because the users then cannot use .EXPORT_ALL_VARIABLES ? If so, is there a way to fix things, so that users can still call the simple FUNCTION2?

还是 .EXPORT_ALL_VARIABLES 是邪恶的功能,不应使用?

Or is .EXPORT_ALL_VARIABLES an evil feature and should not be used?

推荐答案

我个人认为 .EXPORT_ALL_VARIABLES 是一个邪恶的功能,不应使用.但是,我认为这值得对GNU make进行增强请求:扩展用于导出的变量时,它不应运行 eval .

My personal opinion is that .EXPORT_ALL_VARIABLES is an evil feature and should not be used. However, i think this is worth an enhancement request for GNU make: it shouldn't be running eval when expanding variables for export.

这篇关于如何使用Make改善$(call $(eval $(call)))范例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆