From: Marc-André Lureau <marcandre.lur...@redhat.com> Add SLIRP_CHECK_VERSION() macro, and a slirp_version_string() helpers.
Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> --- meson.build | 13 +++++++++++++ src/libslirp-version.h.in | 22 ++++++++++++++++++++++ src/libslirp.h | 5 +++++ src/util.h | 3 +++ src/version.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 src/libslirp-version.h.in create mode 100644 src/version.c diff --git a/meson.build b/meson.build index d53d17a..ec0a0dd 100644 --- a/meson.build +++ b/meson.build @@ -10,6 +10,11 @@ major_version = varr[0] minor_version = varr[1] micro_version = varr[2] +conf = configuration_data() +conf.set('SLIRP_MAJOR_VERSION', major_version) +conf.set('SLIRP_MINOR_VERSION', minor_version) +conf.set('SLIRP_MICRO_VERSION', micro_version) + # libtool versioning - this applies to libpackagekit # # See http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91 for details @@ -79,11 +84,19 @@ sources = [ 'src/udp.c', 'src/udp6.c', 'src/util.c', + 'src/version.c', ] mapfile = 'src/libslirp.map' vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile) +configure_file( + input : 'src/libslirp-version.h.in', + output : 'libslirp-version.h', + install_dir : join_paths(get_option('includedir'), 'slirp'), + configuration : conf +) + lib = shared_library('slirp', sources, soversion : lt_current, version : lt_version, diff --git a/src/libslirp-version.h.in b/src/libslirp-version.h.in new file mode 100644 index 0000000..e7d56f1 --- /dev/null +++ b/src/libslirp-version.h.in @@ -0,0 +1,22 @@ +#ifndef LIBSLIRP_VERSION_H_ +#define LIBSLIRP_VERSION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define SLIRP_MAJOR_VERSION @SLIRP_MAJOR_VERSION@ +#define SLIRP_MINOR_VERSION @SLIRP_MINOR_VERSION@ +#define SLIRP_MICRO_VERSION @SLIRP_MICRO_VERSION@ + +#define SLIRP_CHECK_VERSION(major,minor,micro) \ + (SLIRP_MAJOR_VERSION > (major) || \ + (SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION > (minor)) || \ + (SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION == (minor) && \ + SLIRP_MICRO_VERSION >= (micro))) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* LIBSLIRP_VERSION_H_ */ diff --git a/src/libslirp.h b/src/libslirp.h index c6cb6a9..8008bd9 100644 --- a/src/libslirp.h +++ b/src/libslirp.h @@ -12,6 +12,8 @@ #include <arpa/inet.h> #endif +#include "libslirp-version.h" + #ifdef __cplusplus extern "C" { #endif @@ -97,6 +99,9 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port, const uint8_t *buf, int size); size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port); + +const char *slirp_version_string(void); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/util.h b/src/util.h index a9c4e32..82b1901 100644 --- a/src/util.h +++ b/src/util.h @@ -71,6 +71,9 @@ struct iovec { #include <sys/uio.h> #endif +#define stringify(s) tostring(s) +#define tostring(s) #s + #define SCALE_MS 1000000 #define ETH_ALEN 6 diff --git a/src/version.c b/src/version.c new file mode 100644 index 0000000..1a1d51e --- /dev/null +++ b/src/version.c @@ -0,0 +1,33 @@ +/* + * libslirp version + * + * Copyright (c) 2018 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "libslirp.h" +#include "util.h" + +const char * +slirp_version_string(void) +{ + return stringify(SLIRP_MAJOR_VERSION) "." + stringify(SLIRP_MINOR_VERSION) "." + stringify(SLIRP_MICRO_VERSION); +} -- 2.21.0.rc0.1.g036caf7885