繁体   English   中英

Makefile:即使存在目标和依赖项也没有目标错误

[英]Makefile: no target error even when target and dependency exist

我的 makefile:

./corpus/%.spacy : ./assets/%.json
     python3 ./scripts/convert.py $< $@

两个问题:

  1. 即使存在 A.spacy 和 A.json 并且 A.json 比 A.spacy 最近更新,我得到以下 output。

     $ make $ make: *** No targets. Stop.
  2. 如果只有 A.json 存在,要添加什么让它制作 A.spacy? 我尝试了下面的代码,但没有成功,我觉得我没有完全理解 makefile 中的目标和依赖关系。

     convert: ./corpus/%.spacy python3./scripts/convert.py $(./scripts/$*.json) $<./corpus/%.spacy: ./assets/%.json echo $?

没有工作,因为给出了以下 output

$ make convert
$ make: *** No rule to make target `corpus/%.spacy', needed by `convert'.  Stop.

您似乎在想,声明一个模式规则会导致 go 在您的目录中寻找使用该模式的所有可能方法,就好像它是通配符或类似于ls *.spacy的东西。

这不是模式规则。

模式规则是一个模板如果它想要构建给定的目标并且它不知道如何构建该目标,则可以应用它。

如果你有上面的 makefile 它只是告诉 make “嘿,如果你碰巧想要创建一个与模式匹配的目标./corpus/%.spacy那么这是一种方法”。 如果您键入make时没有 arguments,那么您还没有告诉 make 您要构建任何东西,因此它不会使用您的模式规则。

如果您键入:

$ make ./corpus/A.spacy

现在你已经告诉 make 你想要实际构建一些东西( ./corpus/A.spacy ),所以现在 make 将尝试构建那个东西,它会看到你的模式规则并尝试使用它。

至于另一个,这个:

convert : ./corpus/%.spacy
        python3 ./scripts/convert.py $(./scripts/$*.json) $<

不是模式规则。 模式规则的目标中必须有模式字符 ( % ); 这是定义一个目标convert ,它依赖于一个明确命名为./corpus/%.spacy的文件,您没有任何具有该名称的文件,因此您会收到该错误。

你实际上并没有描述你想做什么,但我也许你想做这样的事情:

# Find all the .json files
JSONS := $(wildcard ./corpus/*.json)

# Now figure out all the output files we want
SPACYS := $(patsubst ./corpus/%.json,./corpus/%.spacy,$(JSONS))

# Now create a target that depends on the stuff we want to create
all: $(SPACYS)

# And here's a pattern that tells make how to create ONE spacy file:
./corpus/%.spacy : ./assets/%.json
        python3 ./scripts/convert.py $< $@

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM