From c00283ebd0db1b17d7333c5811878f2f614a723d Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 31 May 2019 16:39:02 +0900 Subject: [PATCH] Add version macros Added macros: * SECRET_VERSION_MAJOR * SECRET_VERSION_MINOR * SECRET_VERSION_MICRO * SECRET_CHECK_VERSION These macros are widely defined in GLib based library. For example, GLib, GTK, poppler GLib and so on define them. These macros are useful to detect libsecret version on build type and from GObject Introspection based bindings. --- .gitignore | 1 + configure.ac | 12 +++- docs/reference/libsecret/libsecret-docs.sgml | 1 + .../libsecret/libsecret-sections.txt | 8 +++ libsecret/Makefile.am | 8 ++- libsecret/meson.build | 14 ++++ libsecret/secret-version.h.in | 65 +++++++++++++++++++ libsecret/secret.h | 1 + 8 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 libsecret/secret-version.h.in diff --git a/.gitignore b/.gitignore index 0c8c394..5f2e41a 100644 --- a/.gitignore +++ b/.gitignore @@ -73,6 +73,7 @@ stamp* /libsecret/*-dbus-generated.[ch] /libsecret/secret-enum-types.[ch] +/libsecret/secret-version.h /libsecret/tests/test-* /libsecret/tests/*.metadata !/libsecret/tests/test-*.c diff --git a/configure.ac b/configure.ac index 05fe195..1ce2375 100644 --- a/configure.ac +++ b/configure.ac @@ -1,9 +1,18 @@ AC_PREREQ(2.63) -AC_INIT([libsecret],[0.18.8], +m4_define([libsecret_major_version], 0) +m4_define([libsecret_minor_version], 18) +m4_define([libsecret_micro_version], 8) +m4_define([libsecret_version], + [libsecret_major_version.libsecret_minor_version.libsecret_micro_version]) +AC_INIT([libsecret],[libsecret_version], [https://gitlab.gnome.org/GNOME/libsecret/issues/], [libsecret]) +AC_SUBST(SECRET_MAJOR_VERSION, libsecret_major_version) +AC_SUBST(SECRET_MINOR_VERSION, libsecret_minor_version) +AC_SUBST(SECRET_MICRO_VERSION, libsecret_micro_version) + dnl **************************************************************************** dnl Dependency versions @@ -281,6 +290,7 @@ AC_CONFIG_FILES([ po/Makefile libsecret/libsecret.pc libsecret/libsecret-unstable.pc + libsecret/secret-version.h ]) AC_OUTPUT diff --git a/docs/reference/libsecret/libsecret-docs.sgml b/docs/reference/libsecret/libsecret-docs.sgml index 92e6346..6ce3dba 100644 --- a/docs/reference/libsecret/libsecret-docs.sgml +++ b/docs/reference/libsecret/libsecret-docs.sgml @@ -31,6 +31,7 @@ + diff --git a/docs/reference/libsecret/libsecret-sections.txt b/docs/reference/libsecret/libsecret-sections.txt index de28b3b..2ae7250 100644 --- a/docs/reference/libsecret/libsecret-sections.txt +++ b/docs/reference/libsecret/libsecret-sections.txt @@ -337,3 +337,11 @@ secret_attributes_buildv
SecretGenPrompt
+ +
+secret-version +SECRET_CHECK_VERSION +SECRET_MAJOR_VERSION +SECRET_MICRO_VERSION +SECRET_MINOR_VERSION +
diff --git a/libsecret/Makefile.am b/libsecret/Makefile.am index 3dff582..c91b733 100644 --- a/libsecret/Makefile.am +++ b/libsecret/Makefile.am @@ -22,6 +22,7 @@ libsecret_HEADS = \ inc_HEADERS = \ $(libsecret_HEADS) \ libsecret/secret-enum-types.h \ + libsecret/secret-version.h \ $(NULL) libsecret_BUILT_ENUMS = \ @@ -31,6 +32,7 @@ libsecret_BUILT_ENUMS = \ libsecret_BUILT = \ secret-dbus-generated.c secret-dbus-generated.h \ $(libsecret_BUILT_ENUMS) \ + libsecret/secret-version.h \ $(NULL) libsecret_PUBLIC = \ @@ -121,7 +123,11 @@ Secret_@SECRET_MAJOR@_gir_EXPORT_PACKAGES = libsecret-@SECRET_MAJOR@ Secret_@SECRET_MAJOR@_gir_INCLUDES = GObject-2.0 Gio-2.0 Secret_@SECRET_MAJOR@_gir_LIBS = libsecret-@SECRET_MAJOR@.la Secret_@SECRET_MAJOR@_gir_CFLAGS = -I$(srcdir) -I$(builddir) -DSECRET_COMPILATION -Secret_@SECRET_MAJOR@_gir_FILES = $(libsecret_PUBLIC) $(libsecret_BUILT_ENUMS) +Secret_@SECRET_MAJOR@_gir_FILES = \ + $(libsecret_PUBLIC) \ + $(libsecret_BUILT_ENUMS) \ + libsecret/secret-version.h \ + $(NULL) Secret_@SECRET_MAJOR@_gir_SCANNERFLAGS = --c-include "libsecret/secret.h" gir_DATA += Secret-@SECRET_MAJOR@.gir diff --git a/libsecret/meson.build b/libsecret/meson.build index 590694e..f35c396 100644 --- a/libsecret/meson.build +++ b/libsecret/meson.build @@ -31,6 +31,19 @@ libsecret_headers = [ 'secret-value.h', ] +version_numbers = meson.project_version().split('.') +version_major = version_numbers[0].to_int() +version_minor = version_numbers[1].to_int() +version_micro = version_numbers[2].to_int() +version_h_conf = configuration_data() +version_h_conf.set('SECRET_MAJOR_VERSION', version_major) +version_h_conf.set('SECRET_MINOR_VERSION', version_minor) +version_h_conf.set('SECRET_MICRO_VERSION', version_micro) +version_h = configure_file(input: 'secret-version.h.in', + output: 'secret-version.h', + configuration: version_h_conf) +libsecret_headers += version_h + _dbus_generated = gnome.gdbus_codegen('secret-dbus-generated', sources: 'org.freedesktop.Secrets.xml', interface_prefix: 'org.freedesktop.Secret.', @@ -101,6 +114,7 @@ libsecret_gir_sources = [ 'secret-value.c', 'secret-value.h', ] +libsecret_gir_sources += version_h libsecret_gir_sources += _enums_generated libsecret_gir = gnome.generate_gir(libsecret, diff --git a/libsecret/secret-version.h.in b/libsecret/secret-version.h.in new file mode 100644 index 0000000..30a8389 --- /dev/null +++ b/libsecret/secret-version.h.in @@ -0,0 +1,65 @@ +/* libsecret - GLib wrapper for Secret Service + * + * Copyright 2019 Sutou Kouhei + * + * This program 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 licence or (at + * your option) any later version. + * + * See the included COPYING file for more information. + * + * Author: Sutou Kouhei + */ + +#if !defined (__SECRET_INSIDE_HEADER__) && !defined (SECRET_COMPILATION) +#error "Only can be included directly." +#endif + +#pragma __once__ + +/** + * SECTION:secret-version + * @short_description: Variables and macros to check the libsecret version + * @title: Version Information + * + * Stability: Stable + */ + +/** + * SECRET_MAJOR_VERSION: + * + * The major version of libsecret. + */ +#define SECRET_MAJOR_VERSION (@SECRET_MAJOR_VERSION@) + +/** + * SECRET_MINOR_VERSION: + * + * The minor version of libsecret. + */ +#define SECRET_MINOR_VERSION (@SECRET_MINOR_VERSION@) + +/** + * SECRET_MICRO_VERSION: + * + * The micro version of libsecret. + */ +#define SECRET_MICRO_VERSION (@SECRET_MICRO_VERSION@) + +/** + * SECRET_CHECK_VERSION: + * @major: major version to be satisfied + * @minor: minor version to be satisfied + * @micro: micro version to be satisfied + * + * Returns: %TRUE if using libsecret is newer than or equal to the + * given version + */ +#define SECRET_CHECK_VERSION(major, minor, micro) \ + (SECRET_MAJOR_VERSION > (major) || \ + (SECRET_MAJOR_VERSION == (major) && \ + SECRET_MINOR_VERSION > (minor)) || \ + (SECRET_MAJOR_VERSION == (major) && \ + SECRET_MINOR_VERSION == (minor) && \ + SECRET_MICRO_VERSION >= (micro))) diff --git a/libsecret/secret.h b/libsecret/secret.h index 12c22f6..8d11324 100644 --- a/libsecret/secret.h +++ b/libsecret/secret.h @@ -30,6 +30,7 @@ #include #include #include +#include /* SECRET_WITH_UNSTABLE is defined in the secret-unstable.pc pkg-config file */ #if defined(SECRET_WITH_UNSTABLE) || defined(SECRET_API_SUBJECT_TO_CHANGE)