我在Automake中有一个配方,如果用户发出make doc
或make htmldoc
,则可以选择构建文档 :
if DOXYGEN_AVAILABLE
docs html htmldoc html-doc:
$(DOXYGEN) Doxyfile -d DOXYGEN_PROCESSING
fi
根据{{1}}的结果在DOXYGEN_AVAILABLE
中设置 configure
。如果文档是内置的,将有一个目录AC_CHECK_PROGS
。该文档是可选的,可能缺少html-doc
。
如果存在html-doc
,我将没有文件列表。我不相信这将在html-doc
中起作用:
Makefile.am
使用Automake时,如何选择将文档安装到if DOXYGEN_AVAILABLE
docs html htmldoc html-doc:
$(DOXYGEN) Doxyfile -d DOXYGEN_PROCESSING
pkghtmldir_FILES += html-doc/
fi
?
答案 0 :(得分:0)
我首先建议您稍微改变一下逻辑。如果在无法使用Doxygen构建文件时可以不安装Doxygen文档,那么即使Doxygen 可用也不要安装它们。因此,使用--enable-docs
或--with-docs
或与configure
类似的选项来使程序包构建器表达是否应构建文档是合理的,无论哪种默认值都适合您。您还可以考虑将预构建的文档包含在您的软件包中,然后选择是否启用 re 构建它们。
然后,您仍然可以在无论如何都未请求文档时完全省略对Doxygen的检查,并在请求它们但Doxygen不可用(或过旧)时发出警告或错误。对于包装制造商而言,这应该不足为奇。至少,我不会那么令人惊讶。
不过,无论如何,最终还是归结为Automake条件。这是我在一个项目中处理几乎相同任务的方式的精简版本:
$(top_srcdir)/Makefile.am :
# An Automake conditional:
if make_docs
# The name of the target(s) that encompasses actually building the docs
doxygen_html_targets = dox-html
# My Doxyfile is built by the build system, and the docs also depend on some example
# sources, stylesheets, and other files provided by the package. All these are
# listed here, so that the docs are rebuilt if any of them change:
dox_deps = Doxyfile ...
# How to actually install the docs (a one-line make recipe). Covers also installing
# pre-built docs that I include in the package for convenience, though this example
# has most of the other plumbing for that removed.
#
# The chmod in the below command must ensure the target files writable
# in order to work around weirdness in the behavior of the "distcheck" target
# when not configured to rebuild docs.
html_install = test -d dox-html && html_dir=dox-html || html_dir=$(srcdir)/dox-html; \
$(MKDIR_P) $(DESTDIR)$(pkgdocdir); \
cp -pR $${html_dir} $(DESTDIR)$(pkgdocdir)/html; \
chmod -R u+w,go+rX $(DESTDIR)$(pkgdocdir)/html
else
doxygen_html_targets =
dox_deps =
html_install = :
endif
# The variable prerequisites of this rule are how the selection is made between
# building the docs and not building them:
html-local: $(doxygen_html_targets)
:
## This rule should not be necessary, but Automake seems otherwise to ignore the
## install-html-local rule, perhaps because there are no targets with an HTML
## primary.
install-data-local: install-html-local
# The variable recipe for this rule is how the selection is made between installing
# the docs and not installing them:
install-html-local:
$(html_install)
maintainer-clean-local:
$(RM) -rf dox-html
# This rule, when exercised, is what actually builds the docs:
dox-html: $(dox_deps)
$(RM) -rf dox-html
$(DOXYGEN) Doxyfile
这里要摘录的关键是,不仅可以将文件列表存储在make
变量中,而且可以通过Automake条件语句进行控制。您还可以存储要在先决条件列表中使用的任意目标的名称,甚至可以存储规则配方的文本,以改变所选规则的行为。