Add build variables to make host build more convenient

bug: 115618941

- Avoid clobbering EMUGL_PATH
- Set the right build variables if GOLDFISH_OPENGL_HOST_BUILD is set

As we get more of it building, move the "TODO" line down more
in the top-level Android.mk

Change-Id: I02e7cc3f82fd8561f8c3ef847fcf08b657334995
diff --git a/Android.mk b/Android.mk
index d598d71..6fce2df 100644
--- a/Android.mk
+++ b/Android.mk
@@ -7,22 +7,63 @@
 # Also define BUILD_EMULATOR_OPENGL_DRIVER to 'true' to build the gralloc
 # stuff as well.
 #
-ifeq (true,$(BUILD_EMULATOR_OPENGL))
-
 # Top-level for all modules
-EMUGL_PATH := $(call my-dir)
+GOLDFISH_OPENGL_PATH := $(call my-dir)
+
+# There are two kinds of builds for goldfish-opengl:
+# 1. The standard guest build, denoted by BUILD_EMULATOR_OPENGL
+# 2. The host-side build, denoted by GOLDFISH_OPENGL_BUILD_FOR_HOST
+#
+# Variable controlling whether the build for goldfish-opengl
+# libraries (including their Android.mk's) should be triggered.
+GOLDFISH_OPENGL_SHOULD_BUILD := false
+
+# In the host build, some libraries have name collisions with
+# other libraries, so we have this variable here to control
+# adding a suffix to the names of libraries. Should be blank
+# for the guest build.
+GOLDFISH_OPENGL_LIB_SUFFIX :=
 
 # Directory containing common headers used by several modules
 # This is always set to a module's LOCAL_C_INCLUDES
 # See the definition of emugl-begin-module in common.mk
-#
-EMUGL_COMMON_INCLUDES := $(EMUGL_PATH)/host/include/libOpenglRender $(EMUGL_PATH)/system/include
+EMUGL_COMMON_INCLUDES := $(GOLDFISH_OPENGL_PATH)/host/include/libOpenglRender $(GOLDFISH_OPENGL_PATH)/system/include
 
 # common cflags used by several modules
 # This is always set to a module's LOCAL_CFLAGS
 # See the definition of emugl-begin-module in common.mk
-#
-EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
+EMUGL_COMMON_CFLAGS := -DWITH_GLES2
+
+# Host build
+ifeq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
+
+GOLDFISH_OPENGL_SHOULD_BUILD := true
+GOLDFISH_OPENGL_LIB_SUFFIX := _host
+
+# Set modern defaults for the codename, version, etc.
+PLATFORM_VERSION_CODENAME:=Q
+PLATFORM_SDK_VERSION:=29
+IS_AT_LEAST_OPD1:=true
+
+# The host-side Android framework implementation
+HOST_EMUGL_PATH := $(GOLDFISH_OPENGL_PATH)/../../../external/qemu/android/android-emugl
+EMUGL_COMMON_INCLUDES += $(HOST_EMUGL_PATH)/guest
+
+EMUGL_COMMON_CFLAGS += \
+    -DPLATFORM_SDK_VERSION=29 \
+    -DGOLDFISH_HIDL_GRALLOC \
+    -DEMULATOR_OPENGL_POST_O=1 \
+    -DHOST_BUILD \
+    -DANDROID \
+    -DGL_GLEXT_PROTOTYPES \
+
+endif # GOLDFISH_OPENGL_BUILD_FOR_HOST
+
+ifeq (true,$(BUILD_EMULATOR_OPENGL)) # Guest build
+
+GOLDFISH_OPENGL_SHOULD_BUILD := true
+
+EMUGL_COMMON_CFLAGS += -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
 
 ifeq (O, $(PLATFORM_VERSION_CODENAME))
 EMUGL_COMMON_CFLAGS += -DGOLDFISH_HIDL_GRALLOC
@@ -49,15 +90,19 @@
     EMUGL_COMMON_CFLAGS += -DALOGV=LOGV
 endif
 
-# Uncomment the following line if you want to enable debug traces
-# in the GLES emulation libraries.
-# EMUGL_COMMON_CFLAGS += -DEMUGL_DEBUG=1
-
 # Include common definitions used by all the modules included later
 # in this build file. This contains the definition of all useful
 # emugl-xxxx functions.
 #
-include $(EMUGL_PATH)/common.mk
+include $(GOLDFISH_OPENGL_PATH)/common.mk
+
+endif # BUILD_EMULATOR_OPENGL (guest build)
+
+ifeq (true,$(GOLDFISH_OPENGL_SHOULD_BUILD))
+
+# Uncomment the following line if you want to enable debug traces
+# in the GLES emulation libraries.
+# EMUGL_COMMON_CFLAGS += -DEMUGL_DEBUG=1
 
 # IMPORTANT: ORDER IS CRUCIAL HERE
 #
@@ -71,20 +116,30 @@
 # Note that the build system will complain if you try to import a
 # module that hasn't been declared yet anyway.
 #
+include $(GOLDFISH_OPENGL_PATH)/shared/OpenglCodecCommon/Android.mk
 
-include $(EMUGL_PATH)/shared/OpenglCodecCommon/Android.mk
+# Encoder shared libraries
+include $(GOLDFISH_OPENGL_PATH)/system/GLESv1_enc/Android.mk
+include $(GOLDFISH_OPENGL_PATH)/system/GLESv2_enc/Android.mk
+include $(GOLDFISH_OPENGL_PATH)/system/renderControl_enc/Android.mk
 
-# System static libraries
-include $(EMUGL_PATH)/system/GLESv1_enc/Android.mk
-include $(EMUGL_PATH)/system/GLESv2_enc/Android.mk
-include $(EMUGL_PATH)/system/renderControl_enc/Android.mk
-include $(EMUGL_PATH)/system/OpenglSystemCommon/Android.mk
+# TODO: Get the rest of the libraries to build on host
+# From here, we require more android framework
+# reimplementations on host:
+# goldfish_dma
+# sockets
+# etc.
+ifneq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
+
+include $(GOLDFISH_OPENGL_PATH)/system/OpenglSystemCommon/Android.mk
 
 # System shared libraries
-include $(EMUGL_PATH)/system/GLESv1/Android.mk
-include $(EMUGL_PATH)/system/GLESv2/Android.mk
+include $(GOLDFISH_OPENGL_PATH)/system/GLESv1/Android.mk
+include $(GOLDFISH_OPENGL_PATH)/system/GLESv2/Android.mk
 
-include $(EMUGL_PATH)/system/gralloc/Android.mk
-include $(EMUGL_PATH)/system/egl/Android.mk
+include $(GOLDFISH_OPENGL_PATH)/system/gralloc/Android.mk
+include $(GOLDFISH_OPENGL_PATH)/system/egl/Android.mk
 
-endif # BUILD_EMULATOR_OPENGL == true
+endif # !GOLDFISH_OPENGL_BUILD_FOR_HOST
+
+endif