public inbox for debugedit@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: debugedit@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] sepdebugcrcfix: Add --version, --help and man page.
Date: Thu, 29 Apr 2021 22:48:25 +0200	[thread overview]
Message-ID: <20210429204825.19783-1-mark@klomp.org> (raw)

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


                 reply	other threads:[~2021-04-29 20:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210429204825.19783-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=debugedit@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).