dragonboards: mesa_prebuilt/copy_bins.sh: Auto-detect TARGET_OUT directory

Auto-detect DB845c TARGET_OUT directory instead of using a relative path.

". build/envsetup.sh; lunch db845c-userdebug" commands set the required
variables, e.g. ANDROID_PRODUCT_OUT already. Set ANDROID_PRODUCT_OUT
explicitly if is it not pre-set.

Error out if the variable is not set.

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Change-Id: I13361972bb4e11cf354df47fd3ce9d5495777bae
diff --git a/src/db845c/mesa_prebuilt/copy_bins.sh b/src/db845c/mesa_prebuilt/copy_bins.sh
index ff6521a..38d6fe8 100755
--- a/src/db845c/mesa_prebuilt/copy_bins.sh
+++ b/src/db845c/mesa_prebuilt/copy_bins.sh
@@ -1,4 +1,9 @@
-AOSP_TOP=../../../../../
+# Auto detect DB845c TARGET_OUT directory
+# ". build/envsetup.sh; lunch db845c-userdebug" set the required variables
+if [ ! -d "${ANDROID_PRODUCT_OUT}" ]; then
+    echo "Error in locating out/target/product/db845c directory, check if it exists"
+    exit
+fi
 
 mkdir -p lib64/egl
 mkdir -p lib/egl
@@ -7,14 +12,14 @@
 mkdir -p lib64/hw
 mkdir -p lib/hw
 
-cp -P $AOSP_TOP/out/target/product/db845c/vendor/lib64/egl/*	lib64/egl/
-cp -P $AOSP_TOP/out/target/product/db845c/vendor/lib/egl/*		lib/egl/
-cp -P $AOSP_TOP/out/target/product/db845c/vendor/lib64/dri/*	lib64/dri/
-cp -P $AOSP_TOP/out/target/product/db845c/vendor/lib/dri/*		lib/dri/
+cp -P $ANDROID_PRODUCT_OUT/vendor/lib64/egl/*			lib64/egl/
+cp -P $ANDROID_PRODUCT_OUT/vendor/lib/egl/*			lib/egl/
+cp -P $ANDROID_PRODUCT_OUT/vendor/lib64/dri/*			lib64/dri/
+cp -P $ANDROID_PRODUCT_OUT/vendor/lib/dri/*			lib/dri/
 
-cp $AOSP_TOP/out/target/product/db845c/vendor/lib64/hw/vulkan.freedreno.so	lib64/hw/
-cp $AOSP_TOP/out/target/product/db845c/vendor/lib/hw/vulkan.freedreno.so	lib/hw/
+cp $ANDROID_PRODUCT_OUT/vendor/lib64/hw/vulkan.freedreno.so	lib64/hw/
+cp $ANDROID_PRODUCT_OUT/vendor/lib/hw/vulkan.freedreno.so	lib/hw/
 
-cp $AOSP_TOP/out/target/product/db845c/vendor/lib64/libglapi.so	lib64/libglapi.so
-cp $AOSP_TOP/out/target/product/db845c/vendor/lib/libglapi.so	lib/libglapi.so
+cp $ANDROID_PRODUCT_OUT/vendor/lib64/libglapi.so		lib64/libglapi.so
+cp $ANDROID_PRODUCT_OUT/vendor/lib/libglapi.so			lib/libglapi.so