用于将 Markdown 文件编译为单个 PDF 的 Makefile

Makefile for compiling Markdown files to a single PDF

当许多 Markdown 文件中的任何一个发生更改时,我正在尝试使用 Makefile 来编译 PDF:

# Compile report

source := draft
output := dist
sources := $(wildcard $(source)/*.md)
objects := $(patsubst %.md,%.pdf,$(subst$(source),$(output),$(sources)))
all: $(objects)

report-print.md: $(source)/%.md
    cat draft/*.md | pandoc \
        --variable geometry:a4paper \
        --number-sections \ 
        --toc \
        --f markdown \
        -s \
        -o dist/report-print.pdf \ 

.PHONY : clean

clean:
    rm -f $(output)/*.pdf

我收到一个错误:

make: *** No rule to make target `dist/01-title.pdf', needed by `all'.  Stop.

文件 draft/01-title.md 是源文件之一。

您没有从一个 .md 文件创建一个 .pdf 文件的规则。这很好,因为那不是你想做的。您想从 所有 .md 文件创建一个 pdf 文件(据我了解)。所以,抛弃所有 objects 东西;您不需要创建所有这些单独的 pdf 文件。

还有许多其他小问题:您没有创建与目标相同的文件名(report-print.md$(output)/report-print.pdf),您应该使用自动变量等)

您的 makefile 将只是:

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 \
            --f markdown \
            -s \
            -o $@

.PHONY : clean

clean:
        rm -f $(output)/*.pdf