Use self-made help to avoid recompilations on version changes.
authorAndre Noll <maan@systemlinux.org>
Fri, 12 Apr 2013 12:24:54 +0000 (14:24 +0200)
committerAndre Noll <maan@systemlinux.org>
Thu, 13 Jun 2013 16:29:03 +0000 (18:29 +0200)
This provides print_help() for all remaining commands so that we can
get rid of the gengetopt generated help output completely.

Hence the *.cmdline.[ch] files no longer depend on git-version.h
which saves a lot of recompilations.

14 files changed:
afh.c
audioc.c
client_common.c
configure.ac
fade.c
gui.c
m4/gengetopt/afh.m4
m4/gengetopt/audioc.m4
m4/gengetopt/client.m4
m4/gengetopt/fade.m4
m4/gengetopt/gui.m4
m4/gengetopt/makefile
m4/gengetopt/server.m4
server.c

diff --git a/afh.c b/afh.c
index f02b47b10404ebd2424f78b922521f6261b86ba6..9ab694cf47d96c284cfe6af9b7caffcdcbf217f7 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -15,6 +15,7 @@
 #include "afh.h"
 #include "error.h"
 #include "version.h"
+#include "ggo.h"
 
 static struct afh_args_info conf;
 INIT_AFH_ERRLISTS;
@@ -56,6 +57,16 @@ static void print_chunk_table(struct afh_info *afhi)
        }
 }
 
+__noreturn static void print_help_and_die(void)
+{
+       struct ggo_help h = DEFINE_GGO_HELP(afh);
+       int d = conf.detailed_help_given;
+       unsigned flags = d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS;
+
+       ggo_print_help(&h, flags);
+       exit(EXIT_SUCCESS);
+}
+
 /**
  * The main function of para_afh.
  *
@@ -74,6 +85,9 @@ int main(int argc, char **argv)
        afh_cmdline_parser(argc, argv, &conf);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
        version_handle_flag("afh", conf.version_given);
+       if (conf.help_given || conf.detailed_help_given)
+               print_help_and_die();
+       afh_init();
        ret = -E_AFH_SYNTAX;
        if (conf.inputs_num == 0)
                goto out;
index 0147b4cf411b0a277b4378cd708e3874f05ba831..164a1554f0ee2ceba94f6a509ea4911fba8a66f9 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -17,6 +17,7 @@
 #include "net.h"
 #include "string.h"
 #include "fd.h"
+#include "ggo.h"
 #include "version.h"
 
 INIT_AUDIOC_ERRLISTS;
@@ -263,6 +264,15 @@ static char *configfile_exists(void)
        return NULL;
 }
 
+__noreturn static void print_help_and_die(void)
+{
+       struct ggo_help h = DEFINE_GGO_HELP(audioc);
+       bool d = conf.detailed_help_given;
+
+       ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS);
+       exit(0);
+}
+
 /**
  * The client program to connect to para_audiod.
  *
@@ -288,6 +298,8 @@ int main(int argc, char *argv[])
        audioc_cmdline_parser(argc, argv, &conf);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
        version_handle_flag("audioc", conf.version_given);
+       if (conf.help_given || conf.detailed_help_given)
+               print_help_and_die();
        cf = configfile_exists();
        if (cf) {
                struct audioc_cmdline_parser_params params = {
index 754b5bf235d6817714cb28e922ff60fbed2e0649..1ecba73068f04c4dbf43480f5ccf32a932e01279 100644 (file)
@@ -22,6 +22,7 @@
 #include "client.h"
 #include "buffer_tree.h"
 #include "version.h"
+#include "ggo.h"
 
 /** The size of the receiving buffer. */
 #define CLIENT_BUFSIZE 4000
@@ -611,6 +612,15 @@ err_out:
        return ret;
 }
 
