Fix OVERRIDE_BUILT_MODULE_PATH for prebuilt shared libraries.

So that prebuilt shared libraries can be referenced with the module name
in other module's Android.mk.
This is a clean cherrypick from later branches.
Bug: 5652242

Change-Id: I850978251a23808559d30025a9c519fe8e59594a
diff --git a/core/prebuilt.mk b/core/prebuilt.mk
index 8f9eafb..d0155cf 100644
--- a/core/prebuilt.mk
+++ b/core/prebuilt.mk
@@ -16,6 +16,17 @@
 $(error dont use LOCAL_PREBUILT_JAVA_LIBRARIES anymore LOCAL_PATH=$(LOCAL_PATH))
 endif
 
+ifdef LOCAL_IS_HOST_MODULE
+  my_prefix:=HOST_
+else
+  my_prefix:=TARGET_
+endif
+ifeq (SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS))
+  # Put the built targets of all shared libraries in a common directory
+  # to simplify the link line.
+  OVERRIDE_BUILT_MODULE_PATH := $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)
+endif
+
 ifneq ($(filter APPS,$(LOCAL_MODULE_CLASS)),)
 ifeq (true,$(WITH_DEXPREOPT))
 ifeq (,$(TARGET_BUILD_APPS))