Set up rules to build shared libraries for TARGET_2ND_ARCH

The rules for the 2nd arch are set up in the second inclusion
of shared_library_internal.mk.
Intermediate fils of libfoo of the 2nd arch will be built into
$(PRODUCT_OUT)/obj_$(TARGET_2ND_ARCH)/SHARED_LIBRARIES/libfoo_intermediates/
and the built libfoo.so will be in
$(PRODUCT_OUT)/obj_$(TARGET_2ND_ARCH)/lib.

Bug: 11654773
Change-Id: I58bbe5a05a65f63bce6279131552f3792000716e
diff --git a/core/main.mk b/core/main.mk
index cc57ae8..e2b93c2 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -603,6 +603,14 @@
   $(eval r := $(filter $(HOST_OUT_ROOT)/%,$(call module-installed-files,\
     $(subst $(comma),$(space),$(lastword $(p)))))) \
   $(eval $(call add-required-deps,$(word 2,$(p)),$(r))))
+ifdef TARGET_2ND_ARCH
+$(foreach m,$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES), \
+  $(eval p := $(subst :,$(space),$(m))) \
+  $(eval r := $(filter $(TARGET_OUT_ROOT)/%,$(call module-installed-files,\
+    $(addsuffix $(TARGET_2ND_ARCH_MODULE_SUFFIX), \
+      $(subst $(comma),$(space),$(lastword $(p))))))) \
+  $(eval $(call add-required-deps,$(word 2,$(p)),$(r))))
+endif
 
 m :=
 r :=