Include options for receivers/filters/writer in man pages
authorAndre Noll <maan@systemlinux.org>
Sun, 29 Dec 2013 01:28:41 +0000 (01:28 +0000)
committerAndre Noll <maan@systemlinux.org>
Sat, 22 Feb 2014 15:49:29 +0000 (16:49 +0100)
This broke in v0.5.0 when we started to create the man pages in a
way that works also in a cross-compile setup.

This fix introduces a new script man_util.bash which does the real
work and hides all the ugliness from the Makefiles.

Makefile.in
Makefile.real
configure.ac
m4/gengetopt/makefile
man_util.bash [new file with mode: 0755]

index 19679923934883941ab6b810dcbb0e33cf4c3e39..6762b449bed265fd2e0141e3c6bf462bf44e3a6e 100644 (file)
@@ -16,6 +16,10 @@ ggo_descriptions_declared := @ggo_descriptions_declared@
 object_executable_matrix := @object_executable_matrix@
 
 executables := @executables@
 object_executable_matrix := @object_executable_matrix@
 
 executables := @executables@
+receivers := @receivers@
+filters := @filters@
+writers := @writers@
+
 recv_objs := @recv_objs@
 filter_objs := @filter_objs@
 client_objs := @client_objs@
 recv_objs := @recv_objs@
 filter_objs := @filter_objs@
 client_objs := @client_objs@
index d80203765c521d68a3f2f634536cf46283142545..6d839880d96808b72e16a2d0410396a09cfa6955 100644 (file)
@@ -138,23 +138,31 @@ server_command_list.h server_command_list.man server_completion.h: command.c
 afs_command_list.h afs_command_list.man afs_completion.h: afs.c aft.c attribute.c
 audiod_command_list.h audiod_command_list.man audiod_completion.h: audiod_command.c
 
 afs_command_list.h afs_command_list.man afs_completion.h: afs.c aft.c attribute.c
 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: $(help2man_dir)/para_server $(server_command_lists_man) | $(man_dir)
-       @[ -z "$(Q)" ] || echo 'MAN $<'
-       $(Q) opts="`for i in $(server_command_lists_man); do printf "%s\n" "-i $$i"; done`"; \
-       $(HELP2MAN) $$opts ./$< > $@
+server_command_lists := server_command_list.man afs_command_list.man
+audiod_command_lists := audiod_command_list.man
+play_command_lists := play_command_list.man
 
 
-$(man_dir)/para_audiod.1: $(help2man_dir)/para_audiod audiod_command_list.man | $(man_dir)
-       @[ -z "$(Q)" ] || echo 'MAN $<'
-       $(Q) $(HELP2MAN) -N -i audiod_command_list.man ./$< > $@
+$(man_dir)/para_server.1: $(server_command_lists)
+$(man_dir)/para_audiod.1: $(audiod_command_lists)
+$(man_dir)/para_play.1: $(play_command_lists)
 
 
-$(man_dir)/para_play.1: $(help2man_dir)/para_play play_command_list.man | $(man_dir)
-       @[ -z "$(Q)" ] || echo 'MAN $<'
-       $(Q) $(HELP2MAN) -N -i play_command_list.man ./$< > $@
+$(man_dir)/para_server.1: man_util_command_lists := $(server_command_lists)
+$(man_dir)/para_audiod.1: man_util_command_lists := $(audiod_command_lists)
+$(man_dir)/para_play.1: man_util_command_lists := $(play_command_lists)
 
 
-$(man_dir)/%.1: $(help2man_dir)/% | $(man_dir)
+$(man_dir)/para_%.1: $(ggo_dir)/%.ggo man_util.bash | $(man_dir) $(help2man_dir)
        @[ -z "$(Q)" ] || echo 'MAN $<'
        @[ -z "$(Q)" ] || echo 'MAN $<'
