sepdebugcrcfix: Add --version, --help and man page.
authorMark Wielaard <mark@klomp.org>
Thu, 29 Apr 2021 20:44:41 +0000 (22:44 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 29 Apr 2021 22:39:39 +0000 (00:39 +0200)
Add --version and --help support to sepdebugcrcfix. Use this to generate
a manual page using help2man.

* .gitignore: Add sepdebugcrcfix.1
* Makefile.am (dist_man_MANS): Add sepdebugcrcfix.1
(sepdebugcrcfix.1): New make rule.
* tools/sepdebugcrcfix.c (version): New static functions.
(help): Likewise.
(main): Call version or help depending on argc and argv.

https://sourceware.org/bugzilla/show_bug.cgi?id=27642

Signed-off-by: Mark Wielaard <mark@klomp.org>
.gitignore
Makefile.am
tools/sepdebugcrcfix.c

index 55d4bfcb0f1064b9c8339b728159caa4bf287fe6..d41ec64bbd604731a3b09cffca57e47efd4a09c4 100644 (file)
@@ -29,6 +29,7 @@ missing
 debugedit
 debugedit.1
 sepdebugcrcfix
+sepdebugcrcfix.1
 
 atconfig
 atlocal
index 504278518ce303c565f92f6c6f7c766fd847b8c3..de7c51d4775478e8490618791824991613a06949 100644 (file)
@@ -39,7 +39,7 @@ sepdebugcrcfix_CFLAGS = @LIBELF_CFLAGS@ $(AM_CFLAGS)
 sepdebugcrcfix_LDADD = @LIBELF_LIBS@
 
 # Manual pages are generated for dist
-dist_man_MANS = debugedit.1
+dist_man_MANS = debugedit.1 sepdebugcrcfix.1
 
 debugedit.1: tools/debugedit.c $(top_srcdir)/configure.ac
        $(MAKE) $(AM_MAKEFLAGS) debugedit$(EXEEXT)
@@ -47,6 +47,12 @@ debugedit.1: tools/debugedit.c $(top_srcdir)/configure.ac
          --name='debug source path manipulation tool' \
          ./debugedit$(EXEEXT)
 
+sepdebugcrcfix.1: tools/sepdebugcrcfix.c $(top_srcdir)/configure.ac
+       $(MAKE) $(AM_MAKEFLAGS) sepdebugcrcfix$(EXEEXT)
+       $(HELP2MAN) -N --output=$@ \
+         --name='fixes CRC for separate .debug files' \
+         ./sepdebugcrcfix$(EXEEXT)
+
 noinst_HEADERS= tools/ansidecl.h \
                tools/hashtab.h \
                tools/md5.h \
index 72b3f305688b653d0ccf74faf794ef69b67af5da..20800ba09cec176b9743b2bf6f958c71d098d295 100644 (file)
@@ -300,11 +300,40 @@ process (Elf *elf, int fd, const char *fname)
   return false;
 }
 
+static void
+version (void)
+{
+  printf("sepdebugcrcfix %s\n", VERSION);
+  exit(EXIT_SUCCESS);
+}
+
+static const char *helpText =
+  "Usage: %s DEBUG_DIR FILEs\n" \
+  "Fixes CRC in .debug files under DEBUG_DIR for the given FILEs\n"    \
+  "\n"                                                                 \
+  "DEBUG_DIR is usually \"usr/lib/debug\".\n"                          \
+  "FILEs should have relative paths.\n"                                        \
+  "The relative paths will be used to find the corresponding .debug\n"  \
+  "files under DEBUGDIR\n";
+
+static void
+help (const char *progname, bool error)
+{
+  FILE *f = error ? stderr : stdout;
+  fprintf (f, helpText, progname);
+  exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
 int
 main (int argc, char **argv)
 {
+  if (argc == 2 && strcmp (argv[1], "--version") == 0)
+    version ();
+  if (argc == 2 && strcmp (argv[1], "--help") == 0)
+    help (argv[0], false);
   if (argc < 2)
-    error (1, 0, _("usr/lib/debug [<relative filenames>...]"));
+    help (argv[0], true);
+
   usr_lib_debug = argv[1];
   if (elf_version (EV_CURRENT) == EV_NONE)
     error (1, 0, _("error initializing libelf: %s"), elf_errmsg (-1));
This page took 0.05855 seconds and 5 git commands to generate.