ref: 3f69873c9969961a59cdd4a491487175a0b1f0b4
parent: e1262a9ac97b614d9c7fc66e42baa6f97c065409
author: Nirbheek Chauhan <nirbheek@centricular.com>
date: Thu Nov 13 13:48:33 EST 2014
Makefile: Fix shared library building on various OSes Versioned for OS not in (Windows, Android), and create a .dll.a implib on Windows
--- a/Makefile
+++ b/Makefile
@@ -54,6 +54,7 @@
LDFLAGS += -fsanitize=address
endif
+SHAREDLIBVERSION=0
include $(SRC_PATH)build/platform-$(OS).mk
@@ -179,24 +180,28 @@
endif
ifneq (ios, $(OS))
-libraries: $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX)
+libraries: $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXVER)
else
libraries: $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX)
endif
-LIBRARIES += $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX)
+LIBRARIES += $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXVER)
$(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX): $(ENCODER_OBJS) $(DECODER_OBJS) $(PROCESSING_OBJS) $(COMMON_OBJS)
$(QUIET)rm -f $@
$(QUIET_AR)$(AR) $(AR_OPTS) $+
-$(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX): $(ENCODER_OBJS) $(DECODER_OBJS) $(PROCESSING_OBJS) $(COMMON_OBJS)
+$(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXVER): $(ENCODER_OBJS) $(DECODER_OBJS) $(PROCESSING_OBJS) $(COMMON_OBJS)
$(QUIET)rm -f $@
$(QUIET_CXX)$(CXX) $(SHARED) $(CXX_LINK_O) $+ $(LDFLAGS) $(SHLDFLAGS)
+ if [ "$(SHAREDLIBSUFFIXVER)" != "$(SHAREDLIBSUFFIX)" ]; then \
+ ln -sfn $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXVER) \
+ $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX); \
+ fi
ifeq ($(HAVE_GMP_API),Yes)
-plugin: $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIX)
-LIBRARIES += $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIX)
+plugin: $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIXVER)
+LIBRARIES += $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIXVER)
else
plugin:
@echo "./gmp-api : No such file or directory."
@@ -203,9 +208,13 @@
@echo "You do not have gmp-api. Run make gmp-bootstrap to get the gmp-api headers."
endif
-$(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIX): $(MODULE_OBJS) $(ENCODER_OBJS) $(DECODER_OBJS) $(PROCESSING_OBJS) $(COMMON_OBJS)
+$(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIXVER): $(MODULE_OBJS) $(ENCODER_OBJS) $(DECODER_OBJS) $(PROCESSING_OBJS) $(COMMON_OBJS)
$(QUIET)rm -f $@
$(QUIET_CXX)$(CXX) $(SHARED) $(CXX_LINK_O) $+ $(LDFLAGS) $(SHLDFLAGS) $(MODULE_LDFLAGS)
+ if [ "$(SHAREDLIBSUFFIXVER)" != "$(SHAREDLIBSUFFIX)" ]; then \
+ ln -sfn $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIXVER) \
+ $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIX); \
+ fi
$(PROJECT_NAME).pc: $(PROJECT_NAME).pc.in
@sed -e 's;@prefix@;$(PREFIX);' -e 's;@VERSION@;$(VERSION);' < $(PROJECT_NAME).pc.in > $(PROJECT_NAME).pc
@@ -220,7 +229,15 @@
install-shared: $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) install-headers $(PROJECT_NAME).pc
mkdir -p $(PREFIX)/lib
+ mkdir -p $(PREFIX)/bin
install -m 755 $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) $(PREFIX)/lib
+ if [ -L $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) ]; then \
+ cp -a $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) $(SHAREDLIB_DIR); \
+ fi
+ if [ -f $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX).a ]; then \
+ install -m 644 $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX).a \
+ $(PREFIX)/lib; \
+ fi
mkdir -p $(PREFIX)/lib/pkgconfig
install -m 444 $(PROJECT_NAME).pc $(PREFIX)/lib/pkgconfig
ifneq ($(EXTRA_LIBRARY),)
--- a/build/platform-android.mk
+++ b/build/platform-android.mk
@@ -1,6 +1,10 @@
ARCH = arm
include $(SRC_PATH)build/arch.mk
+SHAREDLIB_DIR = $(PREFIX)/lib
SHAREDLIBSUFFIX = so
+# Android APK/JARs expect libraries to be unversioned
+SHAREDLIBSUFFIXVER=$(SHAREDLIBSUFFIX)
+SHLDFLAGS =
NDKLEVEL = 12
ifeq ($(ARCH), arm)
ifneq ($(APP_ABI), armeabi)
--- a/build/platform-darwin.mk
+++ b/build/platform-darwin.mk
@@ -1,5 +1,10 @@
include $(SRC_PATH)build/arch.mk
+SHAREDLIB_DIR = $(PREFIX)/lib
SHAREDLIBSUFFIX = dylib
+SHAREDLIBSUFFIXVER=$(SHAREDLIBVERSION).$(SHAREDLIBSUFFIX)
+SHLDFLAGS = -dynamiclib -twolevel_namespace -undefined dynamic_lookup \
+ -fno-common -headerpad_max_install_names -install_name \
+ $(SHAREDLIB_DIR)/$(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXVER)
SHARED = -dynamiclib
CFLAGS += -Wall -fPIC -MMD -MP
LDFLAGS += -lpthread
--- a/build/platform-freebsd.mk
+++ b/build/platform-freebsd.mk
@@ -1,5 +1,8 @@
include $(SRC_PATH)build/arch.mk
+SHAREDLIB_DIR = $(PREFIX)/lib
SHAREDLIBSUFFIX = so
+SHAREDLIBSUFFIXVER=$(SHAREDLIBSUFFIX).$(SHAREDLIBVERSION)
+SHLDFLAGS = -Wl,-soname,$(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXVER)
CFLAGS += -fPIC
LDFLAGS += -lpthread
ifeq ($(ASM_ARCH), x86)
--- a/build/platform-linux.mk
+++ b/build/platform-linux.mk
@@ -1,5 +1,8 @@
include $(SRC_PATH)build/arch.mk
+SHAREDLIB_DIR = $(PREFIX)/lib
SHAREDLIBSUFFIX = so
+SHAREDLIBSUFFIXVER=$(SHAREDLIBSUFFIX).$(SHAREDLIBVERSION)
+SHLDFLAGS = -Wl,-soname,$(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXVER)
CFLAGS += -Wall -fno-strict-aliasing -fPIC -MMD -MP
LDFLAGS += -lpthread
ifeq ($(ASM_ARCH), x86)
--- a/build/platform-mingw_nt.mk
+++ b/build/platform-mingw_nt.mk
@@ -1,5 +1,8 @@
include $(SRC_PATH)build/x86-common.mk
+SHAREDLIB_DIR = $(PREFIX)/bin
SHAREDLIBSUFFIX = dll
+SHAREDLIBSUFFIXVER=$(SHAREDLIBSUFFIX)
+SHLDFLAGS = -Wl,--out-implib,$(LIBPREFIX)$(PROJECT_NAME).dll.a
CFLAGS += -MMD -MP
LDFLAGS +=
ifeq ($(ENABLE64BIT), Yes)