public inbox for debugedit@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] sepdebugcrcfix: Add --version, --help and man page.
@ 2021-04-29 20:48 Mark Wielaard
  0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2021-04-29 20:48 UTC (permalink / raw)
  To: debugedit; +Cc: Mark Wielaard

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.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 .gitignore             |  1 +
 Makefile.am            |  8 +++++++-
 tools/sepdebugcrcfix.c | 31 ++++++++++++++++++++++++++++++-
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 55d4bfc..d41ec64 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,7 @@ missing
 debugedit
 debugedit.1
 sepdebugcrcfix
+sepdebugcrcfix.1
 
 atconfig
 atlocal
diff --git a/Makefile.am b/Makefile.am
index 5042785..de7c51d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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 \
diff --git a/tools/sepdebugcrcfix.c b/tools/sepdebugcrcfix.c
index 72b3f30..20800ba 100644
--- a/tools/sepdebugcrcfix.c
+++ b/tools/sepdebugcrcfix.c
@@ -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));
-- 
2.18.4


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-29 20:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-29 20:48 [PATCH] sepdebugcrcfix: Add --version, --help and man page Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).