一个 Makefile 中的多个构建
More than one build in a Makefile
我正在尝试整理一个 Makefile 来编译多个文件。
我的 Makefile 中有三个独立的 'jobs',我的问题是只处理了第一个作业。每个作业都独立运行,或者如果它们是文件中的第一个作业。
重要的是 运行 整个构建就像 make
一样简单,这样贡献文档的人就不必 fiddle 处理事情了。
如何完成所有三份工作运行?
# 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 $@
# 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 $@
.PHONY : clean
clean:
rm -f $(output)/*.pdf
-- 更新
根据以下答案,功能齐全的 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 $@
# 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 $@
.PHONY : clean all docs report
clean:
rm -f $(output)/*.pdf
除非您指定目标,否则只会构建文件中的第一个目标。按照惯例,您会将目标 all
作为第一个目标,将所有其他目标作为依赖项。这样所有目标都将默认构建。所以一般来说第一个目标应该是:
all : job1 job2 job3
我建议在您的情况下,应重命名两个 all
目标。重复的宏 source
、output
和 sources
也需要是唯一的或删除重复项。
我正在尝试整理一个 Makefile 来编译多个文件。
我的 Makefile 中有三个独立的 'jobs',我的问题是只处理了第一个作业。每个作业都独立运行,或者如果它们是文件中的第一个作业。
重要的是 运行 整个构建就像 make
一样简单,这样贡献文档的人就不必 fiddle 处理事情了。
如何完成所有三份工作运行?
# 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 $@
# 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 $@
.PHONY : clean
clean:
rm -f $(output)/*.pdf
-- 更新
根据以下答案,功能齐全的 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 $@
# 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 $@
.PHONY : clean all docs report
clean:
rm -f $(output)/*.pdf
除非您指定目标,否则只会构建文件中的第一个目标。按照惯例,您会将目标 all
作为第一个目标,将所有其他目标作为依赖项。这样所有目标都将默认构建。所以一般来说第一个目标应该是:
all : job1 job2 job3
我建议在您的情况下,应重命名两个 all
目标。重复的宏 source
、output
和 sources
也需要是唯一的或删除重复项。