GNU autotools 项目中与生成手册相关的“make distcheck”问题

GNU autotools 项目中与生成手册相关的“make distcheck”问题

我正在使用autoconfautomake构建一个小项目。

对于项目手册,我使用了 OpenBSD 的本机mdoc格式,并man使用此生成可安装格式的手册实用mandoc程序。 - 格式的手册man将作为实际手册安装make install,因为某些系统无法mdoc正确理解或根本无法理解。

在项目的doc目录中,我有一个Makefile.am当前如下所示的文件(该手册适用于名为 的实用程序shell):

dist_man1_MANS= shell.man
EXTRA_DIST=     shell.mdoc

shell.man:      shell.mdoc
        $(mandoc) -T man shell.mdoc >shell.man

$(mandoc)将被正确扩展为格式化程序的完整路径mandoc(该变量由脚本设置configure)。

这允许我运行make dist它创建shell.man然后创建一个压缩tar存档,其中包含源mdoc手册和生成的man手册以及项目分发文件的其余部分:

$ tar tzf shell-toolbox-20180401.tar.gz
...
shell-toolbox-20180401/doc/Makefile.am
shell-toolbox-20180401/doc/shell.man
shell-toolbox-20180401/doc/Makefile.in
shell-toolbox-20180401/doc/shell.mdoc

tar存档稍后可用于成功构建和安装项目及其手册。到目前为止,一切都很好。

但是,如果我跑make distcheck(因为我想确保它绝对有效):

$ make distcheck
...
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/local/bin/gmkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for mandoc... /usr/bin/mandoc
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating doc/Makefile
config.status: creating src/shell
Making all in src
Making all in doc
/usr/bin/mandoc -T man shell.mdoc >shell.man
mandoc: shell.mdoc: ERROR: No such file or directory
*** Error 3 in shell-toolbox-20180401/_build/sub/doc (Makefile:459 'shell.man')
*** Error 1 in shell-toolbox-20180401/_build/sub (Makefile:345 'all-recursive')
*** Error 1 in /home/myself/local/build/shell-toolbox (Makefile:576 'distcheck')

mdoc当需要构建手册时,构建目录中似乎没有源文件:

$ ls shell-toolbox-20180401/_build/sub/doc
total 32
-rw-r--r--  1 myself  myself  14989 Apr  1 21:35 Makefile
-rw-r--r--  1 myself  myself      0 Apr  1 21:35 shell.man

零长度shell.man文件来自失败的mandoc运行。

源代码可在解压的存档中找到,但只是未复制到_build/sub/doc目录中:

$ ls -l shell-toolbox-20180401/doc
total 48
-r--r--r--  1 myself  myself   178 Apr  1 21:23 Makefile.am
-r--r--r--  1 myself  myself 13925 Apr  1 21:23 Makefile.in
-r--r--r--  1 myself  myself  3443 Apr  1 21:27 shell.man
-r--r--r--  1 myself  myself  3319 Apr  1 18:54 shell.mdoc

问题:在尝试生成 - 格式的手册之前,automake我必须应用什么魔法才能将源代码make distcheck正确复制到构建目录?我正在寻找一种“正确”的方法来做到这一点,而不是黑客。mdocman

我尝试使用

man1_SOURCES= shell.mdoc

但这让人automake抱怨

doc/Makefile.am:2: warning: variable 'man1_SOURCES' is defined but no program or
doc/Makefile.am:2: library has 'man1' as canonical name (possible typo)

引发此错误的另一种方法是手动执行VPATH构建(这基本上是做时发生的事情make distcheck):

$ make distclean
$ mkdir t
$ cd t

$ ../configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/local/bin/gmkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for mandoc... /usr/bin/mandoc
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating doc/Makefile
config.status: creating src/shell

$ make
Making all in src
Making all in doc
/usr/bin/mandoc -T man shell.mdoc >shell.man
mandoc: shell.mdoc: ERROR: No such file or directory
*** Error 3 in doc (Makefile:459 'shell.man')
*** Error 1 in /home/myself/local/build/shell-toolbox/t (Makefile:345 'all-recursive')

$ ls -l doc
total 32
-rw-r--r--  1 myself myself 14589 Apr  1 22:42 Makefile
-rw-r--r--  1 myself myself     0 Apr  1 22:42 shell.man

答案1

解决方案:要在执行 VPATH 构建时正确获取手册源,文件相关部分中的规则Makefile.am应如下所示

shell.man:      $(srcdir)/shell.mdoc
        $(mandoc) -T man $(srcdir)/shell.mdoc >shell.man

通过指定$(srcdir)/shell.mdocmake即使构建树位于与分发树不同的位置,也会在分发树中查找文件。

答案2

已经有一个公认的答案,但我认为以下规则可能适用于 VPATH 构建,并且它还有一个优点:它更小:

shell.man:      shell.mdoc
        $(mandoc) -T man $< >$@

答案3

automake在某些不同目标之前和之后运行的支持-local和规则。-hook显然没有distcheck-local,所以您的另一个想法是Makefile.am使用dist-hook在之后运行某些内容dist

dist-hook:
        cp something $(distdir)/somewhere

相关内容