Makefile中有多个版本

时间:2015-03-19 09:20:22

标签: makefile

我正在尝试将Makefile放在一起编译一些文档。

我的Makefile中有三个单独的'jobs',我的问题是只处理了第一个作业。每个作业都可以单独工作,或者如果它们是文件中的第一个作业。

运行总体构建非常重要,就像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 $@


# 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

1 个答案:

答案 0 :(得分:1)

除非您指定目标,否则只会构建文件中的第一个目标。通常,您将目标all作为第一个目标,并将所有其他目标作为依赖项。这样,默认情况下将构建所有目标。所以一般来说,第一个目标应该是:

all : job1 job2 job3

我建议在您的情况下,应重命名两个all目标。重复的宏sourceoutputsources也必须是唯一的,否则会删除重复项。

相关问题