From 224dfb2570fc7168a07056c1a7f84853f8f2cb12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
Date: Fri, 26 Jun 2015 11:55:06 -0300
Subject: [PATCH] (qb/Makefile.common) Add checks for GLUI and XMB

---
 Makefile.common     | 52 ++++++++++++++++++++++++++-------------------
 qb/config.libs.sh   | 12 +++++++++++
 qb/config.params.sh |  4 ++--
 3 files changed, 44 insertions(+), 24 deletions(-)

diff --git a/Makefile.common b/Makefile.common
index 084778e8d7..cb9c9e7f77 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -1,3 +1,19 @@
+ifeq ($(HAVE_GL_CONTEXT),)
+   HAVE_GL_CONTEXT=0
+
+   ifeq ($(HAVE_OPENGL), 1)
+      HAVE_GL_CONTEXT=1
+   endif
+
+   ifeq ($(HAVE_GLES), 1)
+      HAVE_GL_CONTEXT=1
+   endif
+
+   ifeq ($(HAVE_GLES3), 1)
+      HAVE_GL_CONTEXT=1
+   endif
+endif
+
 ifeq ($(HAVE_LIBRETRODB),)
    HAVE_LIBRETRODB = 1
 endif
@@ -45,13 +61,6 @@ CFLAGS += -I./libretro-common/include
 
 # Switches
 
-# Extra menu drivers if GL supported
-ifeq ($(HAVE_OPENGL), 1)
-ifeq ($(HAVE_RGUI), 1)
-HAVE_GLUI = 1
-HAVE_XMB = 1
-endif
-endif
 
 # System
 
@@ -328,6 +337,20 @@ ifeq ($(HAVE_NEON),1)
    OBJ += audio/audio_utils_neon.o
 endif
 
+# XMB and GLUI are always enabled if supported and not explicitly disabled
+ifeq ($(HAVE_RGUI)$(HAVE_GL_CONTEXT), 11)
+   ifeq ($(HAVE_GLUI),)
+      HAVE_GLUI = 1
+   endif
+
+   ifeq ($(HAVE_XMB),)
+      HAVE_XMB = 1
+   endif
+else
+   HAVE_GLUI = 0
+   HAVE_XMB  = 0
+endif
+
 ifeq ($(HAVE_RGUI), 1)
    OBJ += menu/drivers/rgui.o
    DEFINES += -DHAVE_MENU -DHAVE_RGUI
@@ -482,21 +505,6 @@ ifeq ($(HAVE_PARPORT), 1)
 endif
 
 # Video
-ifeq ($(HAVE_GL_CONTEXT),)
-   HAVE_GL_CONTEXT=0
-
-   ifeq ($(HAVE_OPENGL), 1)
-      HAVE_GL_CONTEXT=1
-   endif
-
-   ifeq ($(HAVE_GLES), 1)
-      HAVE_GL_CONTEXT=1
-   endif
-
-   ifeq ($(HAVE_GLES3), 1)
-      HAVE_GL_CONTEXT=1
-   endif
-endif
 
 ifeq ($(HAVE_GL_CONTEXT), 1)
    DEFINES += -DHAVE_OPENGL -DHAVE_GLSL
diff --git a/qb/config.libs.sh b/qb/config.libs.sh
index 21308f43e0..5969873057 100644
--- a/qb/config.libs.sh
+++ b/qb/config.libs.sh
@@ -386,6 +386,18 @@ check_lib MMAP "$CLIB" mmap
 
 check_pkgconf PYTHON python3
 
+if [ "$HAVE_GLUI" != 'no' ] || [ "$HAVE_XMB" != 'no' ]; then
+	if [ "$HAVE_RGUI" = 'no' ]; then
+		HAVE_GLUI=no
+		HAVE_XMB=no
+		echo "Notice: RGUI not available, GLUI and XMB will be disabled."
+	elif [ "$HAVE_OPENGL" = 'no' ] && [ "$HAVE_GLES" = 'no' ]; then
+		HAVE_GLUI=no
+		HAVE_XMB=no
+		echo "Notice: GL/GLES not available, XMB and GLUI will be disabled."
+	fi
+fi
+
 check_macro NEON __ARM_NEON__
 
 add_define_make OS "$OS"
diff --git a/qb/config.params.sh b/qb/config.params.sh
index f01b734e2a..e639faad0f 100644
--- a/qb/config.params.sh
+++ b/qb/config.params.sh
@@ -1,7 +1,7 @@
 HAVE_LIBRETRODB=yes     # Disable libretrodb
 HAVE_RGUI=yes           # Disable RGUI
-HAVE_GLUI=no            # Enable GLUI menu
-HAVE_XMB=no             # Enable XMB menu
+HAVE_GLUI=auto          # Enable GLUI menu
+HAVE_XMB=auto           # Enable XMB menu
 HAVE_DYNAMIC=yes        # Disable dynamic loading of libretro library
 HAVE_SDL=auto           # SDL support
 HAVE_SDL2=auto          # SDL2 support (disables SDL 1.x)