0
我試圖編譯一個Makefile來編譯一些文檔。Makefile中有多個內部版本
在我的Makefile中有三個獨立的'作業',我的問題是隻處理第一個作業。每個作業都是獨立工作的,或者它們是文件中的第一份工作。
運行整個構建非常重要,就像make
一樣簡單,因此貢獻文檔的人員不必擺弄東西。
如何讓所有三個工作都運行?
# Generate index
index.html: index.md
pandoc \
index.md \
-f markdown_github \
-t html5 \
-s \
-o index.html
# Generate background-writing documents
source := background-writing
output := dist
sources := $(wildcard $(source)/*.md)
objects := $(patsubst %.md,%.pdf,$(subst $(source),$(output),$(sources)))
all: $(objects)
$(output)/%.pdf: $(source)/%.md
pandoc \
--variable geometry:a4paper \
--number-sections \
-f markdown $< \
-s \
-o [email protected]
# Compile report
source := draft
output := dist
sources := $(wildcard $(source)/*.md)
all: $(output)/report-print.pdf
$(output)/report-print.pdf: $(sources)
cat $^ | pandoc \
--variable geometry:a4paper \
--number-sections \
--toc \
--from markdown \
-s \
-o [email protected]
.PHONY : clean
clean:
rm -f $(output)/*.pdf
- UPDATE
基於下面的答案,全功能的Makefile看起來是這樣的:
all: index.html docs report
# Generate index
index.html: index.md
pandoc \
index.md \
-f markdown_github \
-t html5 \
-s \
-o index.html
output := dist
# Generate background-writing documents
docsource := background-writing
docsources := $(wildcard $(docsource)/*.md)
objects := $(patsubst %.md,%.pdf,$(subst $(docsource),$(output),$(docsources)))
docs: $(objects)
$(output)/%.pdf: $(docsource)/%.md
pandoc \
--variable geometry:a4paper \
--number-sections \
-f markdown $< \
-s \
-o [email protected]
# Compile report
reportsource := draft
reportsources := $(wildcard $(reportsource)/*.md)
report: $(output)/report-print.pdf
$(output)/report-print.pdf: $(reportsources)
cat $^ | pandoc \
--variable geometry:a4paper \
--number-sections \
--toc \
--from markdown \
-s \
-o [email protected]
.PHONY : clean all docs report
clean:
rm -f $(output)/*.pdf
這通常是正確的,但有一些問題。首先也是最關鍵的,你從不在先決條件之間使用逗號;這會給你一個錯誤(例如,無法構建目標'index.html')。它應該是'all:index.html文檔報告'。其次,如果你有多個目標,比如'all',在makefile中有不同的先決條件;只要他們只有一個配方(在這種情況下,「全部」根本沒有任何配方,所以沒關係)。第三,因爲'all','docs'和'report'不是真正的目標,所以作者應該聲明它們爲'.PHONY'。 – MadScientist 2015-03-19 11:47:18
最後,您應該明確爲什麼作者的嘗試失敗:如果您沒有在命令行上提供任何目標,make的默認行爲是確保它在makefile中找到的_first_目標是最新的。在這個問題中,第一個目標是'index.html',所以這就是make的構建方式,除非你用'make report'來請求另外一個。所以,答案是創建一個像'all'這樣的目標,這取決於所有你想要默認建立的東西,並確保_that_是makefile中的第一個目標。然後'make'和'make all'是等價的。 – MadScientist 2015-03-19 11:51:03
我把你的建議寫入了Makefile,現在它正在工作。我在問題中包含了功能文件,以便其他人也可以從中學習。多謝你們。 – henrikstroem 2015-03-19 12:51:50