Support GPU emulation standalone build.

This patch modifies the emulator's standalone build system
to rebuild all GPU emulation libraries directly from sources,
assuming their are located under ../../sdk/emulator/opengl/
or ../opengl/

Change-Id: I2ac8fc4bc2d06561dc52298689840f74171397aa
diff --git a/android-configure.sh b/android-configure.sh
index 8abfd52..bfda5e2 100755
--- a/android-configure.sh
+++ b/android-configure.sh
@@ -24,7 +24,7 @@
 OPTION_STATIC=no
 OPTION_MINGW=no
 
-GLES_LIBS=
+GLES_DIR=
 GLES_SUPPORT=no
 GLES_PROBE=yes
 
@@ -63,8 +63,7 @@
   ;;
   --static) OPTION_STATIC=yes
   ;;
-  --gles-libs=*) GLES_LIBS=$optarg
-  GLES_SUPPORT=yes
+  --gles-dir=*) GLES_DIR=$optarg
   ;;
   --no-gles) GLES_PROBE=no
   ;;
@@ -97,7 +96,7 @@
     echo "  --static                 build a completely static executable"
     echo "  --verbose                verbose configuration"
     echo "  --debug                  build debug version of the emulator"
-    echo "  --gles-libs=PATH         specify path to GLES emulation host libraries"
+    echo "  --gles-dir=PATH          specify path to GLES host emulation sources [auto-detected]"
     echo "  --no-gles                disable GLES emulation support"
     echo "  --no-pcbios              disable copying of PC Bios files"
     echo ""
@@ -139,6 +138,18 @@
 esac
 
 TARGET_OS=$OS
+
+setup_toolchain
+
+BUILD_AR=$AR
+BUILD_CC=$CC
+BUILD_CXX=$CC
+BUILD_LD=$LD
+BUILD_AR=$AR
+BUILD_CFLAGS=$CFLAGS
+BUILD_CXXFLAGS=$CXXFLAGS
+BUILD_LDFLAGS=$LDFLAGS
+
 if [ "$OPTION_MINGW" = "yes" ] ; then
     enable_linux_mingw
     TARGET_OS=windows
@@ -161,27 +172,6 @@
     IN_ANDROID_BUILD=no
 fi
 
-# This is the list of static and shared host libraries we need to link
-# against in order to support OpenGLES emulation properly. Note that in
-# the case of a standalone build, we will find these libraries inside the
-# platform build tree and copy them into objs/lib/ automatically, unless
-# you use --gles-libs to point explicitely to a different directory.
-#
-GLES_SHARED_LIBRARIES="\
-  libOpenglRender \
-  libGLES_CM_translator \
-  libGLES_V2_translator \
-  libEGL_translator"
-
-if [ "$OPTION_MINGW" != "yes" ]; then
-  # There are no 64-bit libraries for Windows yet!
-  GLES_SHARED_LIBRARIES="$GLES_SHARED_LIBRARIES \
-    lib64OpenglRender \
-    lib64GLES_CM_translator \
-    lib64GLES_V2_translator \
-    lib64EGL_translator"
-fi
-
 if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
     locate_android_prebuilt
 
@@ -214,22 +204,10 @@
     else
         log "Tools      : Could not locate $TOOLS_PROPS !?"
     fi
-
-    GLES_PROBE_LIB_DIR=$(dirname "$HOST_BIN")/lib
-    case $GLES_PROBE_LIB_DIR in
-        */windows/lib)
-            GLES_PROBE_LIB_DIR=${GLES_PROBE_LIB_DIR%%/windows/lib}/windows-x86/lib
-            ;;
-    esac
 else
     if [ "$USE_CCACHE" != 0 ]; then
         CCACHE=$(which ccache 2>/dev/null)
     fi
-    GLES_PROBE_OS=$TARGET_OS
-    if [ "$GLES_PROBE_OS" = "windows" ]; then
-      GLES_PROBE_OS=windows-x86
-    fi
-    GLES_PROBE_LIB_DIR=../../out/host/$GLES_PROBE_OS/lib
 fi  # IN_ANDROID_BUILD = no
 
 if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
@@ -243,41 +221,26 @@
 # Try to find the GLES emulation headers and libraries automatically
 if [ "$GLES_PROBE" = "yes" ]; then
     GLES_SUPPORT=yes
