Makefile 生成依赖于目标的变量

Makefile 生成依赖于目标的变量,makefile,Makefile,我在make中有一个变量,它依赖于一个必须在设置变量之前构建的文件,有没有办法让它工作 parsable_file: dependancies commands to make parsable_file targets=$(shell parse_cmd parsable_file) $(targets): parsable_file command to make targets .phony: all all:$(targets) 如果我运行$make parsable_

我在make中有一个变量,它依赖于一个必须在设置变量之前构建的文件,有没有办法让它工作

parsable_file: dependancies
    commands to make parsable_file
targets=$(shell parse_cmd parsable_file)
$(targets): parsable_file
    command to make targets
.phony: all
all:$(targets)

如果我运行
$make parsable_file&&make all
这将起作用(我得到一个错误,
parse_cmd
找不到
parsable_file
但它起作用),但make all将不起作用。这有一个Make成语吗

在主makefile中包含的文件中设置变量,并在主makefile中包含如何构建它的规则(您已经拥有的规则应该可以)

我相信这会满足你的要求

有关此概念的更多详细信息,请参见和(从第一节链接)


另外,除非
parseable_file
具有独立于该
parse_cmd
调用的用法,否则应该可以同时进行创建和解析,只需一步使生成的makefile包含
$(targets)
的正确值即可。

谢谢,我想没有办法避免创建另一个文件?如果愿意,您可以在makefile的早期使用shell调用来创建文件(可能还有变量设置),但我不确定这是否更好(并且可以使用基于依赖关系的文件重新生成跟踪手册)。