+__noreturn static void print_help_and_die(struct client_task *ct)
+{
+       struct ggo_help h = DEFINE_GGO_HELP(client);
+       bool d = ct->conf.detailed_help_given;
+
+       ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS);
+       exit(0);
+}
+
 /**
  * Parse a client configuration.
  *
@@ -642,6 +652,8 @@ int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr,
        if (client_cmdline_parser(argc, argv, &ct->conf))
                goto out;
        version_handle_flag("client", ct->conf.version_given);
+       if (ct->conf.help_given || ct->conf.detailed_help_given)
+               print_help_and_die(ct);
 
        ct->config_file = ct->conf.config_file_given?
                para_strdup(ct->conf.config_file_arg) :
index e3d1b40eabce19c8fc4168a59451af8a4dfc3866..3a0a36f62f002a9bf19d3d9e66d495fc27b942b0 100644 (file)
@@ -124,7 +124,14 @@ filter_ldflags="-lm"
 filters=" compress wav amp fecdec wmadec prebuffer"
 
 audioc_cmdline_objs="add_cmdline(audioc)"
-audioc_errlist_objs="audioc string net fd version"
+audioc_errlist_objs="
+       audioc
+       string
+       net
+       fd
+       version
+       ggo
+"
 audioc_ldflags=""
 
 audiod_cmdline_objs="add_cmdline(audiod compress_filter http_recv dccp_recv file_write client amp_filter udp_recv prebuffer_filter)"
@@ -149,12 +156,38 @@ writers=" file"
 default_writer="FILE_WRITE"
 
 client_cmdline_objs="add_cmdline(client)"
-client_errlist_objs="client net string fd sched stdin stdout time sideband
-       client_common buffer_tree crypt_common version"
+client_errlist_objs="
+       client
+       net
+       string
+       fd
+       sched
+       stdin
+       stdout
+       time
+       sideband
+       client_common
+       buffer_tree
+       crypt_common
+       version
+       ggo
+"
 client_ldflags=""
 
 gui_cmdline_objs="add_cmdline(gui)"
-gui_errlist_objs="exec signal string stat ringbuffer fd gui gui_theme version time"
+gui_errlist_objs="
+       exec
+       signal
+       string
+       stat
+       ringbuffer
+       fd
+       gui
+       gui_theme
+       time
+       version
+       ggo
+"
 gui_objs="$gui_cmdline_objs $gui_errlist_objs"
 play_errlist_objs="play fd sched ggo buffer_tree time string net
        afh_recv afh_common
@@ -292,12 +325,43 @@ else
        extras="$extras server"
        executables="$executables server"
        server_cmdline_objs="add_cmdline(server)"
-       server_errlist_objs="server afh_common mp3_afh vss command net
-               string signal time daemon http_send close_on_fork mm
-               crypt_common ipc dccp_send fd user_list chunk_queue
-               afs aft mood score attribute blob playlist sched acl
-               send_common udp_send color fec wma_afh wma_common sideband
-               version"
+       server_errlist_objs="
+               server
+               afh_common
+               mp3_afh
+               vss command
+               net
+               string
+               signal
+               time
+               daemon
+               http_send
+               close_on_fork
+               mm
+               crypt_common
+               ipc dccp_send
+               fd
+               user_list
+               chunk_queue
+               afs
+               aft
+               mood
+               score
+               attribute
+               blob
+               playlist
+               sched
+               acl
+               send_common
+               udp_send
+               color
+               fec
+               wma_afh
+               wma_common
+               sideband
+               version
+               ggo
+       "
        all_errlist_objs="$all_errlist_objs server vss command
                http_send close_on_fork mm ipc dccp_send user_list
                chunk_queue afs aft mood score attribute blob playlist
@@ -889,7 +953,7 @@ AC_CHECK_HEADER(sys/soundcard.h, [
 
        write_errlist_objs="$write_errlist_objs oss_write"
        write_cmdline_objs="$write_cmdline_objs add_cmdline(oss_write)"
-       fade_errlist_objs="$fade_errlist_objs oss_mix version"
+       fade_errlist_objs="$fade_errlist_objs oss_mix"
        all_errlist_objs="$all_errlist_objs oss_write oss_mix"
 
        writers="$writers oss"
@@ -968,7 +1032,7 @@ if test -n "$mixers"; then
        extras="$extras fade"
        executables="$executables fade"
        all_errlist_objs="$all_errlist_objs fade"
-       fade_errlist_objs="$fade_errlist_objs fade exec string fd"
+       fade_errlist_objs="$fade_errlist_objs fade exec string fd version ggo"
        fade_cmdline_objs="add_cmdline(fade)"
        fade_objs="$fade_cmdline_objs $fade_errlist_objs"
        AC_SUBST(fade_objs, add_dot_o($fade_objs))
diff --git a/fade.c b/fade.c
index 76d6a8b422b3fca28ded60dee815d8335378a5c9..878b83a17e26f40da9c33c6035dba345353257d4 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -14,6 +14,7 @@
 #include "string.h"
 #include "mix.h"
 #include "error.h"
+#include "ggo.h"
 #include "version.h"
 
 INIT_FADE_ERRLISTS;
@@ -286,6 +287,15 @@ static struct mixer *get_mixer_or_die(void)
        exit(EXIT_FAILURE);
 }
 
+__noreturn static void print_help_and_die(void)
+{
+       struct ggo_help h = DEFINE_GGO_HELP(fade);
+       bool d = conf.detailed_help_given;
+
+       ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS);
+       exit(0);
+}
+
 int main(int argc, char *argv[])
 {
        int ret;
@@ -295,6 +305,8 @@ int main(int argc, char *argv[])
        fade_cmdline_parser(argc, argv, &conf);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
        version_handle_flag("fade", conf.version_given);
+       if (conf.help_given || conf.detailed_help_given)
+               print_help_and_die();
        ret = configfile_exists();
        if (!ret && conf.config_file_given) {
                PARA_EMERG_LOG("can not read config file %s\n",
diff --git a/gui.c b/gui.c
index 4e293feba6860e7ed1dcc2ab2f045ccc7618f350..b874d0820c6341f124ccb9748dd91bce0a0d395b 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -23,6 +23,7 @@
 #include "list.h"
 #include "sched.h"
 #include "signal.h"
+#include "ggo.h"
 #include "version.h"
 
 /** define the array of error lists needed by para_gui */
