This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Move print_version into printversion.{h|c}


Rename version.c so that the implementation is called after the header
and the header doesn't clash with the toplevel version.h. print_version
depends on argp and is only used in the tools.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
 lib/ChangeLog      | 13 +++++++++++++
 lib/Makefile.am    |  4 ++--
 lib/printversion.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 lib/printversion.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/system.h       | 16 ----------------
 lib/version.c      | 47 -----------------------------------------------
 po/ChangeLog       |  4 ++++
 po/POTFILES.in     |  2 +-
 src/ChangeLog      | 18 ++++++++++++++++++
 src/addr2line.c    |  1 +
 src/ar.c           |  1 +
 src/elfcmp.c       |  2 +-
 src/elfcompress.c  |  2 +-
 src/elflint.c      |  1 +
 src/findtextrel.c  |  2 +-
 src/nm.c           |  1 +
 src/objdump.c      |  1 +
 src/ranlib.c       |  1 +
 src/readelf.c      |  1 +
 src/size.c         |  2 +-
 src/stack.c        |  1 +
 src/strings.c      |  1 +
 src/strip.c        |  1 +
 src/unstrip.c      |  2 +-
 24 files changed, 147 insertions(+), 71 deletions(-)
 create mode 100644 lib/printversion.c
 create mode 100644 lib/printversion.h
 delete mode 100644 lib/version.c

diff --git a/lib/ChangeLog b/lib/ChangeLog
index fd63e03..84290f7 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,16 @@
+2017-02-16  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* Makefile.am (libeu_a_SOURCES): Remove version.c, add printversion.c
+	(noinst_HEADERS): Add printversion.h
+	* version.c: Moved to printversion.c.
+	* printversion.c: New file, moved from version.c,
+	remove stdio.h, argp.h, system.h includes,
+	add printversion.h include.
+	* printversion.h: New file.
+	* system.h: Remove argp.h include,
+	(ARGP_PROGRAM_VERSION_HOOK_DEF, ARGP_PROGRAM_BUG_ADDRESS_DEF): Remove.
+	(print_version): Remove.
+
 2017-02-15  Ulf Hermann  <ulf.hermann@qt.io>
 
 	* system.h: Provide mempcpy if it doesn't exist.
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 3e0c601..7a65eb9 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -35,10 +35,10 @@ noinst_LIBRARIES = libeu.a
 
 libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \
 		  crc32.c crc32_file.c md5.c sha1.c \
-		  color.c version.c
+		  color.c printversion.c
 
 noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \
-		 md5.h sha1.h eu-config.h color.h
+		 md5.h sha1.h eu-config.h color.h printversion.h
 EXTRA_DIST = dynamicsizehash.c
 
 if !GPROF
diff --git a/lib/printversion.c b/lib/printversion.c
new file mode 100644
index 0000000..4056b93
--- /dev/null
+++ b/lib/printversion.c
@@ -0,0 +1,45 @@
+/* Common argp_print_version_hook for all tools.
+   Copyright (C) 2016 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <libintl.h>
+#include "printversion.h"
+
+void
+print_version (FILE *stream, struct argp_state *state)
+{
+  fprintf (stream, "%s (%s) %s\n", state->name, PACKAGE_NAME, PACKAGE_VERSION);
+  fprintf (stream, gettext ("\
+Copyright (C) %s The elfutils developers <%s>.\n\
+This is free software; see the source for copying conditions.  There is NO\n\
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
+"), "2016", PACKAGE_URL);
+}
diff --git a/lib/printversion.h b/lib/printversion.h
new file mode 100644
index 0000000..a9e059f
--- /dev/null
+++ b/lib/printversion.h
@@ -0,0 +1,49 @@
+/* Common argp_print_version_hook for all tools.
+   Copyright (C) 2017 The Qt Company Ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef PRINTVERSION_H
+#define PRINTVERSION_H 1
+
+#include <argp.h>
+#include <stdio.h>
+
+/* Defined in version.c.  Common ARGP_PROGRAM_VERSION_HOOK_DEF.  */
+void print_version (FILE *stream, struct argp_state *state);
+
+/* We need define two variables, argp_program_version_hook and
+   argp_program_bug_address, in all programs.  argp.h declares these
+   variables as non-const (which is correct in general).  But we can
+   do better, it is not going to change.  So we want to move them into
+   the .rodata section.  Define macros to do the trick.  */
+#define ARGP_PROGRAM_VERSION_HOOK_DEF \
+  void (*const apvh) (FILE *, struct argp_state *) \
+   __asm ("argp_program_version_hook")
+#define ARGP_PROGRAM_BUG_ADDRESS_DEF \
+  const char *const apba__ __asm ("argp_program_bug_address")
+
+#endif // PRINTVERSION_H
diff --git a/lib/system.h b/lib/system.h
index 429b0c3..2d05702 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -33,7 +33,6 @@
 # include <config.h>
 #endif
 
