Custom output directory support with NDK_OUT

This patch allows the use of the NDK_OUT environment variable
to specify a custom output directory for all intermediate
generated files (i.e. instead of $PROJECT_PATH/obj).

ndk-gdb will pick up the right location if the variable is
defined too. Note that final binaries are still placed under
$PROJECT_PATH/libs by default since the packaging scripts
expect them to be here.

This fixes http://code.google.com/p/android/issues/detail?id=25470

Change-Id: I50618df619c13f5208200f8d0902b8e4fe201de8
diff --git a/ndk-gdb b/ndk-gdb
index d812a93..2322a59 100755
--- a/ndk-gdb
+++ b/ndk-gdb
@@ -509,6 +509,16 @@
 fi
 log "Compatible device ABI: $COMPAT_ABI"
 
+# Get information from the build system
+GDBSETUP_INIT=`get_build_var_for_abi NDK_APP_GDBSETUP $COMPAT_ABI`
+log "Using gdb setup init: $GDBSETUP_INIT"
+
+TOOLCHAIN_PREFIX=`get_build_var_for_abi TOOLCHAIN_PREFIX $COMPAT_ABI`
+log "Using toolchain prefix: $TOOLCHAIN_PREFIX"
+
+APP_OUT=`get_build_var_for_abi TARGET_OUT $COMPAT_ABI`
+log "Using app out directory: $APP_OUT"
+
 # Check that the application is debuggable, or nothing will work
 DEBUGGABLE=`run_awk_manifest_script extract-debuggable.awk`
 log "Found debuggable flag: $DEBUGGABLE"
@@ -553,16 +563,6 @@
 fi
 log "Found device gdbserver: $DEVICE_GDBSERVER"
 
-# Get information from the build system
-GDBSETUP_INIT=`get_build_var_for_abi NDK_APP_GDBSETUP $COMPAT_ABI`
-log "Using gdb setup init: $GDBSETUP_INIT"
-
-TOOLCHAIN_PREFIX=`get_build_var_for_abi TOOLCHAIN_PREFIX $COMPAT_ABI`
-log "Using toolchain prefix: $TOOLCHAIN_PREFIX"
-
-APP_OUT=`get_build_var_for_abi TARGET_OUT $COMPAT_ABI`
-log "Using app out directory: $APP_OUT"
-
 # Find the <dataDir> of the package on the device
 adb_var_shell2 DATA_DIR run-as $PACKAGE_NAME /system/bin/sh -c pwd
 if [ $? != 0 -o -z "$DATA_DIR" ] ; then