glapi: Fix OpenGL and OpenGL ES interop.

When --enable-shared-glapi is specified, libGL will share libglapi with
OpenGL ES instead of defining its own copy of glapi.  This makes sure an
app will get only one copy of glapi in its address space.

The new option is disabled by default.  When enabled, libGL and libglapi
must be built from the same source tree and distributed together.  This
requirement comes from the fact that the dispatch offsets used by these
libraries are re-assigned whenever GLAPI XMLs are changed.

For GLX, indirect rendering for has_different_protocol() functions is
tricky.  A has_different_protocol() function is assigned only one
dispatch offset, yet each entry point needs a different protocol opcode.
It cannot be supported by the shared glapi.  The fix to this is to make
glXGetProcAddress handle such functions specially before calling
_glapi_get_proc_address.

Note that these files are automatically generated/re-generated

 src/glx/indirect.c
 src/glx/indirect.h
 src/mapi/glapi/glapi_mapi_tmp.h
diff --git a/configure.ac b/configure.ac
index ba5e12e..1c6edb7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -528,6 +528,18 @@
 fi
 AC_SUBST([API_DEFINES])
 
+AC_ARG_ENABLE([shared-glapi],
+    [AS_HELP_STRING([--enable-shared-glapi],
+        [EXPERIMENTAL.  Enable shared glapi for OpenGL @<:@default=no@:>@])],
+    [enable_shared_glapi="$enableval"],
+    [enable_shared_glapi=no])
+
+SHARED_GLAPI="0"
+if test "x$enable_shared_glapi" = xyes; then
+    SHARED_GLAPI="1"
+fi
+AC_SUBST([SHARED_GLAPI])
+
 dnl
 dnl Driver configuration. Options are xlib, dri and osmesa right now.
 dnl More later: fbdev, ...
@@ -589,8 +601,8 @@
 GALLIUM_DRIVERS_DIRS="softpipe failover galahad trace rbug noop identity"
 GALLIUM_STATE_TRACKERS_DIRS=""
 
-# build shared-glapi if OpenGL ES is enabled
-case "x$enable_gles1$enable_gles2" in
+# build shared-glapi if enabled for OpenGL or if OpenGL ES is enabled
+case "x$enabled_shared_glapi$enable_gles1$enable_gles2" in
 x*yes*)
     CORE_DIRS="$CORE_DIRS mapi/shared-glapi"
     ;;