-       $(Q) $(HELP2MAN) -N ./$< > $@
+       $(Q) \
+               COMMAND_LISTS="$(man_util_command_lists)" \
+               FILTERS="$(filters)" \
+               GENGETOPT=$(GENGETOPT) \
+               GGO_DIR=$(ggo_dir) \
+               HELP2MAN=$(HELP2MAN) \
+               HELP2MAN_DIR=$(help2man_dir) \
+               RECEIVERS="$(receivers)" \
+               VERSION="$(GIT_VERSION)" \
+               WRITERS="$(writers)" \
+               ./man_util.bash $@
 
 $(hostbin_dir)/error2: error2.c | $(hostbin_dir)
        @[ -z "$(Q)" ] || echo 'HCC $<'
 
 $(hostbin_dir)/error2: error2.c | $(hostbin_dir)
        @[ -z "$(Q)" ] || echo 'HCC $<'
index 36eab1142a30517110bc13eda34dd52850ab629f..ba177eac3c29a4beda0dbee952ac3977f1708e78 100644 (file)
@@ -1167,6 +1167,8 @@ if test "$have_samplerate" = "yes"; then
        filter_cmdline_objs="$filter_cmdline_objs resample_filter"
        filters="$filters resample"
 fi
        filter_cmdline_objs="$filter_cmdline_objs resample_filter"
        filters="$filters resample"
 fi
+filters="$(echo $filters)"
+AC_SUBST(filters)
 filter_objs="add_cmdline($filter_cmdline_objs) $filter_errlist_objs"
 
 AC_SUBST(filter_objs, add_dot_o($filter_objs))
 filter_objs="add_cmdline($filter_cmdline_objs) $filter_errlist_objs"
 
 AC_SUBST(filter_objs, add_dot_o($filter_objs))
@@ -1231,6 +1233,7 @@ if test "$have_flac" = "yes"; then
        recv_errlist_objs="$recv_errlist_objs flac_afh"
 fi
 recv_objs="add_cmdline($recv_cmdline_objs) $recv_errlist_objs"
        recv_errlist_objs="$recv_errlist_objs flac_afh"
 fi
 recv_objs="add_cmdline($recv_cmdline_objs) $recv_errlist_objs"
+AC_SUBST(receivers, "http dccp udp afh")
 AC_SUBST(recv_objs, add_dot_o($recv_objs))
 AC_DEFINE_UNQUOTED(INIT_RECV_ERRLISTS, objlist_to_errlist($recv_errlist_objs),
        errors used by para_recv)
 AC_SUBST(recv_objs, add_dot_o($recv_objs))
 AC_DEFINE_UNQUOTED(INIT_RECV_ERRLISTS, objlist_to_errlist($recv_errlist_objs),
        errors used by para_recv)
@@ -1421,6 +1424,7 @@ if test "$have_alsa" = "yes"; then
        writers="$writers alsa"
        default_writer="ALSA_WRITE"
 fi
        writers="$writers alsa"
        default_writer="ALSA_WRITE"
 fi
