将递归 makefile 变量导出到子 make
我需要导出用户定义的GNU make函数 (即 递归扩展的 makefile 变量)到子 make 。然而,make 似乎将所有这些变量扩展为简单的扩展变量,这使得它们毫无用处。
下面是一个示例:
Contents of "parent.make":
export myfunc = my arg is $1
$(info parent testing myfunc: $(call myfunc,parent))
all: ; $(MAKE) -f child.make
Contents of "child.make":
$(info child testing myfunc: $(call myfunc,child))
nullrule: ; @true
运行 "make -f Parent.make" 会产生以下输出:
parent testing myfunc: my arg is parent
make -f child.make
child testing myfunc: my arg is
Parent 将 myfunc 导出为包含“my arg is”的简单扩展变量子 make,使其作为一个函数毫无用处。
I need to export a user-defined GNU make function (i.e. a recursively expanded makefile variable) to a sub-make. However, make seems to expand all such variables into simply expanded variables, which makes them useless.
Here is an example:
Contents of "parent.make":
export myfunc = my arg is $1
$(info parent testing myfunc: $(call myfunc,parent))
all: ; $(MAKE) -f child.make
Contents of "child.make":
$(info child testing myfunc: $(call myfunc,child))
nullrule: ; @true
Running "make -f parent.make" produces the following output:
parent testing myfunc: my arg is parent
make -f child.make
child testing myfunc: my arg is
Parent exports myfunc as a simple expanded variable containing "my arg is" to the sub-make, making it useless as a function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是否有原因导致公共变量和函数不能放入父 makefile 和子 makefile 都包含的单独 makefile 中?
Is there a reason why common variables and functions can't be put into a separate makefile included by both the parent and the child makefiles?
我不确定这是否能满足您的要求,但这里是:
parent.make:
child.make:
编辑:
好吧,这样怎么样:
child.make:
编辑:
不太快。看看这个:
parent.make:
child.make:
grandchild.make:
这无需对
child.make
或grandchild.make
进行任何修改即可工作。它确实需要parent.make
调用myfunc_base
而不是myfunc
;如果这是一个问题,就有办法解决它,也许不止一种。一种可能性是,我们将定义向上移动到任何调用
parent
的地方,实际上根本不会调用它:grandparent.make:
parent.make:
我意识到这可能行不通,因为定义
myfunc
可能需要parent.make
中定义的其他内容。看看这是否适合您的情况;可能还有另一种方法...I'm not sure if this will satisfy your requirements, but here goes:
parent.make:
child.make:
EDIT:
All right, how about this:
child.make:
EDIT:
Not so fast. Take a look at this:
parent.make:
child.make:
grandchild.make:
This works with no modification at all to
child.make
orgrandchild.make
. It does require thatparent.make
callmyfunc_base
rather thanmyfunc
; if that's a problem there's a way around it, maybe more than one.One possibility, we move the definition up into whatever calls
parent
, where it won't actually be called at all:grandparent.make:
parent.make:
I realize this might not be workable, since the definition of
myfunc
might require other things defined inparent.make
. See if this will suit your situation; there may be another way...