Recursion 将递归生成文件变量导出到子生成

Recursion 将递归生成文件变量导出到子生成,recursion,makefile,export,gnu-make,user-defined-functions,Recursion,Makefile,Export,Gnu Make,User Defined Functions,我需要出口(即)到子制造商。然而,make似乎将所有这些变量扩展为简单的扩展变量,这使得它们毫无用处 以下是一个例子: “parent.make”的内容: “child.make”的内容: 运行“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似乎将所有这些变量扩展为简单的扩展变量,这使得它们毫无用处

以下是一个例子:

“parent.make”的内容:

“child.make”的内容:

运行“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”的简单扩展变量导出到sub make,使其无法作为函数使用。

我不确定这是否满足您的要求,但下面是:

parent.make:

export myfunc = my arg is $1
$(info parent testing myfunc: $(call myfunc,parent))
all: ; $(MAKE) -f child.make
export myfunc1 = my arg is $1
export myfunc2 = $(value myfunc1)
$(info parent testing myfunc1: $(call myfunc1,parent))
all: ; $(MAKE) -f child.make
myfunc_base = my arg is $1

export myfunc = $(value myfunc_base)

$(info parent testing myfunc: $(call myfunc_base,parent))
all: ; @$(MAKE) -f child.make
myfunc_base = my arg is $1

export myfunc = $(value myfunc_base)

all: ; @$(MAKE) -f child.make
$(info parent testing myfunc: $(call myfunc,parent))
all: ; @$(MAKE) -f child.make
child.make:

$(info child testing myfunc: $(call myfunc,child))
nullrule: ; @true
$(info child testing myfunc2: $(call myfunc2,child))
nullrule: ; @true
myfunc1=$(myfunc2)

$(info child testing myfunc1: $(call myfunc1,child))
nullrule: ; @true
$(info child testing myfunc: $(call myfunc,child))
nullrule: ;  @$(MAKE) -f grandchild.make
$(info grandchild testing myfunc: $(call myfunc,grandchild))
nullrule: ; @true
编辑:
好吧,这个怎么样:

child.make:

$(info child testing myfunc: $(call myfunc,child))
nullrule: ; @true
$(info child testing myfunc2: $(call myfunc2,child))
nullrule: ; @true
myfunc1=$(myfunc2)

$(info child testing myfunc1: $(call myfunc1,child))
nullrule: ; @true
$(info child testing myfunc: $(call myfunc,child))
nullrule: ;  @$(MAKE) -f grandchild.make
$(info grandchild testing myfunc: $(call myfunc,grandchild))
nullrule: ; @true
编辑:

别那么快。看看这个:

parent.make:

export myfunc = my arg is $1
$(info parent testing myfunc: $(call myfunc,parent))
all: ; $(MAKE) -f child.make
export myfunc1 = my arg is $1
export myfunc2 = $(value myfunc1)
$(info parent testing myfunc1: $(call myfunc1,parent))
all: ; $(MAKE) -f child.make
myfunc_base = my arg is $1

export myfunc = $(value myfunc_base)

$(info parent testing myfunc: $(call myfunc_base,parent))
all: ; @$(MAKE) -f child.make
myfunc_base = my arg is $1

export myfunc = $(value myfunc_base)

all: ; @$(MAKE) -f child.make
$(info parent testing myfunc: $(call myfunc,parent))
all: ; @$(MAKE) -f child.make
child.make:

$(info child testing myfunc: $(call myfunc,child))
nullrule: ; @true
$(info child testing myfunc2: $(call myfunc2,child))
nullrule: ; @true
myfunc1=$(myfunc2)

$(info child testing myfunc1: $(call myfunc1,child))
nullrule: ; @true
$(info child testing myfunc: $(call myfunc,child))
nullrule: ;  @$(MAKE) -f grandchild.make
$(info grandchild testing myfunc: $(call myfunc,grandchild))
nullrule: ; @true
孙女:制作:

$(info child testing myfunc: $(call myfunc,child))
nullrule: ; @true
$(info child testing myfunc2: $(call myfunc2,child))
nullrule: ; @true
myfunc1=$(myfunc2)

$(info child testing myfunc1: $(call myfunc1,child))
nullrule: ; @true
$(info child testing myfunc: $(call myfunc,child))
nullrule: ;  @$(MAKE) -f grandchild.make
$(info grandchild testing myfunc: $(call myfunc,grandchild))
nullrule: ; @true
这对
子.make
孙.make
完全没有修改。它确实需要
parent.make
调用
myfunc\u base
而不是
myfunc
;如果这是一个问题,有办法解决,也许不止一个

一种可能性是,我们将定义向上移动到调用
parent
的任何地方,在那里它实际上根本不会被调用:

祖父母:制作:

export myfunc = my arg is $1
$(info parent testing myfunc: $(call myfunc,parent))
all: ; $(MAKE) -f child.make
export myfunc1 = my arg is $1
export myfunc2 = $(value myfunc1)
$(info parent testing myfunc1: $(call myfunc1,parent))
all: ; $(MAKE) -f child.make
myfunc_base = my arg is $1

export myfunc = $(value myfunc_base)

$(info parent testing myfunc: $(call myfunc_base,parent))
all: ; @$(MAKE) -f child.make
myfunc_base = my arg is $1

export myfunc = $(value myfunc_base)

all: ; @$(MAKE) -f child.make
$(info parent testing myfunc: $(call myfunc,parent))
all: ; @$(MAKE) -f child.make
parent.make:

export myfunc = my arg is $1
$(info parent testing myfunc: $(call myfunc,parent))
all: ; $(MAKE) -f child.make
export myfunc1 = my arg is $1
export myfunc2 = $(value myfunc1)
$(info parent testing myfunc1: $(call myfunc1,parent))
all: ; $(MAKE) -f child.make
myfunc_base = my arg is $1

export myfunc = $(value myfunc_base)

$(info parent testing myfunc: $(call myfunc_base,parent))
all: ; @$(MAKE) -f child.make
myfunc_base = my arg is $1

export myfunc = $(value myfunc_base)

all: ; @$(MAKE) -f child.make
$(info parent testing myfunc: $(call myfunc,parent))
all: ; @$(MAKE) -f child.make

我意识到这可能不可行,因为
myfunc
的定义可能需要在
parent.make
中定义其他内容。看看这是否适合你的情况;还有另一种方法……

为什么不能将公共变量和函数放入父级和子级makefile包含的单独makefile中?

这是一个巧妙的技巧。然而,它并不能真正解决我当前的问题,因为我需要父代和子代都能够使用相同的名称引用函数。(这是一个预先存在的、顽固的、庞大的、复杂的make设置)。我的回退选项是在单独的文件中定义这些函数,并为每个submake实例包含该文件,但这也不太理想。关于编辑,这并不实际。有很多函数,为每个函数添加两行额外的代码太冗长了。此外,还有多个级别的make运行子make,这使问题更加复杂。无论如何,我会接受你的回答,因为这似乎是唯一的选择!