Man

GNU autotools 項目中與生成手冊有關的“make distcheck”問題

  • April 2, 2018

我正在使用autoconfautomake建構一個小項目。

對於該項目的手冊,我使用了 OpenBSD 的原生mdoc格式man,並且使用mandoc實用程序生成了可安裝格式的手冊。-formattedman手冊將作為實際手冊安裝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

問題:在嘗試生成-formatted 手冊之前,automake我必須應用什麼魔法才能將源make distcheck正確複製到建構目錄?我正在尋找一種“正確”的方式來做到這一點,而不是黑客。mdoc``man

我嘗試使用

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

解決方案:為了在執行 VPATH 建構時正確獲取手冊的原始碼,Makefile.am文件相關部分中的規則應如下所示

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

通過指定$(srcdir)/shell.mdoc,make將在分發樹中找到文件,即使建構樹與分發樹位於不同的位置。

automake在一些不同的目標之前和之後執行的支持-local和規則。-hook顯然沒有distcheck-local另一個想法是在您Makefile.am使用dist-hook之後執行某些東西dist

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

引用自:https://unix.stackexchange.com/questions/434891