@@ -1511,6 +1512,15 @@ static void handle_command(int c)
                km_keyname(c));
 }
 
+__noreturn static void print_help_and_die(void)
+{
+       struct ggo_help h = DEFINE_GGO_HELP(gui);
+       bool d = conf.detailed_help_given;
+
+       ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS);
+       exit(0);
+}
+
 int main(int argc, char *argv[])
 {
        int ret;
@@ -1522,6 +1532,8 @@ int main(int argc, char *argv[])
        gui_cmdline_parser(argc, argv, &conf); /* exits on errors */
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
        version_handle_flag("gui", conf.version_given);
+       if (conf.help_given || conf.detailed_help_given)
+               print_help_and_die();
        cf = configfile_exists();
        if (!cf && conf.config_file_given) {
                fprintf(stderr, "can not read config file %s\n",
index 6fd4ab6921b4654bead1b0386e38b5711d8e4333..f8e29fea8693af08506fb6b91210010d722994ac 100644 (file)
@@ -1,4 +1,4 @@
-args "--unamed-opts=audio_file --no-handle-version"
+args "--unamed-opts=audio_file --no-handle-version --no-handle-help"
 
 purpose "Print information about audio file(s)."
 
index 2865900e7a4fb00d362e5714faa732aed2f18f63..36520bfa0f16888020d431d7001c40c17c00146a 100644 (file)
@@ -1,4 +1,4 @@
-args "--unamed-opts=command --conf-parser --no-handle-version"
+args "--unamed-opts=command --conf-parser --no-handle-version --no-handle-help"
 
 purpose "Communicate with para_audiod through a local socket."
 
index a14b59c0aa4d2299659b18d71af4364c9f8fd6df..f0bbc0bd8eadf2000e69f2f95e41b22c146f4080 100644 (file)
@@ -1,4 +1,4 @@
-args "--unamed-opts=command --no-handle-error --conf-parser --no-handle-version"
+args "--unamed-opts=command --no-handle-error --conf-parser --no-handle-version --no-handle-help"
 
 purpose "Communicate with para_server through the paraslash control port."
 
index 8b81975b36a0a3ba4f08bf21af39c8a9e946ea43..7c731c2b6ec1cdf15322131827fe99add0917e09 100644 (file)
@@ -1,4 +1,4 @@
-args "--conf-parser --no-handle-version"
+args "--conf-parser --no-handle-version --no-handle-help"
 
 purpose "An alarm clock and volume-fader for OSS and ALSA."
 
index af1ca1452b2e82e6172831bdfdadc9d01e546b3a..1f5cf6e425bc506e8d7eae143a2b3a7319dd4a5e 100644 (file)
@@ -1,4 +1,4 @@
-args "--conf-parser --no-handle-version"
+args "--conf-parser --no-handle-version --no-handle-help"
 
 purpose "Show para_audiod status in a curses window."
 
index c816bd74ad8669b469417144e9aa01f13bdd6589..548a3d5d83bcb406a66dc26a77c0a840745d868f 100644 (file)
@@ -9,7 +9,7 @@ endef
 
 .PRECIOUS: $(cmdline_dir)/%.cmdline.c $(cmdline_dir)/%.cmdline.h $(ggo_dir)/%.ggo
 
-$(cmdline_dir)/%.cmdline.h $(cmdline_dir)/%.cmdline.c: $(ggo_dir)/%.ggo git-version.h | $(cmdline_dir)
+$(cmdline_dir)/%.cmdline.h $(cmdline_dir)/%.cmdline.c: $(ggo_dir)/%.ggo | $(cmdline_dir)
        @[ -z "$(Q)" ] || echo 'GGO $<'
        $(Q) $(GENGETOPT) $(ggo_opts) < $<
 ifeq ($(ggo_descriptions_declared),no)
index 6596d9340acb8f6746e01b13031c9c3d018d151e..8707554f7719ace121dae2701e179c22ab687184 100644 (file)
@@ -1,4 +1,4 @@
-args "--conf-parser --no-handle-version"
+args "--conf-parser --no-handle-version --no-handle-help"
 
 purpose "Manage and stream audio files."
 
index cd985c6d7f554d8ef9b2d980a5fe35d0c0690c14..f26abef5753204c4628c4183519f50f02b8f674e 100644 (file)
--- a/server.c
+++ b/server.c
@@ -91,6 +91,7 @@
 #include "signal.h"
 #include "user_list.h"
 #include "color.h"
+#include "ggo.h"
 #include "version.h"
 
 __printf_2_3 void (*para_log)(int, const char*, ...) = daemon_log;
@@ -473,6 +474,15 @@ static int init_afs(int argc, char **argv)
        return afs_server_socket[0];
 }
 
+__noreturn static void print_help_and_die(void)
+{
+       struct ggo_help h = DEFINE_GGO_HELP(server);
+       bool d = conf.detailed_help_given;
+
+       ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS);
+       exit(0);
+}
+
 static void server_init(int argc, char **argv)
 {
        struct server_cmdline_parser_params params = {
@@ -490,6 +500,8 @@ static void server_init(int argc, char **argv)
        server_cmdline_parser_ext(argc, argv, &conf, &params);
        daemon_set_loglevel(conf.loglevel_arg);
        version_handle_flag("server", conf.version_given);
+       if (conf.help_given || conf.detailed_help_given)
+               print_help_and_die();
        drop_privileges_or_die(conf.user_arg, conf.group_arg);
        /* parse config file, open log and set defaults */
        parse_config_or_die(0);