=== modified file 'android/jni/Android.mk'
--- android/jni/Android.mk	2013-03-01 15:22:03 +0000
+++ android/jni/Android.mk	2013-03-05 09:56:31 +0000
@@ -4,7 +4,7 @@
 
 LOCAL_CPP_EXTENSION := .cc
 LOCAL_MODULE := libglmark2-matrix
-LOCAL_CFLAGS := -DUSE_GLESv2 -Werror -Wall -Wextra -Wnon-virtual-dtor \
+LOCAL_CFLAGS := -DGLMARK2_USE_GLESv2 -Werror -Wall -Wextra -Wnon-virtual-dtor \
                 -Wno-error=unused-parameter
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/src
 LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/libmatrix/*.cc))
@@ -38,7 +38,7 @@
 
 LOCAL_CPP_EXTENSION := .cc
 LOCAL_MODULE := libglmark2-ideas
-LOCAL_CFLAGS := -DGLMARK_DATA_PATH="" -DUSE_GLESv2 -Werror -Wall -Wextra\
+LOCAL_CFLAGS := -DGLMARK_DATA_PATH="" -DGLMARK2_USE_GLESv2 -Werror -Wall -Wextra\
                 -Wnon-virtual-dtor -Wno-error=unused-parameter
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/src \
                     $(LOCAL_PATH)/src/libmatrix
@@ -55,7 +55,7 @@
 LOCAL_MODULE := libglmark2-android
 LOCAL_STATIC_LIBRARIES := libglmark2-matrix libglmark2-png libglmark2-ideas libglmark2-jpeg
 LOCAL_CFLAGS := -DGLMARK_DATA_PATH="" -DGLMARK_VERSION="\"2012.12\"" \
-                -DUSE_GLESv2 -Werror -Wall -Wextra -Wnon-virtual-dtor \
+                -DGLMARK2_USE_GLESv2 -Werror -Wall -Wextra -Wnon-virtual-dtor \
                 -Wno-error=unused-parameter
 LOCAL_SHARED_LIBRARIES := liblog libz libEGL libGLESv2 libandroid libdl libstlport
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/src \

=== modified file 'android/jni/Android.ndk.mk'
--- android/jni/Android.ndk.mk	2013-03-01 15:22:03 +0000
+++ android/jni/Android.ndk.mk	2013-03-05 09:56:31 +0000
@@ -4,7 +4,7 @@
 
 LOCAL_CPP_EXTENSION := .cc
 LOCAL_MODULE := libglmark2-matrix
-LOCAL_CFLAGS := -DUSE_GLESv2 -Werror -Wall -Wextra -Wnon-virtual-dtor \
+LOCAL_CFLAGS := -DGLMARK2_USE_GLESv2 -Werror -Wall -Wextra -Wnon-virtual-dtor \
                 -Wno-error=unused-parameter
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/src
 LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/libmatrix/*.cc))
@@ -34,7 +34,7 @@
 
 LOCAL_CPP_EXTENSION := .cc
 LOCAL_MODULE := libglmark2-ideas
-LOCAL_CFLAGS := -DGLMARK_DATA_PATH="" -DUSE_GLESv2 -Werror -Wall -Wextra\
+LOCAL_CFLAGS := -DGLMARK_DATA_PATH="" -DGLMARK2_USE_GLESv2 -Werror -Wall -Wextra\
                 -Wnon-virtual-dtor -Wno-error=unused-parameter
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/src \
                     $(LOCAL_PATH)/src/libmatrix
@@ -48,7 +48,7 @@
 LOCAL_MODULE := libglmark2-android
 LOCAL_STATIC_LIBRARIES := libglmark2-matrix libglmark2-png libglmark2-ideas libglmark2-jpeg
 LOCAL_CFLAGS := -DGLMARK_DATA_PATH="" -DGLMARK_VERSION="\"2012.12\"" \
-                -DUSE_GLESv2 -Werror -Wall -Wextra -Wnon-virtual-dtor \
+                -DGLMARK2_USE_GLESv2 -Werror -Wall -Wextra -Wnon-virtual-dtor \
                 -Wno-error=unused-parameter
 LOCAL_LDLIBS := -landroid -llog -lGLESv2 -lEGL -lz
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/src \

=== modified file 'src/canvas-generic.cpp'
--- src/canvas-generic.cpp	2013-03-01 14:48:21 +0000
+++ src/canvas-generic.cpp	2013-03-04 19:07:07 +0000
@@ -89,9 +89,9 @@
 CanvasGeneric::clear()
 {
     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-#if USE_GL
+#if GLMARK2_USE_GL
     glClearDepth(1.0f);
-#elif USE_GLESv2
+#elif GLMARK2_USE_GLESv2
     glClearDepthf(1.0f);
 #endif
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -310,7 +310,7 @@
     bool supports_depth24(false);
     bool supports_depth32(false);
 
-#if USE_GLESv2
+#if GLMARK2_USE_GLESv2
     if (GLExtensions::support("GL_ARM_rgba8"))
         supports_rgba8 = true;
 
@@ -324,7 +324,7 @@
 
     if (GLExtensions::support("GL_OES_depth32"))
         supports_depth32 = true;
-#elif USE_GL
+#elif GLMARK2_USE_GL
     supports_rgba8 = true;
     supports_rgb8 = true;
     supports_depth24 = true;

=== modified file 'src/gl-headers.h'
--- src/gl-headers.h	2012-03-20 11:29:09 +0000
+++ src/gl-headers.h	2013-03-04 19:07:07 +0000
@@ -24,13 +24,13 @@
 
 #define GL_GLEXT_PROTOTYPES
 
-#if USE_GL
+#if GLMARK2_USE_GL
 #include <GL/gl.h>
 #include <GL/glext.h>
 #ifndef GL_RGB565
 #define GL_RGB565 0x8D62
 #endif
-#elif USE_GLESv2
+#elif GLMARK2_USE_GLESv2
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 #ifndef GL_WRITE_ONLY

=== modified file 'src/gl-state-egl.cpp'
--- src/gl-state-egl.cpp	2013-03-03 10:18:39 +0000
+++ src/gl-state-egl.cpp	2013-03-04 19:07:07 +0000
@@ -307,14 +307,14 @@
 void
 GLStateEGL::init_gl_extensions()
 {
-#if USE_GLESv2
+#if GLMARK2_USE_GLESv2
     if (GLExtensions::support("GL_OES_mapbuffer")) {
         GLExtensions::MapBuffer =
             reinterpret_cast<PFNGLMAPBUFFEROESPROC>(eglGetProcAddress("glMapBufferOES"));
         GLExtensions::UnmapBuffer =
             reinterpret_cast<PFNGLUNMAPBUFFEROESPROC>(eglGetProcAddress("glUnmapBufferOES"));
     }
-#elif USE_GL
+#elif GLMARK2_USE_GL
     GLExtensions::MapBuffer = glMapBuffer;
     GLExtensions::UnmapBuffer = glUnmapBuffer;
 #endif
@@ -428,9 +428,9 @@
         return false;
     }
 
-#if USE_GLESv2
+#if GLMARK2_USE_GLESv2
     EGLenum apiType(EGL_OPENGL_ES_API);
-#elif USE_GL
+#elif GLMARK2_USE_GL
     EGLenum apiType(EGL_OPENGL_API);
 #endif
     if (!eglBindAPI(apiType)) {
@@ -500,9 +500,9 @@
         EGL_ALPHA_SIZE, requested_visual_config_.alpha,
         EGL_DEPTH_SIZE, requested_visual_config_.depth,
         EGL_STENCIL_SIZE, requested_visual_config_.stencil,
-#if USE_GLESv2
+#if GLMARK2_USE_GLESv2
         EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
-#elif USE_GL
+#elif GLMARK2_USE_GL
         EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
 #endif
         EGL_NONE
@@ -600,7 +600,7 @@
         return false;
 
     static const EGLint context_attribs[] = {
-#ifdef USE_GLESv2
+#ifdef GLMARK2_USE_GLESv2
         EGL_CONTEXT_CLIENT_VERSION, 2,
 #endif
         EGL_NONE

=== modified file 'src/main.cpp'
--- src/main.cpp	2013-03-01 14:57:51 +0000
+++ src/main.cpp	2013-03-04 19:07:07 +0000
@@ -37,15 +37,16 @@
 
 #include "canvas-generic.h"
 
-#if USE_DRM
+#if GLMARK2_USE_X11
+#include "native-state-x11.h"
+#elif GLMARK2_USE_DRM
 #include "native-state-drm.h"
+#endif
+
+#if GLMARK2_USE_EGL
 #include "gl-state-egl.h"
-#elif USE_GL
-#include "native-state-x11.h"
+#elif GLMARK2_USE_GLX
 #include "gl-state-glx.h"
-#elif USE_GLESv2
-#include "native-state-x11.h"
-#include "gl-state-egl.h"
 #endif
 
 using std::vector;
@@ -187,15 +188,16 @@
     }
 
     // Create the canvas
-#if USE_DRM
+#if GLMARK2_USE_X11
+    NativeStateX11 native_state;
+#elif GLMARK2_USE_DRM
     NativeStateDRM native_state;
+#endif
+
+#if GLMARK2_USE_EGL
     GLStateEGL gl_state;
-#elif USE_GL
-    NativeStateX11 native_state;
+#elif GLMARK2_USE_GLX
     GLStateGLX gl_state;
-#elif USE_GLESv2
-    NativeStateX11 native_state;
-    GLStateEGL gl_state;
 #endif
 
     CanvasGeneric canvas(native_state, gl_state, Options::size.first, Options::size.second);

=== modified file 'src/wscript_build'
--- src/wscript_build	2013-03-01 14:57:51 +0000
+++ src/wscript_build	2013-03-04 19:07:07 +0000
@@ -3,91 +3,72 @@
                                             f.name.find('android') == -1 and
                                             f.name.find('native-state-') == -1 and
                                             f.name.find('gl-state-') == -1]
-gl_sources = ['canvas-generic.cpp', 'native-state-x11.cpp', 'gl-state-glx.cpp']
-glesv2_sources = ['canvas-generic.cpp', 'native-state-x11.cpp', 'gl-state-egl.cpp']
-gl_drm_sources = ['canvas-generic.cpp', 'native-state-drm.cpp', 'gl-state-egl.cpp']
-glesv2_drm_sources = ['canvas-generic.cpp', 'native-state-drm.cpp', 'gl-state-egl.cpp']
+common_uselibs = ['libpng12']
+common_defines = ['USE_EXCEPTIONS']
+
 libmatrix_sources = [f for f in bld.path.ant_glob('libmatrix/*.cc')
                      if not f.name.endswith('test.cc')]
+flavor_sources = {
+  'x11-gl' : ['canvas-generic.cpp', 'native-state-x11.cpp', 'gl-state-glx.cpp'],
+  'x11-glesv2' : ['canvas-generic.cpp', 'native-state-x11.cpp', 'gl-state-egl.cpp'],
+  'drm-gl' : ['canvas-generic.cpp', 'native-state-drm.cpp', 'gl-state-egl.cpp'],
+  'drm-glesv2' : ['canvas-generic.cpp', 'native-state-drm.cpp', 'gl-state-egl.cpp']
+}
+flavor_target = {
+  'x11-gl' : 'glmark2',
+  'x11-glesv2' : 'glmark2-es2',
+  'drm-gl' : 'glmark2-drm',
+  'drm-glesv2' : 'glmark2-es2-drm'
+}
+flavor_uselibs = {
+  'x11-gl' : ['x11', 'gl', 'matrix-gl'],
+  'x11-glesv2' : ['x11', 'egl', 'glesv2', 'matrix-glesv2'],
+  'drm-gl' : ['drm', 'gbm', 'egl', 'gl', 'matrix-gl'],
+  'drm-glesv2' : ['drm', 'gbm', 'egl', 'glesv2', 'matrix-gl'],
+}
+flavor_defines = {
+  'x11-gl' : ['GLMARK2_USE_X11', 'GLMARK2_USE_GL', 'GLMARK2_USE_GLX'],
+  'x11-glesv2' : ['GLMARK2_USE_X11', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL'],
+  'drm-gl' : ['GLMARK2_USE_DRM', 'GLMARK2_USE_GL', 'GLMARK2_USE_EGL', '__GBM__'],
+  'drm-glesv2' : ['GLMARK2_USE_DRM', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL', '__GBM__']
+}
+
 includes = ['.', 'scene-ideas', 'scene-terrain']
 
-if bld.env.USE_GL:
-    bld(
-        features = ['cxx', 'cxxstlib'],
-        source   = libmatrix_sources,
-        target   = 'matrix',
-        lib      = ['m'],
-        includes = ['.'],
-        export_includes = 'libmatrix',
-        defines  = ['USE_GL', 'USE_EXCEPTIONS']
-        )
-    bld(
-        features     = ['cxx', 'cprogram'],
-        source       = common_sources + gl_sources,
-        target       = 'glmark2',
-        use          = ['x11', 'gl', 'matrix', 'libpng12'],
-        lib          = ['m', 'jpeg'],
-        includes     = includes,
-        defines      = ['USE_GL', 'USE_EXCEPTIONS']
-        )
-
-if bld.env.USE_GLESv2:
-    bld(
-        features = ['cxx', 'cxxstlib'],
-        source   = libmatrix_sources,
-        target   = 'matrix-es2',
-        lib      = ['m'],
-        includes = ['.'],
-        export_includes = 'libmatrix',
-        defines  = ['USE_GLESv2', 'USE_EXCEPTIONS']
-        )
-    bld(
-        features     = ['cxx', 'cprogram'],
-        source       = common_sources + glesv2_sources,
-        target       = 'glmark2-es2',
-        use          = ['x11', 'egl', 'glesv2', 'matrix-es2', 'libpng12'],
-        lib          = ['m', 'dl', 'jpeg'],
-        includes     = includes,
-        defines      = ['USE_GLESv2', 'USE_EXCEPTIONS']
-        )
-
-if bld.env.USE_GL_DRM:
-    bld(
-        features = ['cxx', 'cxxstlib'],
-        source   = libmatrix_sources,
-        target   = 'matrix-drm',
-        lib      = ['m'],
-        includes = ['.'],
-        export_includes = 'libmatrix',
-        defines  = ['USE_DRM', '__GBM__', 'USE_GL', 'USE_EXCEPTIONS']
-        )
-    bld(
-        features     = ['cxx', 'cprogram'],
-        source       = common_sources + gl_drm_sources,
-        target       = 'glmark2-drm',
-        use          = ['egl', 'gl', 'matrix-drm', 'libpng12', 'drm', 'gbm'],
-        lib          = ['m', 'jpeg', 'dl'],
-        includes     = includes,
-        defines      = ['USE_DRM', '__GBM__', 'USE_GL']
-        )
-
-if bld.env.USE_GLESv2_DRM:
-    bld(
-        features = ['cxx', 'cxxstlib'],
-        source   = libmatrix_sources,
-        target   = 'matrix-es2-drm',
-        lib      = ['m'],
-        includes = ['.'],
-        export_includes = 'libmatrix',
-        defines  = ['USE_DRM', '__GBM__', 'USE_GLESv2', 'USE_EXCEPTIONS']
-        )
-    bld(
-        features     = ['cxx', 'cprogram'],
-        source       = common_sources + glesv2_drm_sources,
-        target       = 'glmark2-es2-drm',
-        use          = ['egl', 'glesv2', 'matrix-es2-drm', 'libpng12', 'drm',
-                        'gbm'],
-        lib          = ['m', 'jpeg', 'dl'],
-        includes     = includes,
-        defines      = ['USE_DRM', '__GBM__', 'USE_GLESv2']
+all_uselibs = set()
+
+for name in bld.env.keys():
+    if name.startswith('FLAVOR_') and bld.env[name]:
+        flavor = name.replace('FLAVOR_', '').lower().replace('_', '-')
+        bld(
+            features     = ['cxx', 'cprogram'],
+            source       = common_sources + flavor_sources[flavor],
+            target       = flavor_target[flavor],
+            use          = common_uselibs + flavor_uselibs[flavor],
+            lib          = ['m', 'jpeg', 'dl'],
+            includes     = includes,
+            defines      = common_defines + flavor_defines[flavor]
+            )
+        all_uselibs |= set(flavor_uselibs[flavor])
+        
+if 'matrix-gl' in all_uselibs:
+    bld(
+        features = ['cxx', 'cxxstlib'],
+        source   = libmatrix_sources,
+        target   = 'matrix-gl',
+        lib      = ['m'],
+        includes = ['.'],
+        export_includes = 'libmatrix',
+        defines  = ['GLMARK2_USE_GL', 'USE_EXCEPTIONS']
+        )
+
+if 'matrix-glesv2' in all_uselibs:
+    bld(
+        features = ['cxx', 'cxxstlib'],
+        source   = libmatrix_sources,
+        target   = 'matrix-glesv2',
+        lib      = ['m'],
+        includes = ['.'],
+        export_includes = 'libmatrix',
+        defines  = ['GLMARK2_USE_GLESv2', 'USE_EXCEPTIONS']
         )

=== modified file 'wscript'
--- wscript	2012-12-18 19:44:34 +0000
+++ wscript	2013-03-04 19:07:07 +0000
@@ -11,20 +11,32 @@
 VERSION = '2012.12'
 APPNAME = 'glmark2'
 
+FLAVORS = ['x11-gl', 'x11-glesv2', 'drm-gl', 'drm-glesv2']
+FLAVORS_STR = ", ".join(FLAVORS)
+
+def option_list_cb(option, opt, value, parser):
+    value = value.split(',')
+    setattr(parser.values, option.dest, value)
+
+def list_contains(lst, token):
+    for e in lst:
+        if token.endswith('$'):
+            if e.endswith(token[:-1]): return True
+        elif token in e: return True
+
+    return False
+
 def options(opt):
     opt.tool_options('gnu_dirs')
     opt.tool_options('compiler_cc')
     opt.tool_options('compiler_cxx')
 
-    opt.add_option('--enable-gl', action='store_true', dest = 'gl',
-                   default = False, help='build using OpenGL 2.0')
-    opt.add_option('--enable-glesv2', action='store_true', dest = 'glesv2',
-                   default = False, help='build using OpenGL ES 2.0')
-    opt.add_option('--enable-gl-drm', action='store_true', dest = 'gl_drm',
-                   default = False, help='build using OpenGL 2.0 without X')
-    opt.add_option('--enable-glesv2-drm', action='store_true',
-                   dest = 'glesv2_drm',
-                   default = False, help='build using OpenGL ES 2.0 without X')
+    opt.add_option('--with-flavors', type = 'string', action='callback',
+                   callback=option_list_cb,
+                   dest = 'flavors',
+                   help = "a list of flavors to build (%s, all)" % FLAVORS_STR)
+    opt.parser.set_default('flavors', [])
+
     opt.add_option('--no-debug', action='store_false', dest = 'debug',
                    default = True, help='disable compiler debug information')
     opt.add_option('--no-opt', action='store_false', dest = 'opt',
@@ -35,10 +47,21 @@
                    help='path to additional data (models, shaders, textures)')
 
 def configure(ctx):
-    if not Options.options.gl and not Options.options.glesv2 and \
-       not Options.options.gl_drm and not Options.options.glesv2_drm:
-        ctx.fatal("You must configure using at least one of --enable-gl, " +
-                  "--enable-glesv2, --enable-gl-drm, --enable-glesv2-drm")
+    # Special 'all' flavor
+    if 'all' in Options.options.flavors:
+        Options.options.flavors = list(set(Options.options.flavors) | set(FLAVORS))
+        Options.options.flavors.remove('all')
+
+    # Ensure the flavors are valid
+    for flavor in Options.options.flavors:
+       if flavor not in FLAVORS:
+            ctx.fatal('Unknown flavor: %s. Supported flavors are %s' % (flavor, FLAVORS_STR))
+
+    if not Options.options.flavors:
+        ctx.fatal('You need to select at least one flavor. Supported flavors are %s' % FLAVORS_STR)
+
+    for flavor in FLAVORS:
+        ctx.env["FLAVOR_%s" % flavor.upper().replace('-','_')] = flavor in Options.options.flavors
 
     ctx.check_tool('gnu_dirs')
     ctx.check_tool('compiler_cc')
@@ -67,16 +90,12 @@
                       args = '--cflags --libs', mandatory = True)
 
     # Check optional packages
-    opt_pkgs = [('x11', 'x11', Options.options.gl or Options.options.glesv2),
-                ('gl', 'gl', Options.options.gl or Options.options.gl_drm),
-                ('egl', 'egl', Options.options.glesv2 or
-                               Options.options.glesv2_drm),
-                ('glesv2', 'glesv2', Options.options.glesv2 or
-                                     Options.options.glesv2_drm),
-                ('libdrm','drm', Options.options.gl_drm or
-                                 Options.options.glesv2_drm),
-                ('gbm','gbm', Options.options.gl_drm or
-                              Options.options.glesv2_drm)]
+    opt_pkgs = [('x11', 'x11', list_contains(Options.options.flavors, 'x11')),
+                ('gl', 'gl', list_contains(Options.options.flavors, 'gl$')),
+                ('egl', 'egl', list_contains(Options.options.flavors, 'glesv2$')),
+                ('glesv2', 'glesv2', list_contains(Options.options.flavors, 'glesv2$')),
+                ('libdrm','drm', list_contains(Options.options.flavors, 'drm')),
+                ('gbm','gbm', list_contains(Options.options.flavors, 'drm'))]
     for (pkg, uselib, mandatory) in opt_pkgs:
         ctx.check_cfg(package = pkg, uselib_store = uselib,
                       args = '--cflags --libs', mandatory = mandatory)
@@ -106,25 +125,13 @@
     ctx.env.append_unique('DEFINES', 'GLMARK_VERSION="%s"' % VERSION)
     ctx.env.GLMARK2_VERSION = VERSION
 
-    ctx.env.USE_GL = Options.options.gl
-    ctx.env.USE_GLESv2 = Options.options.glesv2
-    ctx.env.USE_GL_DRM = Options.options.gl_drm
-    ctx.env.USE_GLESv2_DRM = Options.options.glesv2_drm
-
     ctx.msg("Prefix", ctx.env.PREFIX, color = 'PINK')
     ctx.msg("Data path", data_path, color = 'PINK')
     ctx.msg("Including extras", "Yes" if ctx.env.HAVE_EXTRAS else "No",
             color = 'PINK');
     if ctx.env.HAVE_EXTRAS:
         ctx.msg("Extras path", Options.options.extras_path, color = 'PINK')
-    ctx.msg("Building X11 GL2 version", "Yes" if ctx.env.USE_GL else "No",
-            color = 'PINK')
-    ctx.msg("Building X11 GLESv2 version", "Yes" if ctx.env.USE_GLESv2 else "No",
-            color = 'PINK')
-    ctx.msg("Building DRM GL2 version", "Yes" if ctx.env.USE_GL_DRM else "No",
-            color = 'PINK')
-    ctx.msg("Building DRM GLESv2 version", "Yes" if ctx.env.USE_GLESv2_DRM else "No",
-            color = 'PINK')
+    ctx.msg("Building flavors", Options.options.flavors)
 
 def build(ctx):
     ctx.recurse('src')

