diff --git a/build/autotools/m4/lol-conf.m4 b/build/autotools/m4/lol-conf.m4
index 3af5bc48..bf23406e 100644
--- a/build/autotools/m4/lol-conf.m4
+++ b/build/autotools/m4/lol-conf.m4
@@ -119,18 +119,19 @@ if test "${enable_gl}" != "no"; then
     AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
     EGL_LIBS="${EGL_LIBS} -lX11"
   fi
-  AC_CHECK_LIB(EGL, main,
-   [ac_cv_my_have_egl="yes"
-    AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
-    EGL_LIBS="-lEGL"])
-  dnl  Raspberry Pi is different, check for it with extra libs; also we
-  dnl  look for a different function to bypass autoconf caching
-  AC_CHECK_LIB(EGL, eglGetDisplay,
-   [ac_cv_my_have_egl="yes"
-    AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
-    EGL_LIBS="-lEGL -lvcos -lvchiq_arm -lbcm_host -lGLESv2"],
-   [:],
-   [-lvcos -lvchiq_arm -lbcm_host -lGLESv2])
+  AC_CHECK_HEADERS(EGL/egl.h,
+   [AC_CHECK_LIB(EGL, eglInitialize,
+     [ac_cv_my_have_egl="yes"
+      AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
+      EGL_LIBS="-lEGL"])
+    dnl  Raspberry Pi is different, check for it with extra libs; also we
+    dnl  look for a different function to bypass autoconf caching
+    AC_CHECK_LIB(EGL, eglGetDisplay,
+     [ac_cv_my_have_egl="yes"
+      AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
+      EGL_LIBS="-lEGL -lvcos -lvchiq_arm -lbcm_host -lGLESv2"],
+     [:],
+     [-lvcos -lvchiq_arm -lbcm_host -lGLESv2])])
 fi
 AM_CONDITIONAL(LOL_USE_EGL, test "${ac_cv_my_have_egl}" != "no")
 
diff --git a/src/eglapp.cpp b/src/eglapp.cpp
index f665ecc0..74c8a587 100644
--- a/src/eglapp.cpp
+++ b/src/eglapp.cpp
@@ -20,8 +20,10 @@
 #       include <X11/Xatom.h>
 #       include <X11/Xutil.h>
 #   endif
-#   include <EGL/egl.h>
-#   include <EGL/eglext.h>
+#   if defined HAVE_EGL_EGL_H
+#       include <EGL/egl.h>
+#       include <EGL/eglext.h>
+#   endif
 #endif
 
 #if LOL_USE_SDL