make/common/NativeCompilation.gmk
changeset 33568 b0459b292c36
parent 33394 dbd286b8742f
parent 33562 c76b2fa11486
child 34116 b746e382da18
child 34102 c0a98357f847
--- a/make/common/NativeCompilation.gmk	Fri Oct 30 12:03:08 2015 -0700
+++ b/make/common/NativeCompilation.gmk	Thu Nov 05 19:31:19 2015 +0100
@@ -35,6 +35,31 @@
 endif
 
 ################################################################################
+# Create exported symbols file for static libraries
+################################################################################
+
+# get the exported symbols from mapfiles and if there
+# is no mapfile, get them from the archive
+define GetSymbols
+  $(RM) $$(@D)/$$(basename $$(@F)).symbols; \
+  if [ ! -z $$($1_MAPFILE) -a -e $$($1_MAPFILE) ]; then \
+    $(ECHO) "Getting symbols from mapfile $$($1_MAPFILE)"; \
+    $(AWK) '/global:/','/local:/' $$($1_MAPFILE) | \
+        $(SED) -e 's/#.*//;s/global://;s/local://;s/\;//;s/^[ 	]*/_/;/^_$$$$/d' | \
+        $(EGREP) -v "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" > \
+        $$(@D)/$$(basename $$(@F)).symbols || true; \
+    $(NM) $$($1_TARGET) | $(GREP)  " T " | \
+        $(EGREP) "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" | \
+        $(CUT) -d ' ' -f 3 >>  $$(@D)/$$(basename $$(@F)).symbols || true;\
+  else \
+    $(ECHO) "Getting symbols from nm"; \
+    $(NM) -m $$($1_TARGET) | $(GREP)  "__TEXT" | \
+        $(EGREP) -v "non-external|private extern|__TEXT,__eh_frame" | \
+        $(SED) -e  's/.* //' > $$(@D)/$$(basename $$(@F)).symbols; \
+  fi
+endef
+
+################################################################################
 # Define a native toolchain configuration that can be used by
 # SetupNativeCompilation calls
 #
@@ -274,6 +299,15 @@
 SetupNativeCompilation = $(NamedParamsMacroTemplate)
 define SetupNativeCompilationBody
 
+  # If we're doing a static build and producing a library
+  # force it to be a static library and remove the -l libraries
+  ifeq ($(STATIC_BUILD), true)
+    ifneq ($$($1_LIBRARY),)
+      $1_STATIC_LIBRARY := $$($1_LIBRARY)
+      $1_LIBRARY :=
+    endif
+  endif
+
   ifneq (,$$($1_BIN))
     $$(error BIN has been replaced with OBJECT_DIR)
   endif
@@ -495,6 +529,12 @@
     $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER)
   endif
 
+  # Pass the library name for static JNI library naming
+  ifneq ($$($1_STATIC_LIBRARY),)
+    $1_EXTRA_CFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY)
+    $1_EXTRA_CXXFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY)
+  endif
+
   # Pick up disabled warnings, if possible on this platform.
   ifneq ($(DISABLE_WARNING_PREFIX),)
     $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)))
@@ -725,7 +765,10 @@
 	$(ECHO) $(LOG_INFO) "Archiving $$($1_STATIC_LIBRARY)"
 	$(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \
 	    $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \
-	        $$($1_RES) $$($1_LIBS) $$($1_EXTRA_LIBS))
+	        $$($1_RES))
+        ifeq ($(STATIC_BUILD), true)
+	  $(GetSymbols)
+        endif
   endif
 
   ifneq (,$$($1_PROGRAM))