Add soname versioning to the dynamic library.

Issue: #340
This commit is contained in:
John McNamara 2021-06-25 00:01:52 +01:00
parent dcf8d418db
commit 9a5ee07d48
6 changed files with 30 additions and 12 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
*.a
*.o
*.so
*.so.*
*.to
*.lo
*.la

View File

@ -191,8 +191,10 @@ endif()
# Configure pkg-config
file(READ "include/xlsxwriter.h" ver)
string(REGEX MATCH "VERSION .*\"\(.*\)\".*" _ ${ver})
string(REGEX MATCH "LXW_VERSION .*\"\(.*\)\".*" _ ${ver})
set(VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "LXW_SOVERSION .*\"\(.*\)\".*" _ ${ver})
set(SOVERSION ${CMAKE_MATCH_1})
set(PREFIX ${CMAKE_INSTALL_PREFIX})
configure_file(dev/release/pkg-config.txt xlsxwriter.pc @ONLY)
@ -252,6 +254,7 @@ endif()
set(LXW_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(LXW_LIB_DIR "${LXW_PROJECT_DIR}/lib")
add_library(${PROJECT_NAME} "")
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${SOVERSION})
target_sources(${PROJECT_NAME}
PRIVATE ${LXW_SOURCES}
PUBLIC ${LXW_HEADERS}

View File

@ -17,13 +17,15 @@ PREFIX ?= /usr/local
PYTEST ?= py.test
PYTESTFILES ?= test
VERSION = $(shell sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < include/xlsxwriter.h)
VERSION = $(shell sed -n -e 's/.*LXW_VERSION \"\(.*\)\"/\1/p' include/xlsxwriter.h)
SOVERSION = $(shell sed -n -e 's/.*LXW_SOVERSION \"\(.*\)\"/\1/p' include/xlsxwriter.h)
.PHONY: docs tags examples third_party
# Build libxlsxwriter.
all : third_party
$(Q)$(MAKE) -C src
$(Q)$(MAKE) -C src SOVERSION=$(SOVERSION)
# Build the third party libs.
third_party :
@ -57,7 +59,7 @@ universal_binary :
$(Q)lipo -create -output lib/libxlsxwriter.dylib lib/libxlsxwriter_x86_64.dylib lib/libxlsxwriter_arm64.dylib
# Build the example programs.
examples :
examples : all
$(Q)$(MAKE) -C examples
# Clean src and test directories.
@ -141,7 +143,7 @@ install: all
$(Q)mkdir -p $(DESTDIR)$(PREFIX)/include
$(Q)cp -R include/* $(DESTDIR)$(PREFIX)/include
$(Q)mkdir -p $(DESTDIR)$(PREFIX)/lib
$(Q)cp lib/* $(DESTDIR)$(PREFIX)/lib
$(Q)cp -R lib/* $(DESTDIR)$(PREFIX)/lib
$(Q)mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig
$(Q)sed -e 's|@PREFIX@|$(PREFIX)|g' -e 's|@VERSION@|$(VERSION)|g' dev/release/pkg-config.txt > $(DESTDIR)$(PREFIX)/lib/pkgconfig/xlsxwriter.pc

View File

@ -121,9 +121,10 @@ function check_versions {
clear
echo
echo "Latest file versions: "
echo
grep -He "[0-9]\.[0-9]\.[0-9]" include/xlsxwriter.h libxlsxwriter.podspec | sed 's/:/ : /g' | awk '{printf " | %-24s %s\n", $1, $5}'
grep -He "LXW_VERSION_ID [0-9][0-9]" include/xlsxwriter.h | sed 's/:/ : /g' | awk '{printf " | %-24s %s\n", $1, $5}'
awk '/s.version / {print "\t" FILENAME "\t" $1 "\t" $3}' libxlsxwriter.podspec
awk '/ LXW/ {print "\t" FILENAME "\t" $2 "\t" $3}' include/xlsxwriter.h
echo
echo -n "Are the versions up to date? [y/N]: "

View File

@ -20,5 +20,6 @@
#define LXW_VERSION "1.0.6"
#define LXW_VERSION_ID 106
#define LXW_SOVERSION "2"
#endif /* __LXW_XLSXWRITER_H__ */

View File

@ -81,7 +81,7 @@ endif
# Library names.
LIBXLSXWRITER_A = libxlsxwriter.a
LIBXLSXWRITER_SO = libxlsxwriter.so
LIBXLSXWRITER_SO = libxlsxwriter.so.$(SOVERSION)
# Library with additional non-static functions for testing.
LIBXLSXWRITER_TO = libxlsxwriter_test.a
@ -91,15 +91,15 @@ ARFLAGS = rc
# Flags passed to dynamic linker.
FPIC = -fPIC
SOFLAGS = -shared $(FPIC)
SOFLAGS = -shared $(FPIC) -Wl,-soname,LIBXLSXWRITER_SO
# Get Env/OS name.
UNAME := $(shell uname)
# Change make options on OS X.
ifeq ($(UNAME), Darwin)
LIBXLSXWRITER_SO = libxlsxwriter.dylib
SOFLAGS = -dynamiclib $(FPIC) -install_name $(PREFIX)/lib/$(LIBXLSXWRITER_SO) $(GCOV)
LIBXLSXWRITER_SO = libxlsxwriter.$(SOVERSION).dylib
SOFLAGS = -dynamiclib $(FPIC) -compatibility_version $(SOVERSION) -install_name $(PREFIX)/lib/$(LIBXLSXWRITER_SO) $(GCOV)
endif
# Check for MinGW/MinGW64/Cygwin environments.
@ -135,6 +135,16 @@ TOBJS = $(patsubst %.c,%.to,$(SRCS))
all : $(LIBXLSXWRITER_A) $(LIBXLSXWRITER_SO)
$(Q)cp $(LIBXLSXWRITER_A) $(LIBXLSXWRITER_SO) ../lib
ifeq ($(UNAME), Darwin)
$(Q)rm -f ../lib/libxlsxwriter.dylib
$(Q)ln -s $(LIBXLSXWRITER_SO) ../lib/libxlsxwriter.dylib
endif
ifneq ($(UNAME), Darwin)
$(Q)rm -f ../lib/libxlsxwriter.so
$(Q)ln -s $(LIBXLSXWRITER_SO) ../lib/libxlsxwriter.so
endif
test_lib : libxlsxwriter_test.a
# The static library.
@ -169,4 +179,4 @@ test_compile : $(OBJS)
# Clean up any temp/build files.
clean :
$(Q)rm -f *.o *.a *.so *.to *.dylib *.dll *.gcno *.gcda
$(Q)rm -f *.o *.a *.so *.so.* *.to *.dylib *.dll *.gcno *.gcda