-    if [ -z "$GLES_LIBS" ]; then
-        log "GLES       : Probing for host libraries"
-        GLES_LIBS=$GLES_PROBE_LIB_DIR
-        if [ -d "$GLES_LIBS" ]; then
-            echo "GLES       : Libs in $GLES_LIBS"
-        else
-            echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
+    if [ -z "$GLES_DIR" ]; then
+        GLES_DIR=../../sdk/emulator/opengl
+        log2 "GLES       : Probing source dir: $GLES_DIR"
+        if [ ! -d "$GLES_DIR" ]; then
+            GLES_DIR=../opengl
+            log2 "GLES       : Probing source dir: $GLES_DIR"
+            if [ ! -d "$GLES_DIR" ]; then
+                GLES_DIR=
+            fi
+        fi
+        if [ -z "$GLES_DIR" ]; then
+            echo "GLES       : Could not find GPU emulation sources!"
             GLES_SUPPORT=no
+        else
+            echo "GLES       : Found GPU emulation sources: $GLES_DIR"
+            GLES_SUPPORT=yes
         fi
     fi
 fi
 
-if [ "$GLES_SUPPORT" = "yes" ]; then
-    mkdir -p objs/lib
-
-    for lib in $GLES_SHARED_LIBRARIES; do
-        GLES_LIB=$GLES_LIBS/${lib}$TARGET_DLL_SUFFIX
-        if [ ! -f "$GLES_LIB" ]; then
-            echo "ERROR: Missing OpenGLES emulation host library: $GLES_LIB"
-            echo "Please fix this by using --gles-libs to point to the right directory!"
-            if [ "$IN_ANDROID_BUILD" = "true" ]; then
-                echo "You might also be missing the library because you forgot to rebuild the whole platform!"
-            fi
-            exit 1
-        fi
-        cp $GLES_LIB objs/lib
-        if [ $? != 0 ]; then
-            echo "ERROR: Could not find required OpenGLES emulation library: $GLES_LIB"
-            exit 1
-        else
-            log "GLES       : Copying $GLES_LIB"
-        fi
-    done
-fi
-
 if [ "$PCBIOS_PROBE" = "yes" ]; then
     PCBIOS_DIR=$(dirname "$0")/../../prebuilts/qemu-kernel/x86/pc-bios
     if [ ! -d "$PCBIOS_DIR" ]; then
@@ -531,6 +494,21 @@
 # Build the config.make file
 #
 
+case $OS in
+    windows)
+        HOST_EXEEXT=.exe
+        HOST_DLLEXT=.dll
+        ;;
+    darwin)
+        HOST_EXEEXT=
+        HOST_DLLEXT=.dylib
+        ;;
+    *)
+        HOST_EXEEXT=
+        HOST_DLLEXT=
+        ;;
+esac
+
 case $TARGET_OS in
     windows)
         TARGET_EXEEXT=.exe
@@ -566,6 +544,18 @@
 echo "PREBUILT          := $ANDROID_PREBUILT" >> $config_mk
 echo "PREBUILTS         := $ANDROID_PREBUILTS" >> $config_mk
 
+echo "" >> $config_mk
+echo "BUILD_OS          := $HOST_OS" >> $config_mk
+echo "BUILD_ARCH        := $HOST_ARCH" >> $config_mk
+echo "BUILD_EXEEXT      := $HOST_EXEEXT" >> $config_mk
+echo "BUILD_DLLEXT      := $HOST_DLLEXT" >> $config_mk
+echo "BUILD_AR          := $BUILD_AR" >> $config_mk
+echo "BUILD_CC          := $BUILD_CC" >> $config_mk
+echo "BUILD_CXX         := $BUILD_CXX" >> $config_mk
+echo "BUILD_LD          := $BUILD_LD" >> $config_mk
+echo "BUILD_CFLAGS      := $BUILD_CFLAGS" >> $config_mk
+echo "BUILD_LDFLAGS     := $BUILD_LDFLAGS" >> $config_mk
+
 PWD=`pwd`
 echo "SRC_PATH          := $PWD" >> $config_mk
 if [ -n "$SDL_CONFIG" ] ; then
@@ -584,6 +574,10 @@
 if [ $OPTION_STATIC = yes ] ; then
     echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
 fi
+if [ "$GLES_SUPPORT" = "yes" ]; then
+    echo "EMULATOR_BUILD_EMUGL       := true" >> $config_mk
+    echo "EMULATOR_EMUGL_SOURCES_DIR := $GLES_DIR" >> $config_mk
+fi
 
 if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
     echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk