Browse Source

build: add ability to specify shared object version

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Jo-Philipp Wich 5 months ago
parent
commit
23d2722b12
1 changed files with 12 additions and 3 deletions
  1. 12 3
      Makefile

+ 12 - 3
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: