簡體   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