aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile15
-rw-r--r--meson.build8
-rw-r--r--src/libslirp-version.h.in23
-rw-r--r--src/libslirp.h4
-rw-r--r--src/util.h3
-rw-r--r--src/version.c11
6 files changed, 63 insertions, 1 deletions
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 <arpa/inet.h>
#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 <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..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);
+}