Makefile 非递归自动生成和自定义后缀规则(用于LateX文档)
作为后续,我目前正在将一个非常类似的项目从使用递归自动生成转换为一个非递归生成文件。这对于C++源代码和检查来说是很好的。但是,在构建文档时(即运行PDFLaTeX将.tex文件转换为.pdf文件),我遇到了麻烦:Makefile 非递归自动生成和自定义后缀规则(用于LateX文档),makefile,latex,autoconf,automake,Makefile,Latex,Autoconf,Automake,作为后续,我目前正在将一个非常类似的项目从使用递归自动生成转换为一个非递归生成文件。这对于C++源代码和检查来说是很好的。但是,在构建文档时(即运行PDFLaTeX将.tex文件转换为.pdf文件),我遇到了麻烦:make工作正常,但是make distcheck失败,出现以下错误: make[1]: *** No rule to make target `doc//UserGuide.tex', needed by `doc//UserGuide.aux'. Stop. 目录结构如下: pr
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软件包):
在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的情况下可以正常工作):
我尝试将.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/
目录没有显示在\u build
目录中
有没有关于如何使这项工作起作用或改进它的建议?嗯,事实证明有两件事我需要改变:
.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\u p)
行,这只是为了确定。可能只在.tex.aux
规则中添加就足够了
make: *** No rule to make target `UserGuide.pdf', needed by `all-am'. Stop.
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: