summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-02-23 20:18:49 +0100
committerWerner Koch <wk@gnupg.org>2013-02-23 20:18:49 +0100
commite6943de88627c6662fba3fe905c8761dbf0ccfa1 (patch)
treeca32f43f64134265645e6db68421734ef26ce491
parentb78200135ce1d20fb4680174eed2106d6012dc14 (diff)
downloadlibgpg-error-e6943de88627c6662fba3fe905c8761dbf0ccfa1.tar.gz
Add version macros and check function.
* configure.ac (VERSION_NUMBER): New ac_subst. (BUILD_FILEVERSION): Build on all platforms (BUILD_TIMESTAMP): Try to use an ISO string. * src/Makefile.am (extra-h.in): Add new version numbers. * src/versioninfo.rc.in: Update copyright year. * src/version.c: New. (gpg_error_check_version): New API. * src/gpg-error.h.in: Add gpg_error_check_version prototype. * src/gpg-error.def.in: Add gpg_error_check_version * tests/t-version.c: New. * tests/Makefile.am (TESTS): Add t-version.c * src/gpg-error-config.in: s/VERSION/PACKAGE_VERSION/. -- All other GnuPG libraries do this, thus we do it here as well.
-rw-r--r--NEWS9
-rw-r--r--configure.ac42
-rw-r--r--src/Makefile.am39
-rw-r--r--src/gpg-error-config.in2
-rw-r--r--src/gpg-error.def.in5
-rw-r--r--src/gpg-error.h.in13
-rw-r--r--src/version.c121
-rw-r--r--src/versioninfo.rc.in4
-rw-r--r--tests/Makefile.am12
-rw-r--r--tests/t-version.c98
10 files changed, 301 insertions, 44 deletions
diff --git a/NEWS b/NEWS
index fc184ec..a804484 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,11 @@
Noteworthy changes in version 1.11 (unreleased)
----------------------------------------------
- * New error source GPG_ERR_SOURCE_ASSUAN for Libassuan related errors.
+ * New error source GPG_ERR_SOURCE_ASSUAN for Libassuan related
+ errors.
+
+ * New macros GPG_ERROR_VERSION and GPG_ERROR_VERSION_NUMBER. New
+ function gpg_error_check_version.
* Interface changes relative to the 1.10 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -11,6 +15,9 @@ Noteworthy changes in version 1.11 (unreleased)
GPG_ERR_DUP_KEY NEW.
GPG_ERR_AMBIGUOUS NEW.
GPG_ERR_SOURCE_ASSUAN NEW.
+ gpg_error_check_version NEW.
+ GPG_ERROR_VERSION NEW.
+ GPG_ERROR_VERSION_NUMBER NEW.
Noteworthy changes in version 1.10 (2010-10-26)
diff --git a/configure.ac b/configure.ac
index b25630e..dc897a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,12 +26,14 @@ min_automake_version="1.11"
# Please bump the version number immediately after the release, do
# another commit, and a push so that the git magic is able to work.
# See below for the LT versions.
-m4_define([mym4_version], [1.11])
+m4_define([mym4_version_major], [1])
+m4_define([mym4_version_minor], [11])
# Below is m4 magic to extract and compute the revision number, the
# decimalized short revision number, a beta version string, and a flag
# indicating a development version (mym4_isgit). Note that the m4
# processing is done by autoconf and not during the configure run.
+m4_define([mym4_version], [mym4_version_major.mym4_version_minor])
m4_define([mym4_revision],
m4_esyscmd([git rev-parse --short HEAD | tr -d '\n\r']))
m4_define([mym4_revision_dec],
@@ -52,10 +54,16 @@ AC_INIT([libgpg-error],[mym4_full_version],[http://bugs.gnupg.org])
LIBGPG_ERROR_LT_CURRENT=8
LIBGPG_ERROR_LT_AGE=8
LIBGPG_ERROR_LT_REVISION=0
+################################################
+
AC_SUBST(LIBGPG_ERROR_LT_CURRENT)
AC_SUBST(LIBGPG_ERROR_LT_AGE)
AC_SUBST(LIBGPG_ERROR_LT_REVISION)
+VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x00" mym4_version_major \
+ mym4_version_minor)
+AC_SUBST(VERSION_NUMBER)
+
AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE
AC_CONFIG_SRCDIR([src/err-sources.h.in])
@@ -170,23 +178,33 @@ if test "$have_w32_system" = yes; then
AC_DEFINE(HAVE_W32CE_SYSTEM,1,[Defined if we run on WindowsCE])
GPG_ERROR_CONFIG_ISUBDIRAFTER="gpg-extra"
fi
- BUILD_TIMESTAMP=`date --iso-8601=minutes`
- changequote(,)dnl
- BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
- changequote([,])dnl
- BUILD_FILEVERSION="${BUILD_FILEVERSION}0,mym4_revision_dec"
fi
-BUILD_REVISION="mym4_revision"
-AC_SUBST(BUILD_TIMESTAMP)
-AC_SUBST(BUILD_FILEVERSION)
-AC_SUBST(BUILD_REVISION)
-AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
- [GIT commit id used to build this package])
AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
AM_CONDITIONAL(HAVE_W64_SYSTEM, test "$have_w64_system" = yes)
AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
+#
+# Provide information about the build.
+#
+BUILD_REVISION="mym4_revision"
+AC_SUBST(BUILD_REVISION)
+AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
+ [GIT commit id revision used to build this package])
+
+changequote(,)dnl
+BUILD_FILEVERSION=`echo "$PACKAGE_VERSION"|sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
+changequote([,])dnl
+BUILD_FILEVERSION="${BUILD_FILEVERSION}0,mym4_revision_dec"
+AC_SUBST(BUILD_FILEVERSION)
+
+BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
+AC_SUBST(BUILD_TIMESTAMP)
+AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
+ [The time this package was configured for a build])
+
+
+
AC_ARG_ENABLE(languages,
[ --disable-languages do not build support for other languages than C])
AM_CONDITIONAL([LANGUAGES_SOME], [test "x$enable_languages" != xno])
diff --git a/src/Makefile.am b/src/Makefile.am
index a84e3f0..cf9a364 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,33 +1,33 @@
# Makefile.am for libgpg-error.
# Copyright (C) 2003, 2004 g10 Code GmbH
-#
+#
# This file is part of libgpg-error.
-#
+#
# libgpg-error is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
-#
+#
# libgpg-error 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 Lesser General Public License for more details.
-#
+#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
# We distribute the generated sources err-sources.h and err-codes.h,
# because they are needed to build the po directory, and they don't
-# depend on the configuration anyway.
+# depend on the configuration anyway.
if HAVE_W32CE_SYSTEM
gpg_extra_headers = gpg-extra/errno.h
extra_cppflags = -idirafter gpg-extra
else
-gpg_extra_headers =
-extra_cppflags =
+gpg_extra_headers =
+extra_cppflags =
endif
localedir = $(datadir)/locale
@@ -47,9 +47,9 @@ EXTRA_DIST = mkstrtable.awk err-sources.h.in err-codes.h.in \
BUILT_SOURCES = err-sources.h err-codes.h code-to-errno.h code-from-errno.h \
err-sources-sym.h err-codes-sym.h errnos-sym.h gpg-error.h \
- gpg-error.def extra-h.in mkw32errmap.map.c
+ gpg-error.def extra-h.in mkw32errmap.map.c
-tmp_files = _mkerrcodes.h _gpg-error.def.h mkw32errmap.tab.h mkw32errmap.map.c
+tmp_files = _mkerrcodes.h _gpg-error.def.h mkw32errmap.tab.h mkw32errmap.map.c
CLEANFILES = err-sources.h err-codes.h code-to-errno.h code-from-errno.h \
gpg-error.h mkerrcodes mkerrcodes.h gpg-error.def mkw32errmap.tab.h \
@@ -79,7 +79,7 @@ uninstall-def-file:
-rm $(DESTDIR)$(libdir)/gpg-error.def
libgpg_error_la_DEPENDENCIES = $(gpg_error_res) gpg-error.def
-intllibs =
+intllibs =
else
arch_sources =
@@ -99,7 +99,8 @@ libgpg_error_la_LDFLAGS = -version-info \
$(no_undefined) $(export_symbols)
libgpg_error_la_SOURCES = gpg-error.h gettext.h $(arch_sources) \
- init.c init.h strsource.c strerror.c code-to-errno.c code-from-errno.c
+ init.c init.h version.c \
+ strsource.c strerror.c code-to-errno.c code-from-errno.c
# Note that RCCOMPILE needs the same defines as ..._la_CPPFLAGS but
# without the extra_cppflags because they may include am -idirafter
@@ -107,7 +108,7 @@ libgpg_error_la_SOURCES = gpg-error.h gettext.h $(arch_sources) \
libgpg_error_la_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" $(extra_cppflags)
libgpg_error_la_LIBADD = $(gpg_error_res) $(intllibs)
-gpg_error_SOURCES = strsource-sym.c strerror-sym.c gpg-error.c
+gpg_error_SOURCES = strsource-sym.c strerror-sym.c gpg-error.c
gpg_error_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" $(extra_cppflags)
gpg_error_LDADD = ./libgpg-error.la @LTLIBINTL@
@@ -185,14 +186,22 @@ errnos-sym.h: Makefile mkstrtable.awk errnos.in
-v prefix=GPG_ERR_ -v namespace=errnos_ \
$(srcdir)/errnos.in >$@
-extra-h.in: Makefile w32-add.h w32ce-add.h
+# We depend on versioninfo.rc because that is build by config.status
+# and thus has up-to-date version numbers.
+extra-h.in: Makefile w32-add.h w32ce-add.h versioninfo.rc
-rm extra-h.in
+ echo "/* The version string of this header. */" >>extra-h.in
+ echo "#define GPG_ERROR_VERSION \"$(PACKAGE_VERSION)\"" >>extra-h.in
+ echo >>extra-h.in
+ echo "/* The version number of this header. */" >>extra-h.in
+ echo "#define GPG_ERROR_VERSION_NUMBER $(VERSION_NUMBER)" >>extra-h.in
+ echo >>extra-h.in
if HAVE_W32_SYSTEM
cat $(srcdir)/w32-add.h >>extra-h.in
-endif
+endif
if HAVE_W32CE_SYSTEM
cat $(srcdir)/w32ce-add.h >>extra-h.in
-endif
+endif
echo EOF >>extra-h.in
gpg-error.h: Makefile mkheader.awk err-sources.h.in err-codes.h.in \
diff --git a/src/gpg-error-config.in b/src/gpg-error-config.in
index df27f0a..b132314 100644
--- a/src/gpg-error-config.in
+++ b/src/gpg-error-config.in
@@ -54,7 +54,7 @@ while test $# -gt 0; do
output="$output $exec_prefix"
;;
--version)
- echo "@VERSION@"
+ echo "@PACKAGE_VERSION@"
exit 0
;;
--cflags)
diff --git a/src/gpg-error.def.in b/src/gpg-error.def.in
index cbabd57..62e0681 100644
--- a/src/gpg-error.def.in
+++ b/src/gpg-error.def.in
@@ -6,8 +6,8 @@
EXPORTS
gpg_strerror @1
- gpg_strerror_r @2
- gpg_strsource @3
+ gpg_strerror_r @2
+ gpg_strsource @3
gpg_err_code_from_errno @4
gpg_err_code_to_errno @5
gpg_err_init @6
@@ -27,3 +27,4 @@ EXPORTS
_gpg_w32_gettext_use_utf8 @17
#endif
gpg_err_deinit @18
+ gpg_error_check_version @19
diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in
index f89945a..303fac0 100644
--- a/src/gpg-error.h.in
+++ b/src/gpg-error.h.in
@@ -1,18 +1,18 @@
/* gpg-error.h - Public interface to libgpg-error.
- Copyright (C) 2003, 2004, 2010 g10 Code GmbH
+ Copyright (C) 2003, 2004, 2010, 2013 g10 Code GmbH
This file is part of libgpg-error.
-
+
libgpg-error is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
-
+
libgpg-error 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
Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
@@ -32,7 +32,7 @@
#else
#ifndef GPG_ERR_INLINE
#define GPG_ERR_INLINE
-#endif
+#endif
#endif
@@ -245,6 +245,9 @@ gpg_err_code_t gpg_err_code_from_syserror (void);
ERRNO due to peculiarities on WindowsCE. */
void gpg_err_set_errno (int err);
+/* Return or check the version. */
+const char *gpg_error_check_version (const char *req_version);
+
@include extra-h.in
/* Self-documenting convenience functions. */
diff --git a/src/version.c b/src/version.c
new file mode 100644
index 0000000..36e2d58
--- /dev/null
+++ b/src/version.c
@@ -0,0 +1,121 @@
+/* version.c - Version checking
+ * Copyright (C) 2001, 2002, 2012, 2013 g10 Code GmbH
+ *
+ * This file is part of libgpg-error.
+ *
+ * libgpg-error is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * libgpg-error 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <gpg-error.h>
+
+
+#define digitp(a) ((a) >= '0' && (a) <= '9')
+
+
+/* This is actually a dummy function to make sure that is module is
+ not empty. Some compilers barf on empty modules. */
+static const char *
+cright_blurb (void)
+{
+ static const char blurb[] =
+ "\n\n"
+ "This is Libgpg-error " PACKAGE_VERSION " - An error code library\n"
+ "Copyright 2003, 2004, 2010, 2013 g10 Code GmbH\n"
+ "\n"
+ "(" BUILD_REVISION " " BUILD_TIMESTAMP ")\n"
+ "\n\n";
+ return blurb;
+}
+
+
+static const char*
+parse_version_number (const char *s, int *number)
+{
+ int val = 0;
+
+ if (*s == '0' && digitp (s[1]))
+ return NULL; /* Leading zeros are not allowed. */
+ for (; digitp (*s); s++)
+ {
+ val *= 10;
+ val += *s - '0';
+ }
+ *number = val;
+ return val < 0 ? NULL : s;
+}
+
+
+static const char *
+parse_version_string (const char *s, int *major, int *minor)
+{
+ s = parse_version_number (s, major);
+ if (!s || *s != '.')
+ return NULL;
+ s++;
+ s = parse_version_number (s, minor);
+ if (!s)
+ return NULL;
+ return s; /* Patchlevel. */
+}
+
+
+static const char *
+compare_versions (const char *my_version, const char *req_version)
+{
+ int my_major, my_minor;
+ int rq_major, rq_minor;
+ const char *my_plvl, *rq_plvl;
+
+ if (!req_version)
+ return my_version;
+ if (!my_version)
+ return NULL;
+
+ my_plvl = parse_version_string (my_version, &my_major, &my_minor);
+ if (!my_plvl)
+ return NULL; /* Very strange: our own version is bogus. */
+ rq_plvl = parse_version_string(req_version, &rq_major, &rq_minor);
+ if (!rq_plvl)
+ return NULL; /* Requested version string is invalid. */
+
+ if (my_major > rq_major
+ || (my_major == rq_major && my_minor >= rq_minor))
+ {
+ return my_version;
+ }
+ return NULL;
+}
+
+
+/*
+ * Check that the the version of the library is at minimum REQ_VERSION
+ * and return the actual version string; return NULL if the condition
+ * is not met. If NULL is passed to this function, no check is done
+ * and the version string is simply returned.
+ */
+const char *
+gpg_error_check_version (const char *req_version)
+{
+ if (req_version && req_version[0] == 1 && req_version[1] == 1)
+ return cright_blurb ();
+ return compare_versions (PACKAGE_VERSION, req_version);
+}
diff --git a/src/versioninfo.rc.in b/src/versioninfo.rc.in
index 284195b..bcf5893 100644
--- a/src/versioninfo.rc.in
+++ b/src/versioninfo.rc.in
@@ -39,12 +39,12 @@ BEGIN
VALUE "FileDescription", "libgpg-error - Common error codes\0"
VALUE "FileVersion", "@LIBGPG_ERROR_LT_CURRENT@.@LIBGPG_ERROR_LT_AGE@.@LIBGPG_ERROR_LT_REVISION@.@BUILD_REVISION@\0"
VALUE "InternalName", "libgpg-error\0"
- VALUE "LegalCopyright", "Copyright © 2012 g10 Code GmbH\0"
+ VALUE "LegalCopyright", "Copyright © 2013 g10 Code GmbH\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "libgpg-error.dll\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "libgpg-error\0"
- VALUE "ProductVersion", "@VERSION@\0"
+ VALUE "ProductVersion", "@PACKAGE_VERSION@\0"
VALUE "SpecialBuild", "@BUILD_TIMESTAMP@\0"
END
END
diff --git a/tests/Makefile.am b/tests/Makefile.am
index be63260..1a27f81 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,18 +1,18 @@
# Makefile.am for libgpg-error/tests.
# Copyright (C) 2003 g10 Code GmbH
-#
+#
# This file is part of libgpg-error.
-#
+#
# libgpg-error is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
-#
+#
# libgpg-error 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 Lesser General Public License for more details.
-#
+#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
@@ -22,11 +22,11 @@
if HAVE_W32CE_SYSTEM
extra_includes = -idirafter $(top_builddir)/src/gpg-extra
else
-extra_includes =
+extra_includes =
endif
-TESTS = t-strerror t-syserror
+TESTS = t-version t-strerror t-syserror
INCLUDES = -I$(top_builddir)/src $(extra_includes)
diff --git a/tests/t-version.c b/tests/t-version.c
new file mode 100644
index 0000000..d6c6399
--- /dev/null
+++ b/tests/t-version.c
@@ -0,0 +1,98 @@
+/* t-version.c - Check the version info function
+ * Copyright (C) 2013 g10 Code GmbH
+ *
+ * This file is part of libgpg-error.
+ *
+ * libgpg-error is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * libgpg-error 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "../src/gpg-error.h"
+
+static const char *logpfx = "";
+static int verbose;
+static int debug;
+static int errorcount;
+
+int
+main (int argc, char **argv)
+{
+ int last_argc = -1;
+
+ if (argc)
+ {
+ logpfx = *argv;
+ argc--; argv++;
+ }
+ while (argc && last_argc != argc )
+ {
+ last_argc = argc;
+ if (!strcmp (*argv, "--help"))
+ {
+ puts (
+"usage: ./version [options]\n"
+"\n"
+"Options:\n"
+" --verbose Show what is going on\n"
+);
+ exit (0);
+ }
+ if (!strcmp (*argv, "--verbose"))
+ {
+ verbose = 1;
+ argc--; argv++;
+ }
+ else if (!strcmp (*argv, "--debug"))
+ {
+ verbose = debug = 1;
+ argc--; argv++;
+ }
+ }
+
+ if (!gpg_error_check_version (GPG_ERROR_VERSION))
+ {
+ fprintf (stderr, "%s: gpg_error_check_version returned an error\n",
+ logpfx);
+ errorcount++;
+ }
+ if (!gpg_error_check_version ("1.10"))
+ {
+ fprintf (stderr, "%s: gpg_error_check_version returned an "
+ "error for an old version\n", logpfx);
+ errorcount++;
+ }
+ if (gpg_error_check_version ("15"))
+ {
+ fprintf (stderr, "gpg_error_check_version did not return an error"
+ " for a newer version\n", logpfx);
+ errorcount++;
+ }
+ if (verbose || errorcount)
+ {
+ printf ("Version from header: %s (0x%06x)\n",
+ GPG_ERROR_VERSION, GPG_ERROR_VERSION_NUMBER);
+ printf ("Version from binary: %s\n", gpg_error_check_version (NULL));
+ printf ("Copyright blurb ...:%s\n", gpg_error_check_version ("\x01\x01"));
+ }
+
+ return errorcount ? 1 : 0;
+}