From c39ac36e669e3dd5350761c29e774a8329604ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 8 Feb 2019 17:54:00 +0100 Subject: build-sys: add version tooling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add SLIRP_CHECK_VERSION() macro, and slirp_version_string() helpers. Signed-off-by: Marc-André Lureau --- Makefile | 15 ++++++++++++++- meson.build | 8 ++++++++ src/libslirp-version.h.in | 23 +++++++++++++++++++++++ src/libslirp.h | 4 ++++ src/util.h | 3 +++ src/version.c | 11 +++++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/libslirp-version.h.in create mode 100644 src/version.c diff --git a/Makefile b/Makefile index 6d48f62..7f09879 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) BUILD_DIR ?= . LIBSLIRP = $(BUILD_DIR)/libslirp.a +SLIRP_MAJOR_VERSION = 4 +SLIRP_MINOR_VERSION = 0 +SLIRP_MICRO_VERSION = 0 all: $(LIBSLIRP) @@ -19,12 +22,22 @@ override CFLAGS += \ -MMD -MP override LDFLAGS += $(shell $(PKG_CONFIG) --libs glib-2.0) +$(BUILD_DIR)/src/libslirp-version.h: + @$(MKDIR_P) $(dir $@) + $(call quiet-command,cat $(ROOT_DIR)/src/libslirp-version.h.in | \ + sed 's/@SLIRP_MAJOR_VERSION@/$(SLIRP_MAJOR_VERSION)/' | \ + sed 's/@SLIRP_MINOR_VERSION@/$(SLIRP_MINOR_VERSION)/' | \ + sed 's/@SLIRP_MICRO_VERSION@/$(SLIRP_MICRO_VERSION)/' \ + > $@,"GEN","$@") + +$(OBJS): $(BUILD_DIR)/src/libslirp-version.h + $(LIBSLIRP): $(OBJS) .PHONY: clean clean: - rm -r $(OBJS) $(DEPS) $(LIBSLIRP) + rm -r $(OBJS) $(DEPS) $(LIBSLIRP) $(BUILD_DIR)/src/libslirp-version.h $(BUILD_DIR)/src/%.o: $(ROOT_DIR)/src/%.c @$(MKDIR_P) $(dir $@) diff --git a/meson.build b/meson.build index ef68b88..287802b 100644 --- a/meson.build +++ b/meson.build @@ -86,12 +86,20 @@ sources = [ 'src/udp.c', 'src/udp6.c', 'src/util.c', + 'src/version.c', 'src/vmstate.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..59f7a46 --- /dev/null +++ b/src/libslirp-version.h.in @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +#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 bcd2974..9b2f611 100644 --- a/src/libslirp.h +++ b/src/libslirp.h @@ -14,6 +14,8 @@ #include #endif +#include "libslirp-version.h" + #ifdef __cplusplus extern "C" { #endif @@ -108,6 +110,8 @@ int slirp_state_load(Slirp *s, int version_id, SlirpReadCb read_cb, int slirp_state_version(void); +const char *slirp_version_string(void); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/util.h b/src/util.h index 1ef08ae..0d59559 100644 --- a/src/util.h +++ b/src/util.h @@ -72,6 +72,9 @@ struct iovec { #include #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..a837323 --- /dev/null +++ b/src/version.c @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +#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); +} -- cgit v1.1