【问题标题】:Non-recursive Automake and custom suffix rules (for LateX documentation)非递归 Automake 和自定义后缀规则(用于 LateX 文档)
【发布时间】:2014-10-24 10:13:04
【问题描述】:

作为my question from a few years ago 的后续行动,我目前正在将一个非常相似的项目从使用递归自动生成转换为单个非递归生成文件。这适用于 C++ 源代码和检查。但是,在构建文档时(即运行 PDFLaTeX 将 .tex 文件转换为 .pdf 文件)我遇到了麻烦:make 工作正常,但 make distcheck 失败并出现以下错误:

make[1]: *** No rule to make target `doc//UserGuide.tex', needed by `doc//UserGuide.aux'. Stop.

目录结构如下:

project/
  |-- Makefile.am
  |-- configure.ac
  |-- src/            # containing all .cpp and .h files
  |-- doc/
       \-- UserGuide.tex

configure.ac 有一些代码来检测pdflatex 的存在并允许用户禁用编译文档(例如,如果没有安装某个 LaTeX 包):

# The user can disable building of the PDF of the manual, for example
# if the required LaTeX packages are not installed
AC_ARG_ENABLE([latex-doc],
    [AS_HELP_STRING([--disable-latex-doc], [disable building the PDF
    documentation from LaTeX source])],
    [latexdoc=no],
    [latexdoc=yes])

if test "x$latexdoc" = "xyes"; then
   AC_MSG_NOTICE([building of the PDF of the user manual from LaTeX source is enabled])
   # Check for presence of pdfLaTeX
   AC_CHECK_PROGS(PDFLATEX, pdflatex)
   if test -z "$PDFLATEX"; then
      AC_MSG_NOTICE([pdflatex not found - Unable to create PDF version of the user manual])
   fi
fi
AM_CONDITIONAL([HAVE_PDFLATEX], test -n "$PDFLATEX")
AM_CONDITIONAL([BUILD_latexdoc], test "x$latexdoc" = "xyes")

Makefile.am我定义了以下相关部分:

## Stuff needed for documentation in the doc/ directory
dist_doc_DATA = doc/howtocompile.txt doc/UserGuide.tex  \
 COPYING INSTALL ChangeLog AUTHORS

## Build the PDF documentation if building of the LaTeX docs is
## enabled via ./configure.
if BUILD_latexdoc
if HAVE_PDFLATEX
DOCDIR = doc/
MANNAME = $(DOCDIR)/UserGuide
MANPDF = $(MANNAME).pdf
MANTEXSRC = $(MANNAME).tex
MANAUX = $(MANNAME).aux
doc_DATA = $(MANPDF)
PDFLATEXOPTS = --output-directory=$(DOCDIR)

CLEANFILES += $(MANPDF) $(MANNAME).log $(MANNAME).idx $(MANNAME).out \
 $(MANNAME).toc $(MANNAME).idx $(MANNAME).ilg $(MANNAME).ind $(MANAUX) .btmp
endif
endif

问题很可能与我设置的自定义后缀规则有关(在递归 make 的情况下可以正常工作):

# Several make rules to generate the PDF from the LaTeX source
.aux.pdf:
    @echo === Making PDF: $@ from $^ ===
    $(PDFLATEX) $(PDFLATEXOPTS) $(srcdir)/$(MANTEXSRC)
    @while ( grep "Rerun to "           \
        $(MANNAME).log  ); do           \
        echo '** Re-running LaTeX **';      \
        $(PDFLATEX) $(PDFLATEXOPTS) $(srcdir)/$(MANTEXSRC); \
    done
    if [ -f $(MANNAME).idx ]; then \
        echo === Making index ===; \
        makeindex $(MANNAME); \
    fi
    @echo === Making final PDF ===
    $(PDFLATEX) $(PDFLATEXOPTS) $(srcdir)/$(MANTEXSRC)

.tex.aux:
    @echo === Making $@ file from $^ ===
    $(PDFLATEX) $(PDFLATEXOPTS) $(srcdir)/$(MANTEXSRC)
## Look for citations. Make sure grep never returns an error code.
    @grep "^\\\\citation" $(MANAUX) > .btmp.new || true
## If the citations are not changed, don't do anything. Otherwise replace
## the .btmp file to make sure BibTeX will be run.
    @if ( diff .btmp.new .btmp  > /dev/null ); then \
        rm .btmp.new; \
    else \
        mv .btmp.new .btmp; \
    fi

# A target needed to keep track of the nr. of LaTeX runs
.btmp:

我尝试将 .tex.aux 规则更改为 GNU Make 模式规则 (%.aux: $(srcdir)/%.tex),这似乎有效(尽管 Automake 警告这是一个 GNU Make 功能),但是当我尝试这样做时对于 .aux.pdf 规则,这不起作用,并给出以下错误消息:

make: *** No rule to make target `UserGuide.pdf', needed by `all-am'. Stop.

我的猜测是它与make distcheck 执行的VPATH 构建有关,因为doc/ 目录没有出现在_build 目录中。

关于如何使这项工作或改进它的任何建议?

【问题讨论】:

    标签: makefile latex autoconf automake


    【解决方案1】:

    好吧,事实证明我需要改变两件事:

    1. 在 SUFFIX 规则中明确提及扩展名 .tex.aux.pdf
    2. 告诉 Automake 创建 PDF 文档将结束的目标目录(在我的例子中是 $(DOCDIR) 变量。

    问题的最后一段代码现在是:

    SUFFIXES = .tex .aux .pdf
    # Several make rules to generate the PDF from the LaTeX source
    .aux.pdf:
        @echo === Making PDF: $@ from $^ ===
        $(MKDIR_P) $(DOCDIR)
        $(PDFLATEX) $(PDFLATEXOPTS) $(srcdir)/$(MANTEXSRC)
        @while ( grep "Rerun to "           \
            $(MANNAME).log  ); do           \
            echo '** Re-running LaTeX **';      \
            $(PDFLATEX) $(PDFLATEXOPTS) $(srcdir)/$(MANTEXSRC); \
        done
        if [ -f $(MANNAME).idx ]; then \
            echo === Making index ===; \
            makeindex $(MANNAME); \
        fi
        @echo === Making final PDF ===
        $(PDFLATEX) $(PDFLATEXOPTS) $(srcdir)/$(MANTEXSRC)
    
    .tex.aux:
        @echo === Making $@ file from $^ ===
        $(MKDIR_P) $(DOCDIR)
        $(PDFLATEX) $(PDFLATEXOPTS) $(srcdir)/$(MANTEXSRC)
    ## Look for citations. Make sure grep never returns an error code.
        @grep "^\\\\citation" $(MANAUX) > .btmp.new || true
    ## If the citations are not changed, don't do anything. Otherwise replace
    ## the .btmp file to make sure BibTeX will be run.
        @if ( diff .btmp.new .btmp  > /dev/null ); then \
            rm .btmp.new; \
        else \
            mv .btmp.new .btmp; \
        fi
    
    # A target needed to keep track of the nr. of LaTeX runs
    .btmp:
    

    我已将$(MKDIR_P) 行添加到两个后缀规则中,以确保这一点。可能只在.tex.aux 规则中就足够了。

    【讨论】:

      猜你喜欢
      • 2023-03-05
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      相关资源
      最近更新 更多