Change libbcc so that it compiles as an LLVM loadable module (try 2).

The main change is not requiring libLLVM in the makefile for libbcc.
With this change, libbcc can be used as an LLVM loadable module, for
instance as in "opt -load libbcc.so". This is helpful for debugging
individual bcc passes. Note that we still must link directly against
libLLVM on Windows due to the fact that DLLs can't access unresolved
symbols.

Revert "Revert "Change libbcc so that it compiles as an LLVM loadable module.""

This reverts commit a2bbdcdec92f076a38e75bbd81542fc49da19862.

Change-Id: I6729c2fed8542579ad76fcc533db091138f5575e
diff --git a/Android.mk b/Android.mk
index 1ab8386..0124cde 100644
--- a/Android.mk
+++ b/Android.mk
@@ -98,11 +98,22 @@
   libcutils \
   liblog
 
-LOCAL_SHARED_LIBRARIES := libbcinfo libLLVM
+LOCAL_SHARED_LIBRARIES := libbcinfo
 
-ifndef USE_MINGW
+ifdef USE_MINGW
+# Windows needs libLLVM, since DLLs must really have fully resolved their
+# symbolic dependencies.
+LOCAL_SHARED_LIBRARIES += libLLVM
+else
 LOCAL_LDLIBS := -ldl -lpthread
-endif
+ifeq (true,$(FORCE_BUILD_LLVM_COMPONENTS))
+# This line allows libbcc to be used as an LLVM loadable module with
+# opt. We don't build unless we have libLLVMLinker, which is not
+# provided as a prebuilt. libLLVMLinker is needed because it is not
+# pulled into opt.
+LOCAL_STATIC_LIBRARIES += libLLVMLinker
+endif  # FORCE_BUILD_LLVM_COMPONENTS
+endif  # USE_MINGW
 
 include $(LIBBCC_HOST_BUILD_MK)
 include $(LLVM_HOST_BUILD_MK)
diff --git a/bcinfo/Android.mk b/bcinfo/Android.mk
index 5a55014..76af030 100644
--- a/bcinfo/Android.mk
+++ b/bcinfo/Android.mk
@@ -80,9 +80,12 @@
 
 LOCAL_STATIC_LIBRARIES += $(libbcinfo_STATIC_LIBRARIES)
 LOCAL_STATIC_LIBRARIES += libcutils liblog
-LOCAL_SHARED_LIBRARIES += libLLVM
 
-ifndef USE_MINGW
+ifdef USE_MINGW
+# Windows needs libLLVM, since DLLs must really have fully resolved their
+# symbolic dependencies.
+LOCAL_SHARED_LIBRARIES += libLLVM
+else
 LOCAL_LDLIBS := -ldl -lpthread
 endif