about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-01-09T21·14+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-01-09T21·14+0100
commite991ab942b6ed1bc50a63afafe55ffe5cae8cbad (patch)
treedf439623a575e14366e84b49bd353d3f8ffe67e2
parent70d8e8fdded9e21995fecc3ecc68e14cf4f53be7 (diff)
Add support for building shared libraries on Mac OS X
-rw-r--r--lib.mk5
-rw-r--r--libraries.mk22
2 files changed, 21 insertions, 6 deletions
diff --git a/lib.mk b/lib.mk
index 2d8ceef55f3e..5b0d2633cce4 100644
--- a/lib.mk
+++ b/lib.mk
@@ -9,6 +9,7 @@ default: all
 QUIET = @
 bin_SCRIPTS :=
 noinst_SCRIPTS :=
+OS = $(shell uname -s)
 
 
 # Default installation paths.
@@ -27,7 +28,9 @@ BUILD_SHARED_LIBS ?= 1
 ifeq ($(BUILD_SHARED_LIBS), 1)
   GLOBAL_CFLAGS += -fPIC
   GLOBAL_CXXFLAGS += -fPIC
-  GLOBAL_LDFLAGS += -Wl,--no-copy-dt-needed-entries
+  ifneq ($(OS), Darwin)
+    GLOBAL_LDFLAGS += -Wl,--no-copy-dt-needed-entries
+  endif
 endif
 
 
diff --git a/libraries.mk b/libraries.mk
index 98cc9f363f44..818c3d2172a1 100644
--- a/libraries.mk
+++ b/libraries.mk
@@ -1,5 +1,11 @@
 libs_list :=
 
+ifeq ($(OS), Darwin)
+  SO_EXT = dylib
+else
+  SO_EXT = so
+endif
+
 # Build a library with symbolic name $(1).  The library is defined by
 # various variables prefixed by ‘$(1)_’:
 #
@@ -46,18 +52,24 @@ define build-library =
 
   ifeq ($(BUILD_SHARED_LIBS), 1)
 
-    ifndef $(1)_ALLOW_UNDEFINED
-      $(1)_LDFLAGS += -z defs
+    ifdef $(1)_ALLOW_UNDEFINED
+      ifeq ($(OS), Darwin)
+        $(1)_LDFLAGS += -undefined suppress -flat_namespace
+      endif
+    else
+      ifneq ($(OS), Darwin)
+        $(1)_LDFLAGS += -z defs
+      endif
     endif
 
-    $(1)_PATH := $$(_d)/$$($(1)_NAME).so
+    $(1)_PATH := $$(_d)/$$($(1)_NAME).$(SO_EXT)
 
     $$($(1)_PATH): $$($(1)_OBJS) $$(_libs)
 	$(QUIET) $(CXX) -o $$@ -shared $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
 
     $(1)_LDFLAGS_USE += -L$$(_d) -Wl,-rpath,$$(abspath $$(_d)) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME)))
 
-    $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).so
+    $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).$(SO_EXT)
 
     _libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
 
@@ -99,6 +111,6 @@ define build-library =
   -include $$($(1)_DEPS)
 
   libs_list += $$($(1)_PATH)
-  clean_files += $$(_d)/*.a $$(_d)/*.so $$(_d)/*.o $$(_d)/*.dep $$($(1)_DEPS) $$($(1)_OBJS)
+  clean_files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/*.dep $$($(1)_DEPS) $$($(1)_OBJS)
   dist_files += $$(_srcs)
 endef