Internally, our plugins and filters can (and do!) use PACKAGE_VERSION to populate the .version field. But this macro is defined in config.h, which is unsuitable for installation in /usr/include, so external plugin authors cannot use it. It is worth letting our public interface include a version designation (ideally, users should NOT be basing compile-time decisions solely on what version they are compiling against, but instead using actual feature tests, but we weren't even allowing for a version check).
The addition is done in such as way as to continue to allow version bumps to touch a single place in configure.ac and have that propagate to all affected files. Signed-off-by: Eric Blake <[email protected]> --- configure.ac | 15 ++++++++++++- include/nbdkit-common.h | 2 ++ .gitignore | 1 + include/Makefile.am | 1 + include/nbdkit-version.h.in | 45 +++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 include/nbdkit-version.h.in diff --git a/configure.ac b/configure.ac index ac8b4ba7..1667cb3f 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,11 @@ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. -AC_INIT([nbdkit], [1.13.9]) +m4_define([NBDKIT_VERSION_MAJOR], [1]) +m4_define([NBDKIT_VERSION_MINOR], [13]) +m4_define([NBDKIT_VERSION_MICRO], [9]) +AC_INIT([nbdkit], + NBDKIT_VERSION_MAJOR.NBDKIT_VERSION_MINOR.NBDKIT_VERSION_MICRO) AC_CONFIG_MACRO_DIR([m4]) m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],[], [m4_define([AC_USE_SYSTEM_EXTENSIONS],[])]) @@ -45,6 +49,14 @@ AC_CANONICAL_HOST AC_PROG_SED +dnl Expose version information to the public headers +[NBDKIT_]VERSION_MAJOR=NBDKIT_VERSION_MAJOR +[NBDKIT_]VERSION_MINOR=NBDKIT_VERSION_MINOR +[NBDKIT_]VERSION_MICRO=NBDKIT_VERSION_MICRO +AC_SUBST([NBDKIT_VERSION_MAJOR]) +AC_SUBST([NBDKIT_VERSION_MINOR]) +AC_SUBST([NBDKIT_VERSION_MICRO]) + dnl Check for basic C environment. AC_PROG_CC_STDC AC_PROG_INSTALL @@ -891,6 +903,7 @@ AC_CONFIG_FILES([Makefile common/utils/Makefile docs/Makefile include/Makefile + include/nbdkit-version.h plugins/Makefile plugins/curl/Makefile plugins/data/Makefile diff --git a/include/nbdkit-common.h b/include/nbdkit-common.h index e004aa18..3a62b47e 100644 --- a/include/nbdkit-common.h +++ b/include/nbdkit-common.h @@ -41,6 +41,8 @@ #include <stdint.h> #include <errno.h> +#include <nbdkit-version.h> + #ifdef __cplusplus extern "C" { #endif diff --git a/.gitignore b/.gitignore index 15620626..464a860d 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ Makefile.in /docs/plugin-links.pod /fuzzing/sync_dir/ /html/*.html +/include/nbdkit-version.h /INSTALL /install-sh /libtool diff --git a/include/Makefile.am b/include/Makefile.am index 3a293359..cf46abc6 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -35,4 +35,5 @@ include_HEADERS = \ nbdkit-common.h \ nbdkit-plugin.h \ nbdkit-filter.h \ + nbdkit-version.h \ $(NULL) diff --git a/include/nbdkit-version.h.in b/include/nbdkit-version.h.in new file mode 100644 index 00000000..38bbf0d2 --- /dev/null +++ b/include/nbdkit-version.h.in @@ -0,0 +1,45 @@ +/* nbdkit + * Copyright (C) 2013-2019 Red Hat Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Red Hat nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef NBDKIT_VERSION_H +#define NBDKIT_VERSION_H + +#if !defined (NBDKIT_PLUGIN_H) && !defined (NBDKIT_FILTER_H) +#error this header file should not be directly included +#endif + +#define NBDKIT_VERSION_MAJOR @NBDKIT_VERSION_MAJOR@ +#define NBDKIT_VERSION_MINOR @NBDKIT_VERSION_MINOR@ +#define NBDKIT_VERSION_MICRO @NBDKIT_VERSION_MICRO@ +#define NBDKIT_VERSION_STRING "@NBDKIT_VERSION_MAJOR@.@NBDKIT_VERSION_MINOR@.@NBDKIT_VERSION_MICRO@" + +#endif /* NBDKIT_VERSION_H */ -- 2.21.0 _______________________________________________ Libguestfs mailing list [email protected] https://www.redhat.com/mailman/listinfo/libguestfs
