build: add ability to specify shared object version
authorJo-Philipp Wich <jo@mein.io>
Wed, 6 Jan 2021 22:12:46 +0000 (23:12 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 6 Jan 2021 23:47:37 +0000 (23:47 +0000)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Makefile

index 715c03e34671401c6e82f72d78f703b725db9e0e..57b6a09b9fc36fa70ed1e7d2436aa59dbf1e0a8f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,11 @@
+IWINFO_SOVERSION   = $(if $(SOVERSION),$(SOVERSION),0)
+
 IWINFO_BACKENDS    = $(BACKENDS)
 IWINFO_CFLAGS      = $(CFLAGS) -std=gnu99 -fstrict-aliasing -Iinclude
 IWINFO_LDFLAGS     = -luci -lubox -lubus
 
 IWINFO_LIB         = libiwinfo.so
-IWINFO_LIB_LDFLAGS = $(LDFLAGS) -shared
+IWINFO_LIB_LDFLAGS = $(LDFLAGS) -shared -Wl,-soname -Wl,$(IWINFO_LIB).$(IWINFO_SOVERSION)
 IWINFO_LIB_OBJ     = iwinfo_utils.o iwinfo_wext.o iwinfo_wext_scan.o iwinfo_lib.o
 
 IWINFO_LUA         = iwinfo.so
@@ -33,12 +35,19 @@ ifneq ($(filter nl80211,$(IWINFO_BACKENDS)),)
 endif
 
 
+compile: clean $(IWINFO_LIB) $(IWINFO_LUA) $(IWINFO_CLI)
+
 %.o: %.c
        $(CC) $(IWINFO_CFLAGS) $(FPIC) -c -o $@ $<
 
-compile: clean $(IWINFO_LIB_OBJ) $(IWINFO_LUA_OBJ) $(IWINFO_CLI_OBJ)
-       $(CC) $(IWINFO_LDFLAGS) $(IWINFO_LIB_LDFLAGS) -o $(IWINFO_LIB) $(IWINFO_LIB_OBJ)
+$(IWINFO_LIB): $(IWINFO_LIB_OBJ)
+       $(CC) $(IWINFO_LDFLAGS) $(IWINFO_LIB_LDFLAGS) -o $(IWINFO_LIB).$(IWINFO_SOVERSION) $(IWINFO_LIB_OBJ) && \
+       ln -sf $(IWINFO_LIB).$(IWINFO_SOVERSION) $(IWINFO_LIB)
+
+$(IWINFO_LUA): $(IWINFO_LUA_OBJ)
        $(CC) $(IWINFO_LDFLAGS) $(IWINFO_LUA_LDFLAGS) -o $(IWINFO_LUA) $(IWINFO_LUA_OBJ)
+
+$(IWINFO_CLI): $(IWINFO_CLI_OBJ)
        $(CC) $(IWINFO_LDFLAGS) $(IWINFO_CLI_LDFLAGS) -o $(IWINFO_CLI) $(IWINFO_CLI_OBJ)
 
 clean: