fix lib64 handling for 64bit targets

For 64bit targets, make sure we use /usr/lib64 instead of /usr/lib.

The binding between "is 64bit" and "use lib64" is kind of broken, but
Android doesn't really support multiple ABIs cleanly, so this is fine
until it does.

Change-Id: I3dcd7ee50bac08d4b72af793b37c6031c6890611
diff --git a/Android.mk b/Android.mk
index 7d49ce3..08e41d8 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,6 +3,12 @@
 # Only load these subdirs when 3rd party packages have been requested.
 ifneq ($(PRODUCT_3RD_PARTY_PACKAGES),)
 
+ifeq ($(TARGET_IS_64_BIT),true)
+3RD_PARTY_LIBDIR := lib64
+else
+3RD_PARTY_LIBDIR := lib
+endif
+
 3RD_PARTY_CC := $(HOST_OUT_EXECUTABLES)/3rd-party-gcc
 3RD_PARTY_CXX := $(HOST_OUT_EXECUTABLES)/3rd-party-g++
 3RD_PARTY_PKG_CONFIG := $(HOST_OUT_EXECUTABLES)/3rd-party-pkg-config
diff --git a/portage/Android.mk b/portage/Android.mk
index 3e0d0b7..13d1cc6 100644
--- a/portage/Android.mk
+++ b/portage/Android.mk
@@ -5,7 +5,6 @@
 
 define CREATE_WRAPPER
 	$(hide)mkdir -p $(dir $@)
-	$(hide) echo $(HOST_OUT) $(3RD_PARTY_ROOT)
 	$(hide)sed \
 		-e 's:@ROOT_SUBDIR@:$(3RD_PARTY_ROOT_SUBDIR):g' \
 		-e 's:@BIN@:$(BINDIR)/$(notdir $@):' \
@@ -68,6 +67,7 @@
 		-e 's:@COMMON_OBJ@:$${ANDROID_BUILD_TOP}/$(TARGET_OUT_COMMON_GENTOO):' \
 		-e 's:@PRODUCT_OBJ@:$${ANDROID_PRODUCT_OUT}/obj/gentoo:g' \
 		-e 's:@PORTAGE_PREFIX@:$(PORTAGE_PREFIX):g' \
+		-e 's:@LIBDIR@:$(3RD_PARTY_LIBDIR):' \
 		$< > $@
 
 include $(CLEAR_VARS)
diff --git a/portage/make.conf.in b/portage/make.conf.in
index fda6e4e..e359a51 100644
--- a/portage/make.conf.in
+++ b/portage/make.conf.in
@@ -4,6 +4,8 @@
 PORTAGE_PREFIX="${ANDROID_BUILD_TOP}/@PORTAGE_PREFIX@"
 
 ROOTPATH="/usr/bin:/bin:/usr/sbin:/sbin:${PORTAGE_PREFIX}/usr/bin:${ANDROID_BUILD_PATHS}"
+LIBDIR="@LIBDIR@"
+LIBDIR_@ARCH@="@LIBDIR@"
 
 ACCEPT_KEYWORDS="~${ARCH}"
 
diff --git a/toolchain/3rd-party-g++.in b/toolchain/3rd-party-g++.in
index a60334f..17d3374 100644
--- a/toolchain/3rd-party-g++.in
+++ b/toolchain/3rd-party-g++.in
@@ -4,7 +4,7 @@
 	@CXXFLAGS@ \
 	@LDFLAGS@ \
 	--sysroot "${ANDROID_PRODUCT_OUT}/@ROOT_SUBDIR@" \
-	-Wl,-rpath,/system/usr/lib \
+	-Wl,-rpath,/system/usr/@LIBDIR@ \
 	-Wl,-lc++ \
 	-frtti \
 	"$@"
diff --git a/toolchain/3rd-party-gcc.in b/toolchain/3rd-party-gcc.in
index ef8e708..3d797aa 100644
--- a/toolchain/3rd-party-gcc.in
+++ b/toolchain/3rd-party-gcc.in
@@ -4,5 +4,5 @@
 	@CFLAGS@ \
 	@LDFLAGS@ \
 	--sysroot "${ANDROID_PRODUCT_OUT}/@ROOT_SUBDIR@" \
-	-Wl,-rpath,/system/usr/lib \
+	-Wl,-rpath,/system/usr/@LIBDIR@ \
 	"$@"
diff --git a/toolchain/Android.mk b/toolchain/Android.mk
index f8d7db2..8602138 100644
--- a/toolchain/Android.mk
+++ b/toolchain/Android.mk
@@ -19,6 +19,7 @@
 		-e 's:@CFLAGS@:$(foreach p,$(TARGET_C_INCLUDES) $(EXTERNAL_PACKAGES_INCLUDE),-isystem "$${ANDROID_BUILD_TOP}/$(p)"):' \
 		-e 's:@LDFLAGS@:-B"$(patsubst $(PRODUCT_OUT)/%,$${ANDROID_PRODUCT_OUT}/%,$(TARGET_OUT_INTERMEDIATE_LIBRARIES))":' \
 		-e 's:@ROOT_SUBDIR@:$(3RD_PARTY_ROOT_SUBDIR):g' \
+		-e 's:@LIBDIR@:$(3RD_PARTY_LIBDIR):g' \
 		$< > $@.tmp \
 		&& chmod a+rx $@.tmp && mv $@.tmp $@
 
@@ -44,6 +45,7 @@
 		-e 's:@CFLAGS@:$(foreach p,$(TARGET_C_INCLUDES),-isystem "$${ANDROID_BUILD_TOP}/$(p)"):' \
 		-e 's:@LDFLAGS@:-B"$(patsubst $(PRODUCT_OUT)/%,$${ANDROID_PRODUCT_OUT}/%,$(TARGET_OUT_INTERMEDIATE_LIBRARIES))":' \
 		-e 's:@ROOT_SUBDIR@:$(3RD_PARTY_ROOT_SUBDIR):g' \
+		-e 's:@LIBDIR@:$(3RD_PARTY_LIBDIR):g' \
 		$< > $@.tmp \
 		&& chmod a+rx $@.tmp && mv $@.tmp $@