build: Generate man pages directly from ggo files.
authorAndre Noll <maan@systemlinux.org>
Fri, 30 Aug 2013 00:10:41 +0000 (00:10 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 1 Dec 2013 10:47:32 +0000 (11:47 +0100)
Currently all man pages are created by help2man which executes the
para_xxx binaries just compiled with the --detailed-help and --version
options given to obtain the input for the man page to create.

The obvious shortcoming of this approach is that it simply does not
work when cross-compiling. There is another disadvantage though: Since
the man page file (para_xxx.1) depends on the executable (para_xxx),
any code change causes all affected man pages to be recreated, even
if nothing has changed that would alter the man page content.

The good news is that gengetopt can create the help output without
generating or compiling any code. The bad news is that help2man
insists on executing a program with --help and --version to get the
output.

This commit teaches Makefile to create a dummy shell script for each
executable which accepts the above options and runs gengetopt on the
.ggo file to obtain the help text.

This makes cross-compiling possible and shortens rebuild times since
with the patch applied, the man page is only recreated when the ggo
file changes.

Makefile.in
m4/gengetopt/makefile

index bcc19a09b35b816aa76680298b7beec6b3148ee3..409725e1e18b4efac98c61b4a6e7bd94b33a14b4 100644 (file)
@@ -35,6 +35,7 @@ dep_dir := $(build_dir)/deps
 man_dir := $(build_dir)/man/man1
 cmdline_dir := $(build_dir)/cmdline
 m4depdir := $(build_dir)/m4deps
+help2man_dir := $(build_dir)/help2man
 
 DEBUG_CPPFLAGS += -g -Wunused -Wundef -W
 DEBUG_CPPFLAGS += -Wredundant-decls
@@ -103,7 +104,8 @@ dep: $(deps)
 man: $(man_pages)
 tarball: $(tarball)
 
-$(object_dir) $(man_dir) $(ggo_dir) $(cmdline_dir) $(dep_dir) $(m4depdir):
+$(object_dir) $(man_dir) $(ggo_dir) $(cmdline_dir) $(dep_dir) $(m4depdir) \
+               $(help2man_dir):
        $(Q) $(MKDIR_P) $@
 
 -include $(m4_ggo_dir)/makefile
@@ -133,22 +135,22 @@ afs_command_list.h afs_command_list.man afs_completion.h: afs.c aft.c attribute.
 audiod_command_list.h audiod_command_list.man audiod_completion.h: audiod_command.c
 
 server_command_lists_man = server_command_list.man afs_command_list.man
-$(man_dir)/para_server.1: para_server $(server_command_lists_man) | $(man_dir)
+$(man_dir)/para_server.1: $(help2man_dir)/para_server $(server_command_lists_man) | $(man_dir)
        @[ -z "$(Q)" ] || echo 'MAN $<'
-       $(Q) opts="-h --detailed-help -N `for i in $(server_command_lists_man); do printf "%s\n" "-i $$i"; done`"; \
-       $(HELP2MAN) $$opts ./para_server > $@
+       $(Q) opts="`for i in $(server_command_lists_man); do printf "%s\n" "-i $$i"; done`"; \
+       $(HELP2MAN) $$opts ./$< > $@
 
-$(man_dir)/para_audiod.1: para_audiod audiod_command_list.man | $(man_dir)
+$(man_dir)/para_audiod.1: $(help2man_dir)/para_audiod audiod_command_list.man | $(man_dir)
        @[ -z "$(Q)" ] || echo 'MAN $<'
-       $(Q) $(HELP2MAN) -h --detailed-help -N -i audiod_command_list.man ./para_audiod > $@
+       $(Q) $(HELP2MAN) -N -i audiod_command_list.man ./$< > $@
 
-$(man_dir)/para_play.1: para_play play_command_list.man | $(man_dir)
+$(man_dir)/para_play.1: $(help2man_dir)/para_play play_command_list.man | $(man_dir)
        @[ -z "$(Q)" ] || echo 'MAN $<'
-       $(Q) $(HELP2MAN) -h --detailed-help -N -i play_command_list.man ./para_play > $@
+       $(Q) $(HELP2MAN) -N -i play_command_list.man ./$< > $@
 
-$(man_dir)/%.1: % | $(man_dir)
+$(man_dir)/%.1: $(help2man_dir)/% | $(man_dir)
        @[ -z "$(Q)" ] || echo 'MAN $<'
-       $(Q) $(HELP2MAN) -h --detailed-help -N ./$< > $@
+       $(Q) $(HELP2MAN) -N ./$< > $@
 
 $(object_dir)/crypt.o: crypt.c | $(object_dir)
        @[ -z "$(Q)" ] || echo 'CC $<'
index 79e101a3e4e88f3e55b096b90780615b82b2e602..ada70d198b496abc98fb5ed462180f81d4c0d99a 100644 (file)
@@ -25,3 +25,14 @@ $(m4depdir)/%.m4d: $(m4_ggo_dir)/%.m4 | $(m4depdir)
 $(ggo_dir)/%.ggo: $(m4_ggo_dir)/%.m4 $(m4_ggo_dir)/header.m4 | $(ggo_dir)
        @[ -z "$(Q)" ] || echo 'M4 $<'
        $(Q) m4 -I $(m4_ggo_dir) $< > $@
+
+$(help2man_dir)/para_%: $(ggo_dir)/%.ggo | $(help2man_dir)
+       @[ -z "$(Q)" ] || echo 'G2X $<'
+       $(Q) printf "#!/bin/sh\nif [ \"\$$1\" = '--version' ]; then \
+                       $(GENGETOPT) $(ggo_opts) --show-version < $<; \
+               elif [ \"\$$1\" = '--help' ]; then \
+                       $(GENGETOPT)  $(ggo_opts) --show-detailed-help < $<; \
+               else \
+                       exit 1; \
+               fi\n" > $@.tmp
+       $(Q) chmod 755 $@.tmp && mv $@.tmp $@