Link subproject dynamic libraries correctly
authorAndrew Waterman <waterman@eecs.berkeley.edu>
Mon, 27 Jan 2014 00:26:25 +0000 (16:26 -0800)
committerAndrew Waterman <waterman@eecs.berkeley.edu>
Mon, 27 Jan 2014 00:26:25 +0000 (16:26 -0800)
Makefile.in

index 9cd36d16bb45a6c5c20f3c32990cc52279f894a7..f54864fd3d0087e3e86eecae3b7422bf7a5db5b8 100644 (file)
@@ -195,19 +195,23 @@ $$($(2)_c_objs) : %.o : %.c $$($(2)_gen_hdrs)
 
 $(2)_junk += $$($(2)_objs) $$($(2)_c_objs) $$($(2)_deps) $$($(2)_c_deps) $$($(2)_gen_hdrs)
 
-# Build a library for this subproject
-
-lib$(1).so : $$($(2)_objs) $$($(2)_c_objs)
-       $(CXX) -shared -o $$@ $$^
-
-$(2)_junk += lib$(1).so
-
 # Reverse the dependency list so that a given subproject only depends on
 # subprojects listed to its right. This is the correct order for linking
 # the list of subproject libraries.
 
 $(2)_reverse_deps   := $$(call reverse_list,$$($(2)_subproject_deps))
 
+# Build a library for this subproject
+
+$(2)_lib_libs       := $$($(2)_reverse_deps)
+$(2)_lib_libnames   := $$(patsubst %, lib%.so, $$($(2)_lib_libs))
+$(2)_lib_libarg     := -L. $$(patsubst %, -l%, $$($(2)_lib_libs))
+
+lib$(1).so : $$($(2)_objs) $$($(2)_c_objs) $$($(2)_lib_libnames)
+       $(LINK) -shared -o $$@ $(if $(filter Darwin,$(shell uname -s)),-install_name $(install_libs_dir)/$$@) $$^ $$($(2)_lib_libarg) $(LIBS)
+
+$(2)_junk += lib$(1).so
+
 # Build unit tests
 
 $(2)_test_objs      := $$(patsubst %.cc, %.o, $$($(2)_test_srcs))