Makefile: build dylib on macOS

On macOS, shared libraries end in "$(SOVERSION).dylib", not
".so.$(SOVERSION)" like on Linux.  Also, a different linker option is
needed to set the equivalent of the soname.

This is based on patches from:

	Elmar Pruesse <elmar.pruesse@ucdenver.edu>
and
	Roy Storey <kiwiroy@users.noreply.github.com>

but refactored, and fixed to not break the Windows build.
This commit is contained in:
Eric Biggers 2019-08-30 00:14:43 -05:00
parent e227dee9e6
commit 1a440dffea
2 changed files with 21 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
*.a *.a
*.dll *.dll
*.dylib
*.exe *.exe
*.exp *.exp
*.lib *.lib

View File

@ -60,19 +60,17 @@ INCDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib LIBDIR ?= $(PREFIX)/lib
SOVERSION := 0 SOVERSION := 0
STATIC_LIB_SUFFIX := .a STATIC_LIB_SUFFIX := .a
SHARED_LIB_SUFFIX := .so.$(SOVERSION)
SHARED_LIB_CFLAGS := -fPIC
SHARED_LIB_LDFLAGS := -Wl,-soname=libdeflate$(SHARED_LIB_SUFFIX)
PROG_SUFFIX := PROG_SUFFIX :=
PROG_CFLAGS := PROG_CFLAGS :=
HARD_LINKS := 1 HARD_LINKS := 1
# Compiling for Windows with MinGW? # Compiling for Windows with MinGW?
ifneq ($(findstring -mingw,$(shell $(CC) -dumpmachine 2>/dev/null)),) ifneq ($(findstring -mingw,$(shell $(CC) -dumpmachine 2>/dev/null)),)
SOVERSION :=
STATIC_LIB_SUFFIX := static.lib STATIC_LIB_SUFFIX := static.lib
SHARED_LIB_SUFFIX := .dll SHARED_LIB := libdeflate.dll
SHARED_LIB_SYMLINK :=
SHARED_LIB_CFLAGS := SHARED_LIB_CFLAGS :=
SHARED_LIB_LDFLAGS := -Wl,--out-implib,libdeflate.lib SHARED_LIB_LDFLAGS := -Wl,--out-implib,libdeflate.lib
PROG_SUFFIX := .exe PROG_SUFFIX := .exe
@ -88,6 +86,20 @@ ifneq ($(findstring -mingw,$(shell $(CC) -dumpmachine 2>/dev/null)),)
AR := $(shell echo $(CC) | \ AR := $(shell echo $(CC) | \
sed -E 's/g?cc(-?[0-9]+(\.[0-9]+)*)?(\.exe)?$$/ar\3/') sed -E 's/g?cc(-?[0-9]+(\.[0-9]+)*)?(\.exe)?$$/ar\3/')
endif endif
# macOS?
else ifeq ($(shell uname),Darwin)
SHARED_LIB := libdeflate.$(SOVERSION).dylib
SHARED_LIB_SYMLINK := libdeflate.dylib
SHARED_LIB_CFLAGS := -fPIC
SHARED_LIB_LDFLAGS := -install_name $(SHARED_LIB)
# Linux, FreeBSD, etc.
else
SHARED_LIB := libdeflate.so.$(SOVERSION)
SHARED_LIB_SYMLINK := libdeflate.so
SHARED_LIB_CFLAGS := -fPIC
SHARED_LIB_LDFLAGS := -Wl,-soname=$(SHARED_LIB)
endif endif
############################################################################## ##############################################################################
@ -113,7 +125,6 @@ DEFAULT_TARGETS :=
#### Library #### Library
STATIC_LIB := libdeflate$(STATIC_LIB_SUFFIX) STATIC_LIB := libdeflate$(STATIC_LIB_SUFFIX)
SHARED_LIB := libdeflate$(SHARED_LIB_SUFFIX)
LIB_CFLAGS += $(CFLAGS) -fvisibility=hidden -D_ANSI_SOURCE LIB_CFLAGS += $(CFLAGS) -fvisibility=hidden -D_ANSI_SOURCE
@ -168,11 +179,11 @@ $(SHARED_LIB):$(SHARED_LIB_OBJ)
DEFAULT_TARGETS += $(SHARED_LIB) DEFAULT_TARGETS += $(SHARED_LIB)
ifdef SOVERSION ifdef SHARED_LIB_SYMLINK
# Create the symlink libdeflate.so => libdeflate.so.$SOVERSION # Create the symlink libdeflate.so => libdeflate.so.$SOVERSION
libdeflate.so:$(SHARED_LIB) $(SHARED_LIB_SYMLINK):$(SHARED_LIB)
$(QUIET_LN) ln -sf $+ $@ $(QUIET_LN) ln -sf $+ $@
DEFAULT_TARGETS += libdeflate.so DEFAULT_TARGETS += $(SHARED_LIB_SYMLINK)
endif endif
# Rebuild if CC, LIB_CFLAGS, or CPPFLAGS changed # Rebuild if CC, LIB_CFLAGS, or CPPFLAGS changed