+AC_SUBST(writers)
 write_objs="add_cmdline($write_cmdline_objs) $write_errlist_objs"
 AC_SUBST(write_objs, add_dot_o($write_objs))
 AC_DEFINE_UNQUOTED(INIT_WRITE_ERRLISTS,
 write_objs="add_cmdline($write_cmdline_objs) $write_errlist_objs"
 AC_SUBST(write_objs, add_dot_o($write_objs))
 AC_DEFINE_UNQUOTED(INIT_WRITE_ERRLISTS,
@@ -1539,7 +1543,7 @@ unix socket credentials: $have_ucred
 readline (interactive CLIs): $have_readline
 audio formats handlers: $audio_format_handlers
 id3 version2 support: $have_libid3tag
 readline (interactive CLIs): $have_readline
 audio formats handlers: $audio_format_handlers
 id3 version2 support: $have_libid3tag
-filters: $(echo $filters)
+filters: $filters
 writers: $writers
 
 para_fade: $build_fade
 writers: $writers
 
 para_fade: $build_fade
index ada70d198b496abc98fb5ed462180f81d4c0d99a..79e101a3e4e88f3e55b096b90780615b82b2e602 100644 (file)
@@ -25,14 +25,3 @@ $(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) $< > $@
 $(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 $@
diff --git a/man_util.bash b/man_util.bash
new file mode 100755 (executable)
index 0000000..cb7519c
--- /dev/null
@@ -0,0 +1,108 @@
+#!/usr/bin/env bash
+
+# Receivers, filters, writers are called "modules" in this script
+print_modhelp()
+{
+       local ggo="$1"
+
+       $GENGETOPT --show-detailed-help \
+               --set-version "" \
+               --set-package "" \
+               < "$ggo" | awk 'BEGIN {
+                       have_purpose=0
+                       have_usage=0
+               } {
+                       if (!have_purpose) {
+                               if ($0 ~ /^ *$/)
+                                       next
+                               printf(" (%s):", $0)
+                               have_purpose=1
+                               next
+                       }
+                       if (!have_usage) {
+                               if ($0 ~ /^Usage: /) {
+                                       have_usage=1
+                               }
+                               next
+                       }
+                       print $0
+               }'
+}
+
+make_help()
+{
+       local target="$1" module ggo
+
+       ggo="$GGO_DIR/$1.ggo"
+       $GENGETOPT --show-detailed-help \
+               --set-version "$VERSION" \
+               --set-package "para_$1" \
+               < "$ggo"
+
+       if [[ "$target" == 'recv' || "$target" == 'audiod' ]]; then
+               for module in $RECEIVERS; do
+                       ggo="$GGO_DIR/${module}_recv.ggo"
+                       [[ ! -f "$ggo" ]] && continue
+                       printf "\nOptions for the $module receiver"
+                       print_modhelp "$ggo"
+               done
+       fi
+       if [[ "$target" == 'filter' || "$target" == 'audiod' ]]; then
+               for module in $FILTERS; do
+                       ggo="$GGO_DIR/${module}_filter.ggo"
+                       [[ ! -f "$ggo" ]] && continue
+                       printf "\nOptions for the $module filter"
+                       print_modhelp "$ggo"
+               done
+       fi
+       if [[ "$target" == 'write' || "$target" == 'audiod' ]]; then
+               for module in $WRITERS; do
+                       ggo="$GGO_DIR/${module}_write.ggo"
+                       [[ ! -f "$ggo" ]] && continue
+                       printf "\nOptions for the $module writer"
+                       print_modhelp "$ggo"
+               done
+       fi
+}
+
+set -u
+
+(($# != 1)) && exit 1
+
+# These must be set by the caller (make or help2man)
+export COMMAND_LISTS FILTERS GENGETOPT GGO_DIR HELP2MAN HELP2MAN_DIR \
+       RECEIVERS VERSION WRITERS
+
+# If either --version or --help-xxx was given, we are being called by help2man
+if [[ "$1" == "--version" ]]; then
+       echo "$VERSION"
+       exit $?
+fi
+if [[ "$1" =~ --help- ]]; then
+       make_help "${1#--help-}"
+       exit $?
+fi
+
+# Called by make, run help2man
+output_file="$1"
+target="${output_file##*/para_}"
+target="${target%.*}" # server, audiod, filter, ...
+link="$HELP2MAN_DIR/para_$target"
+
+cl_opts=
+for cl in $COMMAND_LISTS; do
+       cl_opts+=" --include $cl"
+done
+
+# Create a symlink para_$target, pointing to this script. This hack is
+# necessary because help2man always includes the name of the executable in its
+# output.
+ln -sf "$PWD/$0" "$link"
+
+# This will call us again twice, with either --help-$target or --version given.
+$HELP2MAN --no-info --help-option "--help-$target" $cl_opts \
+       "$link" > "$output_file"
+if (($? != 0)); then
+       rm -f "$output_file"
+       exit 1
+fi