Skip to content

Commit c39ac36

Browse files
committed
build-sys: add version tooling
Add SLIRP_CHECK_VERSION() macro, and slirp_version_string() helpers. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 2898b00 commit c39ac36

File tree

6 files changed

+63
-1
lines changed

6 files changed

+63
-1
lines changed

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
22
BUILD_DIR ?= .
33

44
LIBSLIRP = $(BUILD_DIR)/libslirp.a
5+
SLIRP_MAJOR_VERSION = 4
6+
SLIRP_MINOR_VERSION = 0
7+
SLIRP_MICRO_VERSION = 0
58

69
all: $(LIBSLIRP)
710

@@ -19,12 +22,22 @@ override CFLAGS += \
1922
-MMD -MP
2023
override LDFLAGS += $(shell $(PKG_CONFIG) --libs glib-2.0)
2124

25+
$(BUILD_DIR)/src/libslirp-version.h:
26+
@$(MKDIR_P) $(dir $@)
27+
$(call quiet-command,cat $(ROOT_DIR)/src/libslirp-version.h.in | \
28+
sed 's/@SLIRP_MAJOR_VERSION@/$(SLIRP_MAJOR_VERSION)/' | \
29+
sed 's/@SLIRP_MINOR_VERSION@/$(SLIRP_MINOR_VERSION)/' | \
30+
sed 's/@SLIRP_MICRO_VERSION@/$(SLIRP_MICRO_VERSION)/' \
31+
> $@,"GEN","$@")
32+
33+
$(OBJS): $(BUILD_DIR)/src/libslirp-version.h
34+
2235
$(LIBSLIRP): $(OBJS)
2336

2437
.PHONY: clean
2538

2639
clean:
27-
rm -r $(OBJS) $(DEPS) $(LIBSLIRP)
40+
rm -r $(OBJS) $(DEPS) $(LIBSLIRP) $(BUILD_DIR)/src/libslirp-version.h
2841

2942
$(BUILD_DIR)/src/%.o: $(ROOT_DIR)/src/%.c
3043
@$(MKDIR_P) $(dir $@)

meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,20 @@ sources = [
8686
'src/udp.c',
8787
'src/udp6.c',
8888
'src/util.c',
89+
'src/version.c',
8990
'src/vmstate.c',
9091
]
9192

9293
mapfile = 'src/libslirp.map'
9394
vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
9495

96+
configure_file(
97+
input : 'src/libslirp-version.h.in',
98+
output : 'libslirp-version.h',
99+
install_dir : join_paths(get_option('includedir'), 'slirp'),
100+
configuration : conf
101+
)
102+
95103
lib = shared_library('slirp', sources,
96104
soversion : lt_current,
97105
version : lt_version,

src/libslirp-version.h.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause */
2+
#ifndef LIBSLIRP_VERSION_H_
3+
#define LIBSLIRP_VERSION_H_
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
#define SLIRP_MAJOR_VERSION @SLIRP_MAJOR_VERSION@
10+
#define SLIRP_MINOR_VERSION @SLIRP_MINOR_VERSION@
11+
#define SLIRP_MICRO_VERSION @SLIRP_MICRO_VERSION@
12+
13+
#define SLIRP_CHECK_VERSION(major,minor,micro) \
14+
(SLIRP_MAJOR_VERSION > (major) || \
15+
(SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION > (minor)) || \
16+
(SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION == (minor) && \
17+
SLIRP_MICRO_VERSION >= (micro)))
18+
19+
#ifdef __cplusplus
20+
} /* extern "C" */
21+
#endif
22+
23+
#endif /* LIBSLIRP_VERSION_H_ */

src/libslirp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <arpa/inet.h>
1515
#endif
1616

17+
#include "libslirp-version.h"
18+
1719
#ifdef __cplusplus
1820
extern "C" {
1921
#endif
@@ -108,6 +110,8 @@ int slirp_state_load(Slirp *s, int version_id, SlirpReadCb read_cb,
108110

109111
int slirp_state_version(void);
110112

113+
const char *slirp_version_string(void);
114+
111115
#ifdef __cplusplus
112116
} /* extern "C" */
113117
#endif

src/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ struct iovec {
7272
#include <sys/uio.h>
7373
#endif
7474

75+
#define stringify(s) tostring(s)
76+
#define tostring(s) #s
77+
7578
#define SCALE_MS 1000000
7679

7780
#define ETH_ALEN 6

src/version.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause */
2+
#include "libslirp.h"
3+
#include "util.h"
4+
5+
const char *
6+
slirp_version_string(void)
7+
{
8+
return stringify(SLIRP_MAJOR_VERSION) "."
9+
stringify(SLIRP_MINOR_VERSION) "."
10+
stringify(SLIRP_MICRO_VERSION);
11+
}

0 commit comments

Comments
 (0)