作为my question from a few years ago的后续,我目前正在将一个非常相似的项目从使用递归automake转换为单个非递归Makefile。这适用于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
目录中。
有关如何使这项工作或改进的任何建议?
答案 0 :(得分:2)
嗯,事实证明我需要改变两件事:
.tex
,.aux
和.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
规则中有它就足够了。