-#include <argp.h>
 #include <errno.h>
 #include <stddef.h>
 #include <stdint.h>
@@ -145,21 +144,6 @@ pread_retry (int fd, void *buf, size_t len, off_t off)
   return recvd;
 }
 
-
-/* We need define two variables, argp_program_version_hook and
-   argp_program_bug_address, in all programs.  argp.h declares these
-   variables as non-const (which is correct in general).  But we can
-   do better, it is not going to change.  So we want to move them into
-   the .rodata section.  Define macros to do the trick.  */
-#define ARGP_PROGRAM_VERSION_HOOK_DEF \
-  void (*const apvh) (FILE *, struct argp_state *) \
-   __asm ("argp_program_version_hook")
-#define ARGP_PROGRAM_BUG_ADDRESS_DEF \
-  const char *const apba__ __asm ("argp_program_bug_address")
-
-/* Defined in version.c.  Common ARGP_PROGRAM_VERSION_HOOK_DEF.  */
-void print_version (FILE *stream, struct argp_state *state);
-
 /* The demangler from libstdc++.  */
 extern char *__cxa_demangle (const char *mangled_name, char *output_buffer,
 			     size_t *length, int *status);
diff --git a/lib/version.c b/lib/version.c
deleted file mode 100644
index b8d70cb..0000000
--- a/lib/version.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* Common argp_print_version_hook for all tools.
-   Copyright (C) 2016 Red Hat, Inc.
-   This file is part of elfutils.
-
-   This file is free software; you can redistribute it and/or modify
-   it under the terms of either
-
-     * the GNU Lesser General Public License as published by the Free
-       Software Foundation; either version 3 of the License, or (at
-       your option) any later version
-
-   or
-
-     * the GNU General Public License as published by the Free
-       Software Foundation; either version 2 of the License, or (at
-       your option) any later version
-
-   or both in parallel, as here.
-
-   elfutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received copies of the GNU General Public License and
-   the GNU Lesser General Public License along with this program.  If
-   not, see <http://www.gnu.org/licenses/>.  */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <argp.h>
-#include <libintl.h>
-#include <stdio.h>
-#include "system.h"
-
-void
-print_version (FILE *stream, struct argp_state *state)
-{
-  fprintf (stream, "%s (%s) %s\n", state->name, PACKAGE_NAME, PACKAGE_VERSION);
-  fprintf (stream, gettext ("\
-Copyright (C) %s The elfutils developers <%s>.\n\
-This is free software; see the source for copying conditions.  There is NO\n\
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "2016", PACKAGE_URL);
-}
diff --git a/po/ChangeLog b/po/ChangeLog
index 38cae02..b679f7a 100644
--- a/po/ChangeLog
+++ b/po/ChangeLog
@@ -1,3 +1,7 @@
+2017-02-16  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* po/POTFILES.in: Removed lib/version.c, added lib/printversion.c.
+
 2016-12-27  Mark Wielaard  <mark@klomp.org>
 
 	* *.po: Update for 0.168.
diff --git a/po/POTFILES.in b/po/POTFILES.in
index dec61ef..4eac6d0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,7 +3,7 @@
 
 # Files from the compatibility library
 lib/color.c
-lib/version.c
+lib/printversion.c
 lib/xmalloc.c
 
 # Library sources
diff --git a/src/ChangeLog b/src/ChangeLog
index 19c7dbb..0601198 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,21 @@
+2017-02-16  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* addr2line.c: Include printversion.h
+	* ar.c: Likewise.
+	* elflint.c: Likewise.
+	* nm.c: Likewise.
+	* objdump.c: Likewise.
+	* ranlib.c: Likewise.
+	* readelf.c: Likewise.
+	* size.c: Likewise.
+	* stack.c: Likewise.
+	* strings.c: Likewise.
+	* strip.c: Likewise.
+	* elfcmp.c: Include printversion.h, remove system.h include.
+	* elfcompress.c: Likewise.
+	* findtextrel.c: Likewise.
+	* unstrip.c: Likewise.
+
 2017-02-14  Ulf Hermann  <ulf.hermann@qt.io>
 
 	* nm.c: Include color.h.
diff --git a/src/addr2line.c b/src/addr2line.c
index 0222088..ba414a7 100644
--- a/src/addr2line.c
+++ b/src/addr2line.c
@@ -38,6 +38,7 @@
 #include <unistd.h>
 
 #include <system.h>
+#include <printversion.h>
 
 
 /* Name and version of program.  */
diff --git a/src/ar.c b/src/ar.c
index f2f322b..ec32cee 100644
--- a/src/ar.c
+++ b/src/ar.c
@@ -41,6 +41,7 @@
 #include <sys/time.h>
 
 #include <system.h>
+#include <printversion.h>
 
 #include "arlib.h"
 
diff --git a/src/elfcmp.c b/src/elfcmp.c
index 401ab31..7673cf2 100644
--- a/src/elfcmp.c
+++ b/src/elfcmp.c
@@ -33,7 +33,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <system.h>
+#include <printversion.h>
 #include "../libelf/elf-knowledge.h"
 #include "../libebl/libeblP.h"
 
diff --git a/src/elfcompress.c b/src/elfcompress.c
index 9f6db1c..8e0d5c5 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -35,7 +35,7 @@
 #include ELFUTILS_HEADER(dwelf)
 #include <gelf.h>
 #include "libeu.h"
-#include "system.h"
+#include "printversion.h"
 
 /* Name and version of program.  */
 ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
diff --git a/src/elflint.c b/src/elflint.c
index 7d3f227..66a13ca 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -39,6 +39,7 @@
 #include <elf-knowledge.h>
 #include <libeu.h>
 #include <system.h>
+#include <printversion.h>
 #include "../libelf/libelfP.h"
 #include "../libelf/common.h"
 #include "../libebl/libeblP.h"
diff --git a/src/findtextrel.c b/src/findtextrel.c
index dc41502..8f1e239 100644
--- a/src/findtextrel.c
+++ b/src/findtextrel.c
@@ -36,7 +36,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <system.h>
+#include <printversion.h>
 
 
 struct segments
diff --git a/src/nm.c b/src/nm.c
index 47a9e3b..969c6d3 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -45,6 +45,7 @@
 #include <libeu.h>
 #include <system.h>
 #include <color.h>
+#include <printversion.h>
 #include "../libebl/libeblP.h"
 #include "../libdwfl/libdwflP.h"
 
diff --git a/src/objdump.c b/src/objdump.c
index 030274b..860cfac 100644
--- a/src/objdump.c
+++ b/src/objdump.c
@@ -36,6 +36,7 @@
 #include <libeu.h>
 #include <system.h>
 #include <color.h>
+#include <printversion.h>
 #include "../libebl/libeblP.h"
 
 
diff --git a/src/ranlib.c b/src/ranlib.c
index 41a3bcf..cc0ee23 100644
--- a/src/ranlib.c
+++ b/src/ranlib.c
@@ -38,6 +38,7 @@
 #include <sys/stat.h>
 
 #include <system.h>
+#include <printversion.h>
 
 #include "arlib.h"
 
diff --git a/src/readelf.c b/src/readelf.c
index d3a9008..8d96ba3 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -45,6 +45,7 @@
 
 #include <libeu.h>
 #include <system.h>
+#include <printversion.h>
 #include "../libelf/libelfP.h"
 #include "../libelf/common.h"
 #include "../libebl/libeblP.h"
diff --git a/src/size.c b/src/size.c
index de0d791..ad8dbcb 100644
--- a/src/size.c
+++ b/src/size.c
@@ -36,7 +36,7 @@
 #include <unistd.h>
 
 #include <system.h>
-
+#include <printversion.h>
 
 /* Name and version of program.  */
 ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
diff --git a/src/stack.c b/src/stack.c
index a5a7beb..6f2ff69 100644
--- a/src/stack.c
+++ b/src/stack.c
@@ -30,6 +30,7 @@
 
 #include <dwarf.h>
 #include <system.h>
+#include <printversion.h>
 
 /* Name and version of program.  */
 ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
diff --git a/src/strings.c b/src/strings.c
index 49aab8b..d214356 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -42,6 +42,7 @@
 
 #include <libeu.h>
 #include <system.h>
+#include <printversion.h>
 
 #ifndef MAP_POPULATE
 # define MAP_POPULATE 0
diff --git a/src/strip.c b/src/strip.c
index a791ca5..f747441 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -44,6 +44,7 @@
 #include "libdwelf.h"
 #include <libeu.h>
 #include <system.h>
+#include <printversion.h>
 
 typedef uint8_t GElf_Byte;
 
diff --git a/src/unstrip.c b/src/unstrip.c
index d838ae9..6e57a6b 100644
--- a/src/unstrip.c
+++ b/src/unstrip.c
@@ -50,7 +50,7 @@
 #include <libdwfl.h>
 #include "libdwelf.h"
 #include "libeu.h"
-#include "system.h"
+#include "printversion.h"
 
 #ifndef _
 # define _(str) gettext (str)
-- 
2.1.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]