From 94e8fc15365c6253f9fb8852329f8c49c5728864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Thu, 16 Jul 2015 14:15:09 +0300 Subject: [PATCH 1/6] Build dylib on Darwin. Adds target libkvazaar.dylib to Makefile. On Darwin, libkvazaar.dylib is set as a prerequisite of the all target. --- src/Makefile | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/Makefile b/src/Makefile index ca58aa7b..a05316ae 100644 --- a/src/Makefile +++ b/src/Makefile @@ -18,6 +18,7 @@ DEBUG = kvazaar_debug TESTS = kvazaar_tests SO = libkvazaar.so LIB = $(SO).$(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE) +DYLIB = libkvazaar.dylib DLL = kvazaar.dll IMPLIB = libkvazaar.dll.a INC = kvazaar.h \ @@ -39,10 +40,13 @@ CFLAGS += -DKVZ_DLL_EXPORTS CFLAGS += $(INCLUDEDIRS) $(WARNINGS) LDFLAGS += -fvisibility=hidden -lm -pthread -ifeq (, $(ARCH)) - ARCH = $(shell uname -m) +ARCH ?= $(shell uname -m) + +ifneq ($(findstring Windows, $(OS)),) + SYSTEM ?= Windows +else + SYSTEM ?= $(shell uname -s) endif -SYSTEM = $(shell uname -s) # ARCH related flags ifeq ($(ARCH), x86_64) @@ -61,7 +65,7 @@ CFLAGS += -m$(TARGET_CPU_BITS) LDFLAGS += -m$(TARGET_CPU_BITS) # Windows (cygwin/mingw) specific flags -ifneq ( ,$(findstring Windows, $(OS))) +ifeq ($(SYSTEM), Windows) ifeq ($(ARCH), x86_64) ASFLAGS += -f win64 ASFLAGS += -DHAVE_ALIGNED_STACK=1 @@ -71,14 +75,20 @@ ifneq ( ,$(findstring Windows, $(OS))) ASFLAGS += -DHAVE_ALIGNED_STACK=0 endif CFLAGS += -D__USE_MINGW_ANSI_STDIO=1 + ALL_TARGETS = $(PROG) $(DLL) + INSTALL_TARGETS = install-prog install-dll + # OS X specific flags -else ifeq ($(SYSTEM),Darwin) +else ifeq ($(SYSTEM), Darwin) ifeq ($(ARCH), x86_64) ASFLAGS += -f macho64 else ASFLAGS += -f macho32 endif ASFLAGS += -DPREFIX + ALL_TARGETS = $(PROG) $(DYLIB) + INSTALL_TARGETS = install-prog + # Default to Linux/elf specific flags else LDFLAGS += -lrt @@ -87,7 +97,10 @@ else else ASFLAGS += -f elf32 endif + ALL_TARGETS = $(PROG) $(LIB) + INSTALL_TARGETS = install-prog install-lib endif + # Flags shared across systems ifeq ($(ARCH), x86_64) ASFLAGS += -DARCH_X86_64=1 @@ -199,11 +212,7 @@ TESTS_OBJS = $(TEST_OBJS) $(OBJS) DEPS = $(RELEASE_OBJS:.o=.d) $(DEBUG_OBJS:.o=.d) $(TESTS_OBJS:.o=.d) -ifneq ( ,$(findstring Windows, $(OS))) - all: $(PROG) $(DLL) -else - all: $(PROG) $(LIB) -endif +all: $(ALL_TARGETS) debug: LDFLAGS := $(filter-out -O3 -O2 -flto, $(LDFLAGS)) debug: CFLAGS := $(filter-out -O3 -O2 -flto, $(CFLAGS)) @@ -218,11 +227,11 @@ build_tests: init_submodules $(TESTS) $(PROG): $(RELEASE_OBJS) $(LD) $^ $(LDFLAGS) -o $@ -$(LIB): $(RELEASE_OBJS) - $(LD) $^ $(LDFLAGS) -shared -Wl,-soname,$(SO).$(VER_MAJOR) -o $@ - -$(DLL): $(RELEASE_OBJS) - $(LD) $^ $(LDFLAGS) -shared -Wl,--out-implib,$(IMPLIB) -o $@ +$(LIB): LDFLAGS += -shared -Wl,-soname,$(SO).$(VER_MAJOR) +$(DLL): LDFLAGS += -shared -Wl,--out-implib,$(IMPLIB) -o $@ +$(DYLIB): LDFLAGS += -dynamiclib -current_version $(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE) +$(LIB) $(DLL) $(DYLIB): $(OBJS) + $(LD) $^ $(LDFLAGS) -o $@ $(DEBUG): $(DEBUG_OBJS) $(LD) $^ $(LDFLAGS) -o $@ @@ -240,11 +249,7 @@ init_submodules: git submodule init git submodule update -ifneq ( ,$(findstring Windows, $(OS))) - install: install-prog install-dll -else - install: install-prog install-lib -endif +install: $(INSTALL_TARGETS) install-prog: $(PROG) $(INSTALL) -d $(DESTDIR)$(BINDIR) @@ -268,7 +273,7 @@ install-dll: $(DLL) clean: $(RM) $(RELEASE_OBJS) $(DEBUG_OBJS) $(TESTS_OBJS) $(DEPS) - $(RM) $(PROG) $(DEBUG) $(TESTS) $(LIB) $(DLL) $(IMPLIB) + $(RM) $(PROG) $(DEBUG) $(TESTS) $(LIB) $(DLL) $(IMPLIB) $(DYLIB) ifneq ($(MAKECMDGOALS),clean) -include $(DEPS) From 56ff1c7805181afcba2801abaff577335ae8acad Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 16 Jul 2015 16:50:09 +0200 Subject: [PATCH 2/6] build: Drop the non-standard -t Should unbreak freebsd. --- src/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Makefile b/src/Makefile index a05316ae..dcce5274 100644 --- a/src/Makefile +++ b/src/Makefile @@ -253,13 +253,13 @@ install: $(INSTALL_TARGETS) install-prog: $(PROG) $(INSTALL) -d $(DESTDIR)$(BINDIR) - $(INSTALL) -m755 $(PROG) -t $(DESTDIR)$(BINDIR) + $(INSTALL) -m755 $(PROG) $(DESTDIR)$(BINDIR) install-lib: $(LIB) $(INSTALL) -d $(DESTDIR)$(INCDIR) $(INSTALL) -d $(DESTDIR)$(LIBDIR) - $(INSTALL) -m644 $(INC) -t $(DESTDIR)$(INCDIR) - $(INSTALL) -m644 $(LIB) -t $(DESTDIR)$(LIBDIR) + $(INSTALL) -m644 $(INC) $(DESTDIR)$(INCDIR) + $(INSTALL) -m644 $(LIB) $(DESTDIR)$(LIBDIR) $(LN_S) -f -T $(LIB) $(DESTDIR)$(LIBDIR)/$(SO).$(VER_MAJOR) $(LN_S) -f -T $(LIB) $(DESTDIR)$(LIBDIR)/$(SO) @@ -267,9 +267,9 @@ install-dll: $(DLL) $(INSTALL) -d $(DESTDIR)$(DLLDIR) $(INSTALL) -d $(DESTDIR)$(INCDIR) $(INSTALL) -d $(DESTDIR)$(LIBDIR) - $(INSTALL) -m644 $(DLL) -t $(DESTDIR)$(DLLDIR) - $(INSTALL) -m644 $(INC) -t $(DESTDIR)$(INCDIR) - $(INSTALL) -m644 $(IMPLIB) -t $(DESTDIR)$(LIBDIR) + $(INSTALL) -m644 $(DLL) $(DESTDIR)$(DLLDIR) + $(INSTALL) -m644 $(INC) $(DESTDIR)$(INCDIR) + $(INSTALL) -m644 $(IMPLIB) $(DESTDIR)$(LIBDIR) clean: $(RM) $(RELEASE_OBJS) $(DEBUG_OBJS) $(TESTS_OBJS) $(DEPS) From 9c414995c5e26dfa3daf38c863e22d5b806ce640 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 17 Jul 2015 19:44:20 +0200 Subject: [PATCH 3/6] build: Add a MacOSX install target for the library --- src/Makefile | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Makefile b/src/Makefile index dcce5274..4e5a1173 100644 --- a/src/Makefile +++ b/src/Makefile @@ -16,9 +16,11 @@ VER_RELEASE = 0 PROG = kvazaar DEBUG = kvazaar_debug TESTS = kvazaar_tests -SO = libkvazaar.so + +NAME = libkvazaar +SO = $(NAME).so LIB = $(SO).$(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE) -DYLIB = libkvazaar.dylib +DYLIB = $(NAME).$(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE).dylib DLL = kvazaar.dll IMPLIB = libkvazaar.dll.a INC = kvazaar.h \ @@ -87,7 +89,7 @@ else ifeq ($(SYSTEM), Darwin) endif ASFLAGS += -DPREFIX ALL_TARGETS = $(PROG) $(DYLIB) - INSTALL_TARGETS = install-prog + INSTALL_TARGETS = install-prog install-dylib # Default to Linux/elf specific flags else @@ -263,6 +265,14 @@ install-lib: $(LIB) $(LN_S) -f -T $(LIB) $(DESTDIR)$(LIBDIR)/$(SO).$(VER_MAJOR) $(LN_S) -f -T $(LIB) $(DESTDIR)$(LIBDIR)/$(SO) +install-dylib: $(DYLIB) + $(INSTALL) -d $(DESTDIR)$(INCDIR) + $(INSTALL) -d $(DESTDIR)$(LIBDIR) + $(INSTALL) -m644 $(INC) $(DESTDIR)$(INCDIR) + $(INSTALL) -m644 $(DYLIB) $(DESTDIR)$(LIBDIR) + $(LN_S) -f $(DYLIB) $(DESTDIR)$(LIBDIR)/$(NAME).$(VER_MAJOR).dylib + $(LN_S) -f $(DYLIB) $(DESTDIR)$(LIBDIR)/$(NAME).dylib + install-dll: $(DLL) $(INSTALL) -d $(DESTDIR)$(DLLDIR) $(INSTALL) -d $(DESTDIR)$(INCDIR) From df749e032efd00974215c2f24adfd00310adbe85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Mon, 20 Jul 2015 14:40:58 +0300 Subject: [PATCH 4/6] Add necessary linker options when building dylib. Sets linker options -compatibility_version and -install_name when making dylib. --- src/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 4e5a1173..2b311096 100644 --- a/src/Makefile +++ b/src/Makefile @@ -231,7 +231,10 @@ $(PROG): $(RELEASE_OBJS) $(LIB): LDFLAGS += -shared -Wl,-soname,$(SO).$(VER_MAJOR) $(DLL): LDFLAGS += -shared -Wl,--out-implib,$(IMPLIB) -o $@ -$(DYLIB): LDFLAGS += -dynamiclib -current_version $(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE) +$(DYLIB): LDFLAGS += -dynamiclib \ + -current_version $(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE) \ + -compatibility_version $(VER_MAJOR) \ + -install_name $(LIBDIR)/$@ $(LIB) $(DLL) $(DYLIB): $(OBJS) $(LD) $^ $(LDFLAGS) -o $@ From 06ea5934772d1902d03ca1da4a60b012173c92b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Mon, 20 Jul 2015 14:49:25 +0300 Subject: [PATCH 5/6] Change dylib file name to libkvazaar.X.dylib. Changes the version number in the dylib filename from a three-digit version (libkvazaar.X.Y.Z.dylib) to a single-digit one (libkvazaar.X.dylib). --- src/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index 2b311096..2513fac0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ TESTS = kvazaar_tests NAME = libkvazaar SO = $(NAME).so LIB = $(SO).$(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE) -DYLIB = $(NAME).$(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE).dylib +DYLIB = $(NAME).$(VER_MAJOR).dylib DLL = kvazaar.dll IMPLIB = libkvazaar.dll.a INC = kvazaar.h \ @@ -273,7 +273,6 @@ install-dylib: $(DYLIB) $(INSTALL) -d $(DESTDIR)$(LIBDIR) $(INSTALL) -m644 $(INC) $(DESTDIR)$(INCDIR) $(INSTALL) -m644 $(DYLIB) $(DESTDIR)$(LIBDIR) - $(LN_S) -f $(DYLIB) $(DESTDIR)$(LIBDIR)/$(NAME).$(VER_MAJOR).dylib $(LN_S) -f $(DYLIB) $(DESTDIR)$(LIBDIR)/$(NAME).dylib install-dll: $(DLL) From 1834ae8f455a5b0390c7fb81358d4f66d70b1698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Mon, 20 Jul 2015 15:05:18 +0300 Subject: [PATCH 6/6] Add dylib to gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ce05e607..810f8dbb 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ src/kvazaar src/libkvazaar.so.* src/kvazaar.dll src/libkvazaar.dll.a +src/libkvazaar.*.dylib