当我运行一个目标时,Make 执行默认规则

问题描述 投票:0回答:1

我有以下文件结构: 文件结构

我有一个名为 thesis-proposal.tex 的文件,与另一个名为“chapters”的目录位于同一目录中,其中有我单独的章节文件(例如,introduction.tex 等)。在 thesis-proposal.tex 中,我包含了我的所有章节。现在我想要一个 Makefile,用它我可以编译整个提案或单个章节。我通过创建一个 temp-wrapper.tex 文件来编译单个章节,在其中编写编译所需的 LaTeX 行。

Makefile 如下所示:

# Variables
MAIN = thesis-proposal.tex
CHAPTER_DIR = chapters
OUTPUT_DIR = output
CHAPTER_OUT_DIR = $(OUTPUT_DIR)/$(CHAPTER_DIR)
CHAPTERS = $(wildcard $(CHAPTER_DIR)/*.tex)
LATEXMK = latexmk
TEMP_WRAPPER = temp_wrapper.tex

# Default target: build the full proposal
all: proposal

# Target to build the full proposal
proposal: $(MAIN) $(CHAPTERS)
    mkdir -p $(OUTPUT_DIR)
    $(LATEXMK) -pdf -output-directory=$(OUTPUT_DIR) -interaction=nonstopmode $(MAIN)
    $(LATEXMK) -pdf -output-directory=$(OUTPUT_DIR) -interaction=nonstopmode $(MAIN) # Run twice for references

# This is the rule you run to compile a specific chapter, using "make chapter=<chapter-name>"
chapter: $(CHAPTER_OUT_DIR)/$(chapter).pdf

# Rule to compile a specific chapter (using pattern matching)
$(CHAPTER_OUT_DIR)/%.pdf: $(CHAPTER_DIR)/$*.tex
    mkdir -p $(CHAPTER_OUT_DIR); \
    echo "\documentclass{article}" > $(TEMP_WRAPPER); \
    echo "\\\\begin{document}" >> $(TEMP_WRAPPER); \
    cat $(CHAPTER_DIR)/$*.tex >> $(TEMP_WRAPPER); \
    echo "\\\\end{document}" >> $(TEMP_WRAPPER); \
    $(LATEXMK) -pdf -jobname=$* -output-directory=$(CHAPTER_OUT_DIR) -interaction=nonstopmode $(TEMP_WRAPPER); \
    rm $(TEMP_WRAPPER)

# Clean up
clean:
    rm -rf $(OUTPUT_DIR)

.PHONY: all proposal chapter clean

为什么当我运行 make Chapter=introduction 时总是触发提案规则?

我遇到的问题是,当我运行 makeproposal 时,它按预期工作,但是当我运行 make Chapter=introduction 时,它仍然运行 makeproposal。有趣的是,当我注释掉提案规则时,我可以使用章节规则并获得预期的行为。我试图找出为什么会发生这种行为,但我失败了。

makefile latex pdflatex
1个回答
0
投票

您没有指定目标,这就是所有正在运行的原因。

尝试:

make chapter-output chapter
使用变量
chapter
的正确值运行章节脚本。

更多信息:https://stackoverflow.com/a/2826068/724039

© www.soinside.com 2019 - 2024. All rights reserved.