From ddc05759f098f06bd93253a7bffe38640963dfb3 Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Fri, 11 Jan 2013 08:00:45 +0100
Subject: fontconfig libX11 mesa mkfontscale xserver git update 11 jan 2013

fontconfig: 0831c1770e4bac7269a190936bbb0529d747e233
libX11: 0b148750027fd0557c5ed93afda861ddf4b92e0f
mkfontscale: 9cbe3256bc932b82f2435b23cda0931f4f5f5ba2
xserver: 6703a7c7cf1a349c137e247a0c8eb462ff7b07be
mesa: babab2876080af0fe65249dff559244aebd0b87e
---
 fontconfig/Makefile.am                             |    2 +-
 fontconfig/README                                  |  105 +-
 fontconfig/autogen.sh                              |    4 +-
 fontconfig/configure.ac                            |   25 +-
 fontconfig/doc/fclangset.fncs                      |    8 +
 fontconfig/doc/func.sgml                           |    2 +-
 fontconfig/fc-validate/Makefile.am                 |   60 ++
 fontconfig/fc-validate/fc-validate.c               |  242 +++++
 fontconfig/fc-validate/fc-validate.sgml            |  182 ++++
 fontconfig/fontconfig/fontconfig.h                 |    5 +-
 fontconfig/new-version.sh                          |    4 +-
 fontconfig/src/fcatomic.h                          |   12 +
 fontconfig/src/fcint.h                             |    3 -
 fontconfig/src/fcstr.c                             |   13 +-
 fontconfig/test/Makefile.am                        |   11 +
 fontconfig/test/test-pthread.c                     |   79 ++
 libX11/configure.ac                                |    2 +-
 mesalib/.gitignore                                 |    6 +-
 mesalib/Makefile.am                                |   18 -
 mesalib/acinclude.m4                               |  119 ---
 mesalib/bin/installmesa                            |   74 --
 mesalib/bin/minstall                               |  112 --
 mesalib/bin/mklib                                  | 1043 ------------------
 mesalib/configs/.gitignore                         |    2 -
 mesalib/configs/current.in                         |  222 ----
 mesalib/configs/default                            |  180 ----
 mesalib/configure.ac                               |  182 +++-
 mesalib/docs/devinfo.html                          |    2 -
 mesalib/src/.gitignore                             |    3 -
 mesalib/src/gallium/.gitignore                     |    1 -
 mesalib/src/gallium/Automake.inc                   |    5 +
 mesalib/src/gallium/Makefile.template              |   73 --
 mesalib/src/gallium/auxiliary/Makefile             |   47 -
 mesalib/src/gallium/auxiliary/Makefile.am          |   51 +
 mesalib/src/gallium/auxiliary/util/u_pack_color.h  |    2 +
 mesalib/src/glsl/.gitignore                        |    1 -
 mesalib/src/glsl/Makefile.sources                  |    1 +
 mesalib/src/glsl/Makefile.template                 |   50 -
 mesalib/src/glsl/ast_to_hir.cpp                    |   99 +-
 mesalib/src/glsl/builtin_compiler/.gitignore       |    1 -
 mesalib/src/glsl/glcpp/.gitignore                  |    2 -
 mesalib/src/glsl/glsl_parser.yy                    |    1 -
 mesalib/src/glsl/link_varyings.cpp                 | 1051 ++++++++++++++++++
 mesalib/src/glsl/link_varyings.h                   |  186 ++++
 mesalib/src/glsl/linker.cpp                        | 1127 +-------------------
 mesalib/src/glsl/linker.h                          |    9 +
 mesalib/src/glsl/loop_controls.cpp                 |    8 +-
 mesalib/src/glsl/lower_packed_varyings.cpp         |   95 +-
 mesalib/src/mapi/glapi/.gitignore                  |    1 -
 mesalib/src/mapi/glapi/gen/.gitignore              |    1 -
 .../src/mapi/glapi/gen/ARB_ES3_compatibility.xml   |   23 +
 mesalib/src/mapi/glapi/gen/GL3x.xml                |    2 +-
 mesalib/src/mapi/glapi/gen/Makefile.am             |   12 +-
 mesalib/src/mapi/glapi/gen/gl_API.xml              |   14 +-
 mesalib/src/mesa/.gitignore                        |    1 -
 mesalib/src/mesa/drivers/.gitignore                |    1 -
 mesalib/src/mesa/drivers/dri/.gitignore            |    1 -
 mesalib/src/mesa/drivers/dri/swrast/.gitignore     |    1 -
 mesalib/src/mesa/main/context.c                    |    3 +
 mesalib/src/mesa/main/extensions.c                 |    3 +-
 mesalib/src/mesa/main/fbobject.c                   |    2 +-
 mesalib/src/mesa/main/get.c                        |   49 +-
 mesalib/src/mesa/main/get.h                        |    2 +-
 mesalib/src/mesa/main/get_hash_generator.py        |    8 +-
 mesalib/src/mesa/main/get_hash_params.py           |  122 ++-
 mesalib/src/mesa/main/macros.h                     |   13 +
 mesalib/src/mesa/main/mtypes.h                     |   12 +
 mesalib/src/mesa/program/.gitignore                |    1 -
 mesalib/src/mesa/program/Makefile.am               |    2 +-
 mesalib/src/mesa/state_tracker/Makefile            |    2 -
 mesalib/src/mesa/state_tracker/st_cb_texture.c     |    4 +-
 mesalib/src/mesa/x86/.gitignore                    |    1 -
 mkfontscale/mkfontscale.c                          |   24 +-
 xorg-server/hw/xfree86/modes/xf86Crtc.c            |   15 +-
 xorg-server/include/dixstruct.h                    |   12 +-
 75 files changed, 2585 insertions(+), 3279 deletions(-)
 create mode 100644 fontconfig/fc-validate/Makefile.am
 create mode 100644 fontconfig/fc-validate/fc-validate.c
 create mode 100644 fontconfig/fc-validate/fc-validate.sgml
 create mode 100644 fontconfig/test/test-pthread.c
 delete mode 100644 mesalib/acinclude.m4
 delete mode 100644 mesalib/bin/installmesa
 delete mode 100644 mesalib/bin/minstall
 delete mode 100644 mesalib/bin/mklib
 delete mode 100644 mesalib/configs/.gitignore
 delete mode 100644 mesalib/configs/current.in
 delete mode 100644 mesalib/configs/default
 delete mode 100644 mesalib/src/.gitignore
 delete mode 100644 mesalib/src/gallium/.gitignore
 create mode 100644 mesalib/src/gallium/Automake.inc
 delete mode 100644 mesalib/src/gallium/Makefile.template
 delete mode 100644 mesalib/src/gallium/auxiliary/Makefile
 create mode 100644 mesalib/src/gallium/auxiliary/Makefile.am
 delete mode 100644 mesalib/src/glsl/Makefile.template
 create mode 100644 mesalib/src/glsl/link_varyings.cpp
 create mode 100644 mesalib/src/glsl/link_varyings.h
 delete mode 100644 mesalib/src/mapi/glapi/gen/.gitignore
 create mode 100644 mesalib/src/mapi/glapi/gen/ARB_ES3_compatibility.xml
 delete mode 100644 mesalib/src/mesa/.gitignore
 delete mode 100644 mesalib/src/mesa/drivers/.gitignore
 delete mode 100644 mesalib/src/mesa/drivers/dri/.gitignore
 delete mode 100644 mesalib/src/mesa/drivers/dri/swrast/.gitignore
 delete mode 100644 mesalib/src/mesa/state_tracker/Makefile

diff --git a/fontconfig/Makefile.am b/fontconfig/Makefile.am
index 6aee88a59..84c91acbb 100644
--- a/fontconfig/Makefile.am
+++ b/fontconfig/Makefile.am
@@ -23,7 +23,7 @@
 
 SUBDIRS=fontconfig fc-case fc-lang fc-glyphname src \
 	fc-cache fc-cat fc-list fc-match fc-pattern fc-query fc-scan \
-	conf.d test
+	fc-validate conf.d test
 if ENABLE_DOCS
 SUBDIRS += doc
 DIST_SUBDIRS = $(SUBDIRS)
diff --git a/fontconfig/README b/fontconfig/README
index 5c666b0f6..fcd3ab343 100644
--- a/fontconfig/README
+++ b/fontconfig/README
@@ -1,12 +1,113 @@
                               Fontconfig
              Font configuration and customization library
-                            Version 2.10.2
-                              2012-03-11
+                      Version 2.10.91 (2.11 RC1)
+                              2013-01-10
 
 
 Check INSTALL for compilation and installation instructions.
 Report bugs to https://bugs.freedesktop.org in the fontconfig module.
 
+2.10.91 (2.11 RC1)
+
+Akira TAGOH (19):
+      Fix a potability issue about stdint.h
+      Fix build issues on clean tree
+      Do not show the deprecation warning if it is a symlink
+      Fix a typo
+      Fix the wrong estimation for the memory usage information in fontconfig
+      Remove the duplicate null-check
+      Remove the dead code
+      clean up
+      Fix a typo that accessing to the out of array
+      Fix a memory leak
+      Check the system font to be initialized
+      Missing header file for _mkdir declaration
+      Clean up the unused variable
+      Bug 47705 - Using O_CLOEXEC
+      missing header file to declare _mkdir
+      Fix a build fail on mingw
+      Fix a typo in the manpages template
+      Bug 29312 - RFE: feature to indicate which characters are missing to satisfy the language support
+      Update the date in README properly
+
+Behdad Esfahbod (73):
+      Fix typo
+      Parse matrices of expressions
+      Fix compiler warnings
+      Fix unused-parameter warnings
+      Fix more warnings
+      Fix sign-compare warnings
+      Fix warning
+      Fix more warnings
+      Fixup from 4f6767470f52b287a2923e7e6d8de5fae1993f67
+      Remove memory accounting and reporting
+      Allow target="font/pattern/default" in <name> elements
+      Don't warn if an unknown element is used in an expression
+      Unbreak build when FC_ARCHITECTURE is defined
+      Remove unneeded stuff
+      Enable fcarch assert checks even when FC_ARCHITECTURE is explicitly given
+      Make tests run on Windows
+      Initialize matrix during name parsing
+      Adjust docs for recent changes
+      Warn if <name target="font"> appears in <match target="pattern">
+      Make FC_DBG_OBJTYPES debug messages into warnings
+      Refuse to set value to unsupported types during config too
+      Add NULL check
+      Don't crash in FcPatternDestroy with NULL pattern
+      Don't crash in FcPatternFormat() with NULL pattern
+      Minor
+      Whitespace
+      Deprecate FcName(Un)RegisterObjectTypes / FcName(Un)RegisterConstants
+      Use a static perfect hash table for object-name lookup
+      Switch .gitignore to git.mk
+      Remove shared-str pool
+      Fix build stuff
+      Add build stuff for threadsafety primitives
+      Add thread-safety primitives
+      Make refcounts, patterns, charsets, strings, and FcLang thread-safe
+      Make FcGetDefaultLang and FcGetDefaultLangs thread-safe
+      Make FcInitDebug() idempotent
+      Make FcDefaultFini() threadsafe
+      Refactor; contain default config in fccfg.c
+      Minor
+      Make default-FcConfig threadsafe
+      Minor
+      Make FcCacheIsMmapSafe() threadsafe
+      Minor
+      Make cache refcounting threadsafe
+      Add a big cache lock
+      Make random-state initialization threadsafe
+      Make cache hash threadsafe
+      Make FcDirCacheDispose() threadsafe
+      Make fcobjs.c thread-safe
+      Warn about undefined/invalid attributes during config parsing
+      Fixup fcobjs.c
+      Remove FcSharedStr*
+      Fix compiler warnings
+      Minor
+      Fix build and warnings on win32
+      Use CC_FOR_BUILD to generate source files
+      Fix more warnings.
+      Trying to fix distcheck
+      Fix build around true/false
+      Work around Sun CPP
+      Really fix cross-compiling and building of tools this time
+      Second try to make Sun CPP happy
+      Ugh, add Tools.mk
+      Minor
+      Don't use blanks for fc-query
+      Remove FcInit() calls from tools
+      Add 10-scale-bitmap-fonts.conf and enable by default
+      Oops, add the actual file
+      Fix pthreads setup
+      Fix memory corruption!
+      Add pthread test
+      Add atomic ops for Solaris
+      Make linker happy
+
+Jon TURNEY (1):
+      Fix build when srcdir != builddir
+
 2.10.2
 
 Akira TAGOH (13):
diff --git a/fontconfig/autogen.sh b/fontconfig/autogen.sh
index 93855cb2f..1482e401c 100644
--- a/fontconfig/autogen.sh
+++ b/fontconfig/autogen.sh
@@ -86,7 +86,7 @@ test $TEST_TYPE $FILE || {
 	exit 1
 }
 
-if test -z "$AUTOGEN_SUBDIR_MODE"; then
+if test -z "$AUTOGEN_SUBDIR_MODE" -a -z "$NOCONFIGURE"; then
         if test -z "$*"; then
                 echo "I am going to run ./configure with no arguments - if you wish "
                 echo "to pass any to it, please specify them on the $0 command line."
@@ -115,7 +115,7 @@ echo Running $AUTOCONF
 $AUTOCONF
 cd $ORIGDIR
 
-if test -z "$AUTOGEN_SUBDIR_MODE"; then
+if test -z "$AUTOGEN_SUBDIR_MODE" -a -z "$NOCONFIGURE"; then
 	echo Running $srcdir/configure "$@"
         $srcdir/configure "$@"
 
diff --git a/fontconfig/configure.ac b/fontconfig/configure.ac
index 803084c09..06ac8a2e7 100644
--- a/fontconfig/configure.ac
+++ b/fontconfig/configure.ac
@@ -34,7 +34,7 @@ dnl This is the package version number, not the shared library
 dnl version.  This same version number must appear in fontconfig/fontconfig.h
 dnl Yes, it is a pain to synchronize version numbers.  Unfortunately, it's
 dnl not possible to extract the version number here from fontconfig.h
-AM_INIT_AUTOMAKE(fontconfig, 2.10.2)
+AM_INIT_AUTOMAKE(fontconfig, 2.10.91)
 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 
 dnl libtool versioning
@@ -592,8 +592,26 @@ if $fc_cv_have_intel_atomic_primitives; then
 	AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1, [Have Intel __sync_* atomic primitives])
 fi
 
-AC_CHECK_HEADERS(sched.h)
-AC_CHECK_FUNCS(sched_yield)
+AC_CACHE_CHECK([for Solaris atomic operations], fc_cv_have_solaris_atomic_ops, [
+	fc_cv_have_solaris_atomic_ops=false
+	AC_TRY_LINK([
+		#include <atomic.h>
+		/* This requires Solaris Studio 12.2 or newer: */
+		#include <mbarrier.h>
+		void memory_barrier (void) { __machine_rw_barrier (); }
+		int atomic_add (volatile unsigned *i) { return atomic_add_int_nv (i, 1); }
+		void *atomic_ptr_cmpxchg (volatile void **target, void *cmp, void *newval) { return atomic_cas_ptr (target, cmp, newval); }
+		], [], fc_cv_have_solaris_atomic_ops=true
+	)
+])
+if $fc_cv_have_solaris_atomic_ops; then
+	AC_DEFINE(HAVE_SOLARIS_ATOMIC_OPS, 1, [Have Solaris __machine_*_barrier and atomic_* operations])
+fi
+
+if test "$os_win32" = no && ! $have_pthread; then
+	AC_CHECK_HEADERS(sched.h)
+	AC_SEARCH_LIBS(sched_yield,rt,AC_DEFINE(HAVE_SCHED_YIELD, 1, [Have sched_yield]))
+fi
 
 have_pthread=false
 if test "$os_win32" = no; then
@@ -677,6 +695,7 @@ fc-match/Makefile
 fc-pattern/Makefile
 fc-query/Makefile
 fc-scan/Makefile
+fc-validate/Makefile
 doc/Makefile
 doc/version.sgml
 test/Makefile
diff --git a/fontconfig/doc/fclangset.fncs b/fontconfig/doc/fclangset.fncs
index e2a40b854..c08d60c70 100644
--- a/fontconfig/doc/fclangset.fncs
+++ b/fontconfig/doc/fclangset.fncs
@@ -178,6 +178,14 @@ Returns a string set of all languages in <parameter>langset</parameter>.
 Returns a string set of all known languages.
 @@
 
+@RET@		FcChar8 *
+@FUNC@		FcLangNormalize
+@TYPE1@		const FcChar8 *			@ARG1@		lang
+@PURPOSE@	Normalize the language string
+@DESC@
+Returns a string to make <parameter>lang</parameter> suitable on fontconfig.
+@@
+
 @RET@		const FcCharSet *
 @FUNC@		FcLangGetCharSet
 @TYPE1@		const FcChar8 *			@ARG1@		lang
diff --git a/fontconfig/doc/func.sgml b/fontconfig/doc/func.sgml
index 88be32047..73e7761ce 100644
--- a/fontconfig/doc/func.sgml
+++ b/fontconfig/doc/func.sgml
@@ -46,7 +46,7 @@
 @?SYNOPSIS@
 @SYNOPSIS@
 @:@
-#include &lt;fontconfig.h&gt;
+#include &lt;fontconfig/fontconfig.h&gt;
 @;@
 	</funcsynopsisinfo>
 @{PROTOTYPE@
diff --git a/fontconfig/fc-validate/Makefile.am b/fontconfig/fc-validate/Makefile.am
new file mode 100644
index 000000000..54edec295
--- /dev/null
+++ b/fontconfig/fc-validate/Makefile.am
@@ -0,0 +1,60 @@
+#
+#  fontconfig/fc-query/Makefile.am
+#
+#  Copyright © 2003 Keith Packard
+#
+#  Permission to use, copy, modify, distribute, and sell this software and its
+#  documentation for any purpose is hereby granted without fee, provided that
+#  the above copyright notice appear in all copies and that both that
+#  copyright notice and this permission notice appear in supporting
+#  documentation, and that the name of the author(s) not be used in
+#  advertising or publicity pertaining to distribution of the software without
+#  specific, written prior permission.  The authors make no
+#  representations about the suitability of this software for any purpose.  It
+#  is provided "as is" without express or implied warranty.
+#
+#  THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+#  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+#  EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+#  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+#  DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+#  TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+#  PERFORMANCE OF THIS SOFTWARE.
+
+bin_PROGRAMS=fc-validate
+
+DOC2MAN = docbook2man
+
+FC_VALIDATE_SRC=${top_srcdir}/fc-validate
+
+SGML = ${FC_VALIDATE_SRC}/fc-validate.sgml
+
+INCLUDES=-I${top_srcdir} $(FREETYPE_CFLAGS) $(WARN_CFLAGS)
+
+BUILT_MANS=fc-validate.1
+
+if ENABLE_DOCS
+man_MANS=${BUILT_MANS}
+endif
+
+EXTRA_DIST=fc-validate.sgml $(BUILT_MANS)
+
+CLEANFILES =
+
+fc_validate_LDADD = ${top_builddir}/src/libfontconfig.la $(FREETYPE_LIBS)
+
+if USEDOCBOOK
+
+${man_MANS}: ${SGML}
+	$(AM_V_GEN) $(RM) $@; \
+	$(DOC2MAN) ${SGML}; \
+	$(RM) manpage.*
+
+all-local: $(man_MANS)
+
+CLEANFILES += $(man_MANS)
+else
+all-local:
+endif
+
+-include $(top_srcdir)/git.mk
diff --git a/fontconfig/fc-validate/fc-validate.c b/fontconfig/fc-validate/fc-validate.c
new file mode 100644
index 000000000..6ecff3671
--- /dev/null
+++ b/fontconfig/fc-validate/fc-validate.c
@@ -0,0 +1,242 @@
+/*
+ * fontconfig/fc-validate/fc-validate.c
+ *
+ * Copyright © 2003 Keith Packard
+ * Copyright © 2012 Red Hat, Inc.
+ * Red Hat Author(s): Akira TAGOH
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the author(s) not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  The authors make no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#ifdef linux
+#define HAVE_GETOPT_LONG 1
+#endif
+#define HAVE_GETOPT 1
+#endif
+
+#include <fontconfig/fontconfig.h>
+#include <fontconfig/fcfreetype.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+
+#ifndef HAVE_GETOPT
+#define HAVE_GETOPT 0
+#endif
+#ifndef HAVE_GETOPT_LONG
+#define HAVE_GETOPT_LONG 0
+#endif
+
+#if HAVE_GETOPT_LONG
+#undef  _GNU_SOURCE
+#define _GNU_SOURCE
+#include <getopt.h>
+static const struct option longopts[] = {
+    {"index", 1, 0, 'i'},
+    {"lang", 1, 0, 'l'},
+    {"verbose", 0, 0, 'v'},
+    {"version", 0, 0, 'V'},
+    {"help", 0, 0, 'h'},
+    {NULL,0,0,0},
+};
+#else
+#if HAVE_GETOPT
+extern char *optarg;
+extern int optind, opterr, optopt;
+#endif
+#endif
+
+static void
+usage (char *program, int error)
+{
+    FILE *file = error ? stderr : stdout;
+#if HAVE_GETOPT_LONG
+    fprintf (file, "usage: %s [-Vhv] [-i index] [-l LANG] [--index index] [--lang LANG] [--verbose] [--version] [--help] font-file...\n",
+	     program);
+#else
+    fprintf (file, "usage: %s [-Vhv] [-i index] [-l LANG] font-file...\n",
+	     program);
+#endif
+    fprintf (file, "Validate font files and print result\n");
+    fprintf (file, "\n");
+#if HAVE_GETOPT_LONG
+    fprintf (file, "  -i, --index INDEX    display the INDEX face of each font file only\n");
+    fprintf (file, "  -l, --lang=LANG      set LANG instead of current locale\n");
+    fprintf (file, "  -v, --verbose        show more detailed information\n");
+    fprintf (file, "  -V, --version        display font config version and exit\n");
+    fprintf (file, "  -h, --help           display this help and exit\n");
+#else
+    fprintf (file, "  -i INDEX   (index)        display the INDEX face of each font file only\n");
+    fprintf (file, "  -l LANG    (lang)         set LANG instead of current locale\n");
+    fprintf (file, "  -v         (verbose)      show more detailed information\n");
+    fprintf (file, "  -V         (version)      display font config version and exit\n");
+    fprintf (file, "  -h         (help)         display this help and exit\n");
+#endif
+    exit (error);
+}
+
+int
+main (int argc, char **argv)
+{
+    int		index_set = 0;
+    int		set_index = 0;
+    FcChar8     *lang = NULL;
+    const FcCharSet *fcs_lang = NULL;
+    int		err = 0;
+    int		i;
+    FT_Library  ftlib;
+    FcBool      verbose = FcFalse;
+#if HAVE_GETOPT_LONG || HAVE_GETOPT
+    int		c;
+
+    setlocale (LC_ALL, "");
+
+#if HAVE_GETOPT_LONG
+    while ((c = getopt_long (argc, argv, "i:l:mVhv", longopts, NULL)) != -1)
+#else
+    while ((c = getopt (argc, argv, "i:l:mVhv")) != -1)
+#endif
+    {
+	switch (c) {
+	case 'i':
+	    index_set = 1;
+	    set_index = atoi (optarg);
+	    break;
+	case 'l':
+	    lang = (FcChar8 *) FcLangNormalize ((const FcChar8 *) optarg);
+	    break;
+	case 'v':
+	    verbose = FcTrue;
+	    break;
+	case 'V':
+	    fprintf (stderr, "fontconfig version %d.%d.%d\n",
+		     FC_MAJOR, FC_MINOR, FC_REVISION);
+	    exit (0);
+	case 'h':
+	    usage (argv[0], 0);
+	default:
+	    usage (argv[0], 1);
+	}
+    }
+    i = optind;
+#else
+    i = 1;
+    verbose = FcTrue;
+#endif
+
+    if (i == argc)
+	usage (argv[0], 1);
+
+    if (!lang)
+	lang = FcLangNormalize ((const FcChar8 *) setlocale (LC_CTYPE, NULL));
+
+    if (lang)
+	fcs_lang = FcLangGetCharSet (lang);
+
+    if (FT_Init_FreeType (&ftlib))
+    {
+	fprintf (stderr, "Can't initalize FreeType library\n");
+	return 1;
+    }
+
+    for (; i < argc; i++)
+    {
+	int index;
+
+	index = set_index;
+
+	do {
+	    FT_Face face;
+	    FcCharSet *fcs, *fcs_sub;
+
+	    if (FT_New_Face (ftlib, argv[i], index, &face))
+	    {
+		if (!index_set && index > 0)
+		    break;
+		fprintf (stderr, "Unable to open %s\n", argv[i]);
+		err = 1;
+	    }
+	    else
+	    {
+		FcChar32 count;
+
+		fcs = FcFreeTypeCharSet (face, NULL);
+		fcs_sub = FcCharSetSubtract (fcs_lang, fcs);
+
+		count = FcCharSetCount (fcs_sub);
+		if (count > 0)
+		{
+		    FcChar32 ucs4, pos, map[FC_CHARSET_MAP_SIZE];
+
+		    printf ("%s:%d Missing %d glyph(s) to satisfy the coverage for %s language\n",
+			    argv[i], index, count, lang);
+
+		    if (verbose)
+		    {
+			for (ucs4 = FcCharSetFirstPage (fcs_sub, map, &pos);
+			     ucs4 != FC_CHARSET_DONE;
+			     ucs4 = FcCharSetNextPage (fcs_sub, map, &pos))
+			{
+			    int j;
+
+			    for (j = 0; j < FC_CHARSET_MAP_SIZE; j++)
+			    {
+				FcChar32 bits = map[j];
+				FcChar32 base = ucs4 + j * 32;
+				int b = 0;
+
+				while (bits)
+				{
+				    if (bits & 1)
+					printf ("  0x%04x\n", base + b);
+				    bits >>= 1;
+				    b++;
+				}
+			    }
+			}
+		    }
+		}
+		else
+		{
+		    printf ("%s:%d Satisfy the coverage for %s language\n", argv[i], index, lang);
+		}
+
+		FcCharSetDestroy (fcs);
+		FcCharSetDestroy (fcs_sub);
+
+		FT_Done_Face (face);
+	    }
+
+	    index++;
+	} while (index_set == 0);
+    }
+
+    FT_Done_FreeType (ftlib);
+
+    if (lang)
+	FcStrFree (lang);
+
+    FcFini ();
+    return err;
+}
diff --git a/fontconfig/fc-validate/fc-validate.sgml b/fontconfig/fc-validate/fc-validate.sgml
new file mode 100644
index 000000000..c677ef292
--- /dev/null
+++ b/fontconfig/fc-validate/fc-validate.sgml
@@ -0,0 +1,182 @@
+<!doctype refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [
+
+<!-- Process this file with docbook-to-man to generate an nroff manual
+     page: `docbook-to-man manpage.sgml > manpage.1'.  You may view
+     the manual page with: `docbook-to-man manpage.sgml | nroff -man |
+     less'.  A typical entry in a Makefile or Makefile.am is:
+
+manpage.1: manpage.sgml
+	docbook-to-man $< > $@
+
+
+	The docbook-to-man binary is found in the docbook-to-man package.
+	Please remember that if you create the nroff version in one of the
+	debian/rules file targets (such as build), you will need to include
+	docbook-to-man in your Build-Depends control field.
+
+  -->
+
+  <!-- Fill in your name for FIRSTNAME and SURNAME. -->
+  <!ENTITY dhfirstname "<firstname>Akira</firstname>">
+  <!ENTITY dhsurname   "<surname>TAGOH</surname>">
+  <!-- Please adjust the date whenever revising the manpage. -->
+  <!ENTITY dhdate      "<date>Sep 10, 2012</date>">
+  <!-- SECTION should be 1-8, maybe w/ subsection other parameters are
+       allowed: see man(7), man(1). -->
+  <!ENTITY dhsection   "<manvolnum>1</manvolnum>">
+  <!ENTITY dhemail     "<email>akira@tagoh.org</email>">
+  <!ENTITY dhusername  "Akira TAGOH">
+  <!ENTITY dhucpackage "<refentrytitle>fc-validate</refentrytitle>">
+  <!ENTITY dhpackage   "fc-validate">
+
+  <!ENTITY gnu         "<acronym>GNU</acronym>">
+  <!ENTITY gpl         "&gnu; <acronym>GPL</acronym>">
+]>
+
+<refentry>
+  <refentryinfo>
+    <address>
+      &dhemail;
+    </address>
+    <author>
+      &dhfirstname;
+      &dhsurname;
+    </author>
+    <copyright>
+      <year>2012</year>
+      <holder>&dhusername;</holder>
+    </copyright>
+    &dhdate;
+  </refentryinfo>
+  <refmeta>
+    &dhucpackage;
+
+    &dhsection;
+  </refmeta>
+  <refnamediv>
+    <refname>&dhpackage;</refname>
+
+    <refpurpose>validate font files</refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <cmdsynopsis>
+      <command>&dhpackage;</command>
+
+      <arg><option>-Vhv</option></arg>
+      <sbr>
+      <group>
+        <arg><option>-i</option> <option><replaceable>index</replaceable></option></arg>
+        <arg><option>--index</option> <option><replaceable>index</replaceable></option></arg>
+      </group>
+      <group>
+	<arg><option>-l</option> <option><replaceable>lang</replaceable></option></arg>
+	<arg><option>--lang</option> <option><replaceable>lang</replaceable></option></arg>
+      </group>
+      <arg><option>--verbose</option></arg>
+      <arg><option>--version</option></arg>
+      <arg><option>--help</option></arg>
+      <arg choice="req" rep="repeat"><option><replaceable>font-file</replaceable></option></arg>
+
+     </cmdsynopsis>
+  </refsynopsisdiv>
+  <refsect1>
+    <title>DESCRIPTION</title>
+
+    <para><command>&dhpackage;</command> validates
+    <replaceable>font-file</replaceable>(s) if each fonts satisfies
+    the language coverage according to the orthography files in fontconfig.
+    If <option>--index</option> is given, only one face of each file is
+    validated, otherwise all faces are validated.</para>
+
+  </refsect1>
+  <refsect1>
+    <title>OPTIONS</title>
+
+    <para>This program follows the usual &gnu; command line syntax,
+      with long options starting with two dashes (`-').  A summary of
+      options is included below.</para>
+
+    <variablelist>
+      <varlistentry>
+        <term><option>-i</option>
+          <option>--index</option>
+	  <option><replaceable>index</replaceable></option>
+        </term>
+        <listitem>
+          <para>Only query face indexed <replaceable>index</replaceable> of
+	  each file.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><option>-l</option>
+	  <option>--lang</option>
+	  <option><replaceable>lang</replaceable></option>
+	</term>
+	<listitem>
+	  <para>Set <replaceable>lang</replaceable> as a language instead of current locale. this is used for <option>-m</option>.</para>
+	</listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><option>-v</option>
+	  <option>--verbose</option>
+	</term>
+	<listitem>
+	  <para>Show more detailed information.</para>
+	</listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-V</option>
+          <option>--version</option>
+        </term>
+        <listitem>
+          <para>Show version of the program and exit.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-h</option>
+          <option>--help</option>
+        </term>
+        <listitem>
+          <para>Show summary of options.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option><replaceable>font-file</replaceable></option>
+        </term>
+        <listitem>
+          <para>Query <replaceable>font-file</replaceable> for font faces.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
+  <refsect1>
+    <title>RETURN CODES</title>
+    <para><command>fc-validate</command> returns error code 0 for successful parsing,
+    or 1 if any errors occured or if at least one font face could not be opened.</para>
+  </refsect1>
+
+  <refsect1>
+    <title>AUTHOR</title>
+
+    <para>This manual page was updated by &dhusername; &dhemail;.</para>
+
+  </refsect1>
+</refentry>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:t
+sgml-shorttag:t
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:2
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-default-dtd-file:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+-->
diff --git a/fontconfig/fontconfig/fontconfig.h b/fontconfig/fontconfig/fontconfig.h
index 1af63abfb..52e9438fe 100644
--- a/fontconfig/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig/fontconfig.h
@@ -52,7 +52,7 @@ typedef int		FcBool;
 
 #define FC_MAJOR	2
 #define FC_MINOR	10
-#define FC_REVISION	2
+#define FC_REVISION	91
 
 #define FC_VERSION	((FC_MAJOR * 10000) + (FC_MINOR * 100) + (FC_REVISION))
 
@@ -580,6 +580,9 @@ FcInitBringUptoDate (void);
 FcPublic FcStrSet *
 FcGetLangs (void);
 
+FcPublic FcChar8 *
+FcLangNormalize (const FcChar8 *lang);
+
 FcPublic const FcCharSet *
 FcLangGetCharSet (const FcChar8 *lang);
 
diff --git a/fontconfig/new-version.sh b/fontconfig/new-version.sh
index 3c620ae4c..39514302e 100644
--- a/fontconfig/new-version.sh
+++ b/fontconfig/new-version.sh
@@ -71,8 +71,8 @@ if [ $version != $last ]; then
 	# header
 	#
 	(sed '/^2\.[0-9.]*/,$d' README | 
-		sed -e "s/Version.*/Version $version_note/" \
-		    -e "s/200.*/$date/" | awk '
+		sed -r -e "s/Version.*/Version $version_note/" \
+		    -e "s/[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/$date/" | awk '
 		    /^[ \t]/ {
 				gsub ("^[ \t]*", "");
 				gsub ("[ \t]*$", "");
diff --git a/fontconfig/src/fcatomic.h b/fontconfig/src/fcatomic.h
index 72ae37280..a76431139 100644
--- a/fontconfig/src/fcatomic.h
+++ b/fontconfig/src/fcatomic.h
@@ -87,6 +87,18 @@ typedef int fc_atomic_int_t;
 #define fc_atomic_ptr_cmpexch(P,O,N)	__sync_bool_compare_and_swap ((P), (O), (N))
 
 
+#elif !defined(FC_NO_MT) && defined(HAVE_SOLARIS_ATOMIC_OPS)
+
+#include <atomic.h>
+#include <mbarrier.h>
+
+typedef unsigned int fc_atomic_int_t;
+#define fc_atomic_int_add(AI, V)	( ({__machine_rw_barrier ();}), atomic_add_int_nv (&(AI), (V)) - (V))
+
+#define fc_atomic_ptr_get(P)		( ({__machine_rw_barrier ();}), (void *) *(P))
+#define fc_atomic_ptr_cmpexch(P,O,N)	( ({__machine_rw_barrier ();}), atomic_cas_ptr ((P), (O), (N)) == (void *) (O) ? FcTrue : FcFalse)
+
+
 #elif !defined(FC_NO_MT)
 
 #define FC_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */
diff --git a/fontconfig/src/fcint.h b/fontconfig/src/fcint.h
index 3883bc96e..512926797 100644
--- a/fontconfig/src/fcint.h
+++ b/fontconfig/src/fcint.h
@@ -817,9 +817,6 @@ FcPrivate FcLangSet *
 FcFreeTypeLangSet (const FcCharSet  *charset,
 		   const FcChar8    *exclusiveLang);
 
-FcPrivate FcChar8 *
-FcLangNormalize (const FcChar8 *lang);
-
 FcPrivate FcLangResult
 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
 
diff --git a/fontconfig/src/fcstr.c b/fontconfig/src/fcstr.c
index cdab38397..414d6dd6b 100644
--- a/fontconfig/src/fcstr.c
+++ b/fontconfig/src/fcstr.c
@@ -1217,6 +1217,17 @@ FcStrSetDel (FcStrSet *set, const FcChar8 *s)
     return FcFalse;
 }
 
+/* TODO Make public */
+static FcStrSet *
+FcStrSetReference (FcStrSet *set)
+{
+    if (FcRefIsConst (&set->ref))
+	return set;
+
+    FcRefInc (&set->ref);
+    return set;
+}
+
 void
 FcStrSetDestroy (FcStrSet *set)
 {
@@ -1245,7 +1256,7 @@ FcStrListCreate (FcStrSet *set)
     if (!list)
 	return 0;
     list->set = set;
-    FcRefInc (&set->ref);
+    FcStrSetReference (set);
     list->n = 0;
     return list;
 }
diff --git a/fontconfig/test/Makefile.am b/fontconfig/test/Makefile.am
index 3fd343a24..664138a5b 100644
--- a/fontconfig/test/Makefile.am
+++ b/fontconfig/test/Makefile.am
@@ -4,6 +4,17 @@ TESTS=run-test.sh
 
 TESTDATA=4x6.pcf 8x16.pcf out.expected fonts.conf.in
 
+AM_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir)
+
+if HAVE_PTHREAD
+check_PROGRAMS = test-pthread
+noinst_PROGRAMS = $(check_PROGRAMS)
+test_pthread_LDADD = $(top_builddir)/src/libfontconfig.la
+# We don't enable this test by default because it will require config and fonts
+# to meaningfully test anything, and we are not installed yet.
+#TESTS += test-pthread
+endif
+
 EXTRA_DIST=$(check_SCRIPTS) $(TESTDATA)
 
 CLEANFILES=
diff --git a/fontconfig/test/test-pthread.c b/fontconfig/test/test-pthread.c
new file mode 100644
index 000000000..7701a24f7
--- /dev/null
+++ b/fontconfig/test/test-pthread.c
@@ -0,0 +1,79 @@
+/* Code originally from Raimund Steger. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <fontconfig/fontconfig.h>
+
+#define NTHR 100
+#define NTEST 100
+
+struct thr_arg_s
+{
+	int thr_num;
+};
+
+static void test_match(int thr_num,int test_num)
+{
+	FcPattern *pat;
+	FcPattern *match;
+	FcResult  result;
+
+	FcInit();
+
+	pat = FcNameParse((const FcChar8 *)"New Century Schoolbook");
+		
+	FcConfigSubstitute(0,pat,FcMatchPattern);
+	FcDefaultSubstitute(pat);
+	
+	match = FcFontMatch(0,pat,&result);
+		
+	FcPatternDestroy(pat);
+	FcPatternDestroy(match);
+}
+
+static void *run_test_in_thread(void *arg)
+{
+	struct thr_arg_s *thr_arg=(struct thr_arg_s *)arg;
+	int thread_num = thr_arg->thr_num;
+	int i=0;
+
+	for(;i<NTEST;i++) test_match(thread_num,i);
+
+	printf("Thread %d: done\n",thread_num);
+
+	return NULL;
+}
+
+int main(int argc,char **argv)
+{
+	pthread_t threads[NTHR];
+	int i, j;
+
+	printf("Creating %d threads\n",NTHR);
+
+	for(i = 0;i<NTHR;i++)
+	{
+		struct thr_arg_s thr_arg;
+		int result;
+		thr_arg.thr_num=i;
+		result = pthread_create(&threads[i],NULL,run_test_in_thread,
+					(void *)&thr_arg);
+		if(result!=0)
+		{
+			fprintf(stderr,"Cannot create thread %d\n",i);
+			break;
+		}
+	}
+
+	for(j=0;j<i;j++)
+	{
+		pthread_join(threads[j],NULL);
+		printf("Joined thread %d\n",j);
+	}
+
+	FcFini();
+
+	return 0;
+}
diff --git a/libX11/configure.ac b/libX11/configure.ac
index fe3179948..c29209420 100644
--- a/libX11/configure.ac
+++ b/libX11/configure.ac
@@ -177,7 +177,7 @@ else
 	AC_DEFINE(HAVE_DLOPEN,1,[Use dlopen to load shared libraries])
 	AC_CHECK_HEADERS([dlfcn.h])
 fi
-if test x$ac_cv_header_dlcfn_h -o x$ac_cv_header_dl_h; then
+if test "x$ac_cv_header_dlfcn_h" = xyes -o "x$ac_cv_header_dl_h" = xyes; then
 	HAVE_LOADABLE_MODULES=yes
 else
 	HAVE_LOADABLE_MODULES=no
diff --git a/mesalib/.gitignore b/mesalib/.gitignore
index 8f39b5334..faf2ca383 100644
--- a/mesalib/.gitignore
+++ b/mesalib/.gitignore
@@ -4,6 +4,7 @@
 *.ilk
 *.la
 *.lo
+*.log
 *.o
 *.obj
 *.os
@@ -17,6 +18,7 @@
 *.tar
 *.tar.bz2
 *.tar.gz
+*.trs
 *.zip
 *~
 depend
@@ -36,9 +38,9 @@ config.py
 build
 libtool
 manifest.txt
-Makefile.in
 .dir-locals.el
 .deps/
 .dirstamp
 .libs/
-/Makefile
+Makefile
+Makefile.in
diff --git a/mesalib/Makefile.am b/mesalib/Makefile.am
index 1f4fcac3a..ee733339a 100644
--- a/mesalib/Makefile.am
+++ b/mesalib/Makefile.am
@@ -33,23 +33,6 @@ check-local:
 	$(MAKE) -C src/glsl/tests check
 	$(MAKE) -C src/glx/tests check
 
-clean-local:
-	-@touch $(top_builddir)/configs/current
-	-@for dir in $(SUBDIRS) ; do \
-		if [ -d $$dir ] ; then \
-			(cd $$dir && $(MAKE) clean) ; \
-		fi \
-	done
-	-@test -s $(top_builddir)/configs/current || rm -f $(top_builddir)/configs/current
-
-
-
-distclean-local:
-	-rm -rf lib*
-	-rm -f $(top_builddir)/configs/current
-	-find . '(' -name '*.o' -o -name '*.a' -o -name '*.so' -o \
-	  -name depend -o -name depend.bak ')' -exec rm -f '{}' ';'
-
 .PHONY: doxygen
 
 # Rules for making release tarballs
@@ -93,7 +76,6 @@ IGNORE_FILES = \
 
 
 parsers: configure
-	-@touch $(top_builddir)/configs/current
 	$(MAKE) -C src/glsl glsl_parser.cc glsl_parser.h glsl_lexer.cc
 	$(MAKE) -C src/glsl/glcpp glcpp-lex.c glcpp-parse.c glcpp-parse.h
 	$(MAKE) -C src/mesa/program lex.yy.c program_parse.tab.c program_parse.tab.h
diff --git a/mesalib/acinclude.m4 b/mesalib/acinclude.m4
deleted file mode 100644
index aba48a362..000000000
--- a/mesalib/acinclude.m4
+++ /dev/null
@@ -1,119 +0,0 @@
-# A few convenience macros for Mesa, mostly to keep all the platform
-# specifics out of configure.ac.
-
-# MESA_PIC_FLAGS()
-#
-# Find out whether to build PIC code using the option --enable-pic and
-# the configure enable_static/enable_shared settings. If PIC is needed,
-# figure out the necessary flags for the platform and compiler.
-#
-# The platform checks have been shamelessly taken from libtool and
-# stripped down to just what's needed for Mesa. See _LT_COMPILER_PIC in
-# /usr/share/aclocal/libtool.m4 or
-# http://git.savannah.gnu.org/gitweb/?p=libtool.git;a=blob;f=libltdl/m4/libtool.m4;hb=HEAD
-#
-AC_DEFUN([MESA_PIC_FLAGS],
-[AC_REQUIRE([AC_PROG_CC])dnl
-AC_ARG_VAR([PIC_FLAGS], [compiler flags for PIC code])
-AC_ARG_ENABLE([pic],
-    [AS_HELP_STRING([--disable-pic],
-        [don't compile PIC objects @<:@default=enabled for shared builds
-        on supported platforms@:>@])],
-    [enable_pic="$enableval"
-    test "x$enable_pic" = x && enable_pic=auto],
-    [enable_pic=auto])
-# disable PIC by default for static builds
-if test "$enable_pic" = auto && test "$enable_static" = yes; then
-    enable_pic=no
-fi
-# if PIC hasn't been explicitly disabled, try to figure out the flags
-if test "$enable_pic" != no; then
-    AC_MSG_CHECKING([for $CC option to produce PIC])
-    # allow the user's flags to override
-    if test "x$PIC_FLAGS" = x; then
-        # see if we're using GCC
-        if test "x$GCC" = xyes; then
-            case "$host_os" in
-            aix*|beos*|cygwin*|irix5*|irix6*|osf3*|osf4*|osf5*)
-                # PIC is the default for these OSes.
-                ;;
-            mingw*|os2*|pw32*)
-                # This hack is so that the source file can tell whether
-                # it is being built for inclusion in a dll (and should
-                # export symbols for example).
-                PIC_FLAGS="-DDLL_EXPORT"
-                ;;
-            darwin*|rhapsody*)
-                # PIC is the default on this platform
-                # Common symbols not allowed in MH_DYLIB files
-                PIC_FLAGS="-fno-common"
-                ;;
-            hpux*)
-                # PIC is the default for IA64 HP-UX and 64-bit HP-UX,
-                # but not for PA HP-UX.
-                case $host_cpu in
-                hppa*64*|ia64*)
-                    ;;
-                *)
-                    PIC_FLAGS="-fPIC"
-                    ;;
-                esac
-                ;;
-            *)
-                # Everyone else on GCC uses -fPIC
-                PIC_FLAGS="-fPIC"
-                ;;
-            esac
-        else # !GCC
-            case "$host_os" in
-            hpux9*|hpux10*|hpux11*)
-                # PIC is the default for IA64 HP-UX and 64-bit HP-UX,
-                # but not for PA HP-UX.
-                case "$host_cpu" in
-                hppa*64*|ia64*)
-                    # +Z the default
-                    ;;
-                *)
-                    PIC_FLAGS="+Z"
-                    ;;
-                esac
-                ;;
-            linux*|k*bsd*-gnu)
-                case `basename "$CC"` in
-                icc*|ecc*|ifort*)
-                    PIC_FLAGS="-KPIC"
-                    ;;
-                pgcc*|pgf77*|pgf90*|pgf95*)
-                    # Portland Group compilers (*not* the Pentium gcc
-                    # compiler, which looks to be a dead project)
-                    PIC_FLAGS="-fpic"
-                    ;;
-                ccc*)
-                    # All Alpha code is PIC.
-                    ;;
-                xl*)
-                    # IBM XL C 8.0/Fortran 10.1 on PPC
-                    PIC_FLAGS="-qpic"
-                    ;;
-                *)
-                    case `$CC -V 2>&1 | sed 5q` in
-                    *Sun\ C*|*Sun\ F*)
-                        # Sun C 5.9 or Sun Fortran
-                        PIC_FLAGS="-KPIC"
-                        ;;
-                    esac
-                esac
-                ;;
-            solaris*)
-                PIC_FLAGS="-KPIC"
-                ;;
-            sunos4*)
-                PIC_FLAGS="-PIC"
-                ;;
-            esac
-        fi # GCC
-    fi # PIC_FLAGS
-    AC_MSG_RESULT([$PIC_FLAGS])
-fi
-AC_SUBST([PIC_FLAGS])
-])# MESA_PIC_FLAGS
diff --git a/mesalib/bin/installmesa b/mesalib/bin/installmesa
deleted file mode 100644
index 1e24c05ca..000000000
--- a/mesalib/bin/installmesa
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/bin/sh
-
-#
-# Simple shell script for installing Mesa's header and library files.
-# If the copy commands below don't work on a particular system (i.e. the
-# -f or -d flags), we may need to branch on `uname` to do the right thing.
-#
-
-
-TOP=.
-
-INCLUDE_DIR="/usr/local/include"
-LIB_DIR="/usr/local/lib"
-
-if [ "x$#" = "x0" ] ; then
-echo
-echo "***** Mesa installation - You may need root privileges to do this *****"
-echo
-echo "Default directory for header files is:" ${INCLUDE_DIR}
-echo "Enter new directory or press <Enter> to accept this default."
-
-read INPUT
-if [ "x${INPUT}" != "x" ] ; then
-	INCLUDE_DIR=${INPUT}
-fi
-
-echo
-echo "Default directory for library files is:" ${LIB_DIR}
-echo "Enter new directory or press <Enter> to accept this default."
-
-read INPUT
-if [ "x${INPUT}" != "x" ] ; then
-	LIB_DIR=${INPUT}
-fi
-
-echo
-echo "About to install Mesa header files (GL/*.h) in: " ${INCLUDE_DIR}/GL
-echo "and Mesa library files (libGL.*, etc) in: " ${LIB_DIR}
-echo "Press <Enter> to continue, or <ctrl>-C to abort."
-
-read INPUT
-
-else
-INCLUDE_DIR=$1/include
-LIB_DIR=$1/lib
-fi
-
-# flags:
-#  -f = force
-#  -d = preserve symlinks (does not work on BSD)
-
-if [ `uname` = "FreeBSD" ] ; then
-	CP_FLAGS="-f"
-elif [ `uname` = "Darwin" ] ; then
-	CP_FLAGS="-f"
-elif [ `uname` = "AIX" ] ; then
-	CP_FLAGS="-fh"
-else
-	CP_FLAGS="-fd"
-fi
-
-
-set -v
-
-mkdir -p ${INCLUDE_DIR}
-mkdir -p ${INCLUDE_DIR}/GL
-# NOT YET: mkdir -p ${INCLUDE_DIR}/GLES
-mkdir -p ${LIB_DIR}
-cp -f ${TOP}/include/GL/*.h ${INCLUDE_DIR}/GL
-cp -f ${TOP}/src/glw/*.h ${INCLUDE_DIR}/GL
-# NOT YET: cp -f ${TOP}/include/GLES/*.h ${INCLUDE_DIR}/GLES
-cp ${CP_FLAGS} ${TOP}/lib*/lib* ${LIB_DIR}
-
-echo "Done."
diff --git a/mesalib/bin/minstall b/mesalib/bin/minstall
deleted file mode 100644
index 094ec0c2b..000000000
--- a/mesalib/bin/minstall
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/bin/sh
-
-
-# A minimal replacement for 'install' that supports installing symbolic links.
-# Only a limited number of options are supported:
-# -d dir          Create a directory
-# -m mode         Sets a file's mode when installing
-
-
-# If these commands aren't portable, we'll need some "if (arch)" type stuff
-SYMLINK="ln -s"
-MKDIR="mkdir -p"
-RM="rm -f"
-
-MODE=""
-
-if [ "$1" = "-d" ] ; then
-	# make a directory path
-	$MKDIR "$2"
-	exit 0
-fi
-
-if [ "$1" = "-m" ] ; then
-	# set file mode
-	MODE=$2
-	shift 2
-fi
-
-# install file(s) into destination
-if [ $# -ge 2 ] ; then
-
-	# Last cmd line arg is the dest dir
-	for FILE in $@ ; do
-		DESTDIR="$FILE"
-	done
-
-	# Loop over args, moving them to DEST directory
-	I=1
-	for FILE in $@ ; do
-		if [ $I = $# ] ; then
-			# stop, don't want to install $DEST into $DEST
-			exit 0
-		fi
-
-                DEST=$DESTDIR
-
-                # On CYGWIN, because DLLs are loaded by the native Win32 loader,
-                # they are installed in the executable path.  Stub libraries used
-                # only for linking are installed in the library path
-                case `uname` in
-                    CYGWIN*)
-                        case $FILE in
-                            *.dll)
-                                DEST="$DEST/../bin"
-                                ;;
-                            *)
-                                ;;
-                        esac
-	                ;;
-                    *)
-                        ;;
-                esac
-
-		PWDSAVE=`pwd`
-
-		# determine file's type
-		if [ -h "$FILE" ] ; then
-			#echo $FILE is a symlink
-			# Unfortunately, cp -d isn't universal so we have to
-			# use a work-around.
-
-			# Use ls -l to find the target that the link points to
-			LL=`ls -l "$FILE"`
-			for L in $LL ; do
-				TARGET=$L
-			done
-			#echo $FILE is a symlink pointing to $TARGET
-
-			FILE=`basename "$FILE"`
-			# Go to $DEST and make the link
-			cd "$DEST"        # pushd
-				$RM "$FILE"
-				$SYMLINK "$TARGET" "$FILE"
-			cd "$PWDSAVE"     # popd
-
-		elif [ -f "$FILE" ] ; then
-			#echo "$FILE" is a regular file
-			# Only copy if the files differ
-			if ! cmp -s $FILE $DEST/`basename $FILE`; then
-				$RM "$DEST/`basename $FILE`"
-				cp "$FILE" "$DEST"
-			fi
-			if [ $MODE ] ; then
-				FILE=`basename "$FILE"`
-				chmod $MODE "$DEST/$FILE"
-			fi
-		else
-			echo "Unknown type of argument: " "$FILE"
-			exit 1
-		fi
-
-		I=`expr $I + 1`
-	done
-
-	exit 0
-fi
-
-# If we get here, we didn't find anything to do
-echo "Usage:"
-echo "  install -d dir                      Create named directory"
-echo "  install [-m mode] file [...] dest   Install files in destination"
-
diff --git a/mesalib/bin/mklib b/mesalib/bin/mklib
deleted file mode 100644
index 086b26898..000000000
--- a/mesalib/bin/mklib
+++ /dev/null
@@ -1,1043 +0,0 @@
-#!/bin/sh
-
-# Make a shared library.
-# This script should be useful for projects other than Mesa.
-# Improvements/fixes are welcome.
-
-
-# Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the "Software"),
-# to deal in the Software without restriction, including without limitation
-# the rights to use, copy, modify, merge, publish, distribute, sublicense,
-# and/or sell copies of the Software, and to permit persons to whom the
-# Software is furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included
-# in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-
-# Clear CDPATH as the 'cd' command will echo stuff
-# to stdout if it is set
-unset CDPATH
-
-# Given a list of files, look for .a archives and unpack them.
-# Return the original list of files minus the .a files plus the unpacked files.
-# first param:  name of a temp directory (to be deleted when finished)
-# remaining params:  list of .o and .a files
-expand_archives() {
-    DIR=$1
-    shift
-    FILES=$@
-    NEWFILES=""
-    ORIG_DIR=`pwd`
-    mkdir -p "$DIR"
-    cd "$DIR"
-    for FILE in $FILES ; do
-        case $FILE in
-            *.a)
-                # extract the .o files from this .a archive
-                case $FILE in
-                    /*) ;;
-                    *)  FILE="$ORIG_DIR/$FILE" ;;
-                esac
-                MEMBERS=`ar t $FILE`
-                ar x $FILE
-                for MEMBER in $MEMBERS ; do
-                    NEWFILES="$NEWFILES $DIR/$MEMBER"
-                done
-                ;;
-            *)
-                # other file type, just add to list
-                NEWFILES="$NEWFILES $FILE"
-                ;;
-        esac
-    done
-    cd "$ORIG_DIR"
-    echo $NEWFILES
-}
-
-
-# Make static library with 'ar'
-# params:
-#    options to ar
-#    1 or 0 to indicate if ranlib should be run
-#    libname to make
-#    list of object files
-# Return name of library we made
-# Example: "make_ar_static_lib -ru 1 libfoo.a foo.o bar.o"
-make_ar_static_lib() {
-    OPTS=$1
-    shift;
-    RANLIB=$1
-    shift;
-    LIBNAME=$1
-    shift;
-    OBJECTS=$@
-
-    # remove existing lib, if present
-    rm -f ${LIBNAME}
-
-    # make static lib
-    ar ${OPTS} ${LIBNAME} ${OBJECTS}
-
-    # run ranlib
-    if [ ${RANLIB} = 1 ] ; then
-        ranlib ${LIBNAME}
-    fi
-
-    echo ${LIBNAME}
-}
-
-
-# Print usage info.
-usage() {
-    echo 'Usage: mklib [options] objects'
-    echo 'Create a shared library from object files.'
-    echo '  -o LIBRARY    specifies the name of the resulting library, without'
-    echo '                the leading "lib" or any suffix.'
-    echo '                (eg: "-o GL" might result in "libGL.so" being made)'
-    echo '  -major N      specifies major version number (default is 1)'
-    echo '  -minor N      specifies minor version number (default is 0)'
-    echo '  -patch N      specifies patch version number (default is 0)'
-    echo '  -lLIBRARY     specifies a dependency on LIBRARY'
-    echo '  -LDIR         search in DIR for library dependencies at build time'
-    echo '  -RDIR         search in DIR for library dependencies at run time'
-    echo '  -linker L     explicity specify the linker program to use (eg: gcc, g++)'
-    echo '                Not observed on all systems at this time.'
-    echo '  -ldflags OPT  specify any additional linker flags in OPT'
-    echo '  -cplusplus    link with C++ runtime'
-    echo '  -static       make a static library (default is dynamic/shared)'
-    echo '  -dlopen       make a shared library suitable for dynamic loading'
-    echo '  -install DIR  put resulting library file(s) in DIR'
-    echo '  -arch ARCH    override using `uname` to determine host system'
-    echo '  -archopt OPT  specify an extra achitecture-specific option OPT'
-    echo '  -altopts OPTS alternate options to override all others'
-    echo "  -noprefix     don't prefix library name with 'lib' nor add any suffix"
-    echo '  -exports FILE only export the symbols listed in FILE'
-    echo '  -id NAME      Sets the id of the dylib (Darwin)'
-    echo '  -h, --help    display this information and exit'
-}
-
-
-#
-# Option defaults
-#
-LIBNAME=""
-MAJOR=1
-MINOR=0
-PATCH=""
-DEPS=""
-LINK=""
-LDFLAGS=""
-CPLUSPLUS=0
-STATIC=0
-DLOPEN=0
-INSTALLDIR="."
-ARCH="auto"
-ARCHOPT=""
-NOPREFIX=0
-EXPORTS=""
-ID=""
-
-#
-# Parse arguments
-#
-while true
-do
-    case $1 in
-	'-h' | '--help')
-	    usage
-	    exit 1
-	    ;;
-	'-o')
-	    shift 1;
-	    LIBNAME=$1
-	    ;;
-	'-major')
-	    shift 1;
-	    MAJOR=$1
-	    ;;
-	'-minor')
-	    shift 1;
-	    MINOR=$1
-	    ;;
-	'-patch')
-	    shift 1;
-	    PATCH=$1
-	    ;;
-	'-linker')
-	    shift 1;
-	    LINK=$1
-	    ;;
-	'-ldflags')
-	    shift 1;
-	    LDFLAGS=$1
-	    ;;
-	-l*)
-	    DEPS="$DEPS $1"
-	    ;;
-	-L*)
-	    DEPS="$DEPS $1"
-	    ;;
-	-R*)
-	    DEPS="$DEPS $1"
-	    ;;
-	-Wl*)
-            DEPS="$DEPS $1"
-            ;;
-	-pthread)
-	    # this is a special case (see bugzilla 10876)
-	    DEPS="$DEPS $1"
-	    ;;
-	'-pthread')
-	    DEPS="$DEPS -pthread"
-	    ;;
-	'-cplusplus')
-	    CPLUSPLUS=1
-	    ;;
-	'-static')
-	    STATIC=1
-	    ;;
-	'-dlopen')
-	    DLOPEN=1
-	    ;;
-	'-install')
-	    shift 1;
-	    INSTALLDIR=$1
-	    ;;
-	'-arch')
-	    shift 1;
-	    ARCH=$1
-	    ;;
-	'-archopt')
-	    shift 1;
-	    ARCHOPT=$1
-	    ;;
-	'-altopts')
-            shift 1;
-            ALTOPTS=$1
-            ;;
-	'-noprefix')
-	    NOPREFIX=1
-	    ;;
-	'-exports')
-	    shift 1;
-	    EXPORTS=$1
-	    ;;
-	'-id')
-	    shift 1;
-	    ID=$1
-	    ;;
-	-*)
-	    echo "mklib: Unknown option: " $1 ;
-	    exit 1
-	    ;;
-	*)
-	    # This should be the first object file, stop parsing
-	    break
-    esac
-    shift 1
-done
-OBJECTS=$@
-
-
-if [ ${ARCH} = "auto" ] ; then
-    ARCH=`uname`
-fi
-
-
-if [ $STATIC = 1 ]; then
-    # filter out linker options inside object list
-    NEWOBJECTS=""
-    for OBJ in $OBJECTS ; do
-	case $OBJ in
-	    -Wl,*|-L*|-l*)
-		echo "mklib: warning: ignoring $OBJ for static library"
-		;;
-	    *)
-		NEWOBJECTS="$NEWOBJECTS $OBJ"
-		;;
-	esac
-    done
-    OBJECTS=$NEWOBJECTS
-fi
-
-
-#
-# Error checking
-#
-if [ "x${LIBNAME}" = "x" ] ; then
-    echo "mklib: Error: no library name specified (-h for help)"
-    exit 1
-fi
-if [ "x${OBJECTS}" = "x" ] ; then
-    echo "mklib: Error: no object files specified (-h for help)"
-    exit 1
-fi
-
-
-#
-# Debugging info
-#
-if [  ]  ; then
-    echo "-----------------"
-    echo ARCH is $ARCH
-    echo LIBNAME is $LIBNAME
-    echo MAJOR is $MAJOR
-    echo MINOR is $MINOR
-    echo PATCH is $PATCH
-    echo DEPS are $DEPS
-    echo "EXPORTS in" $EXPORTS
-    echo ID is $ID
-    echo "-----------------"
-fi
-
-
-#
-# OK, make the library now
-#
-case $ARCH in
-
-    'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/* | 'NetBSD')
-	# we assume gcc
-
-	if [ "x$LINK" = "x" ] ; then
-	    # -linker was not specified so set default link command now
-            if [ $CPLUSPLUS = 1 ] ; then
-                LINK=g++
-            else
-                LINK=gcc
-            fi
-	fi
-
-	# Check if objects are 32-bit and we're running in 64-bit
-	# environment.  If so, pass -m32 flag to linker.
-	add_abi_flag_to_opts() {
-	    case $(file $1) in
-		*32-bit*x86-64*)
-		    # x86_64 x32 ABI.
-		    OPTS="-mx32 ${OPTS}"
-		    ;;
-		*64-bit*x86-64*)
-		    # x86_64 64-bit ABI.
-		    OPTS="-m64 ${OPTS}"
-		    ;;
-		*32-bit*Intel*)
-		    # x86 32-bit ABI.
-		    OPTS="-m32 ${OPTS}"
-		    ;;
-	    esac
-	}
-
-	if [ $NOPREFIX = 1 ] ; then
-	    # No "lib" or ".so" part
-	    echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
-	    case $ARCH in 'Linux' | 'GNU' | GNU/*)
-		OPTS="-Xlinker -Bsymbolic -shared"
-	    ;;
-	    *)
-		OPTS="-shared"
-	    ;;
-	    esac
-
-	    # Check to see if we are building for a different ABI.
-	    add_abi_flag_to_opts ${OBJECTS}
-
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-
-            rm -f ${LIBNAME}
-            # make lib
-            ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
-            # finish up
-            FINAL_LIBS="${LIBNAME}"
-        elif [ $STATIC = 1 ] ; then
-	    # make a static .a library
-            LIBNAME="lib${LIBNAME}.a"     # prefix with "lib", suffix with ".a"
-            echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
-            OPTS="-ru"
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-
-	    # expand .a into .o files
-	    NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
-
-            # make static lib
-	    FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
-
-	    # remove temporary extracted .o files
-	    rm -rf ${LIBNAME}.obj
-        else
-	    # make dynamic library
-	    LIBNAME="lib${LIBNAME}"     # prefix with "lib"
-	    case $ARCH in 'Linux' | 'GNU' | GNU/*)
-		OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
-	    ;;
-	    *)
-		OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
-	    ;;
-	    esac
-	    if [ $EXPORTS ] ; then
-		#OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
-		# Make the 'exptmp' file for --version-script option
-		echo "{" > exptmp
-		echo "global:" >> exptmp
-		sed 's/$/;/' ${EXPORTS} >> exptmp
-		echo "local:" >> exptmp
-		echo "*;" >> exptmp
-		echo "};" >> exptmp
-		OPTS="${OPTS} -Xlinker --version-script=exptmp"
-		# exptmp is removed below
-	    fi
-
-	    # Check to see if we are building for a different ABI.
-	    add_abi_flag_to_opts ${OBJECTS}
-
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-
-	    if [ x${PATCH} = "x" ] ; then
-		VERSION="${MAJOR}.${MINOR}"
-	    else
-		VERSION="${MAJOR}.${MINOR}.${PATCH}"
-	    fi
-
-            echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
-
-            # rm any old libs
-            rm -f ${LIBNAME}.so.${VERSION}
-            rm -f ${LIBNAME}.so.${MAJOR}
-            rm -f ${LIBNAME}.so
-
-            # make lib
-            ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
-            # make usual symlinks
-            ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
-            ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
-            # finish up
-            FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
-#	    rm -f exptmp
-        fi
-	;;
-
-    'SunOS')
-        if [ $STATIC = 1 ] ; then
-	    LIBNAME="lib${LIBNAME}.a"
-	    echo "mklib: Making SunOS static library: " ${LIBNAME}
-	    FINAL_LIBS=`make_ar_static_lib -ruc 0 ${LIBNAME} ${OBJECTS}`
-	else
-	    if [ $NOPREFIX = 0 ] ; then
-		LIBNAME="lib${LIBNAME}.so"
-	    fi
-	    echo "mklib: Making SunOS shared library: " ${LIBNAME}
-
-	    if [ "x$LINK" = "x" ] ; then
-		# -linker was not specified, choose default linker now
-		if [ $CPLUSPLUS = 1 ] ; then
-		    # determine linker and options for C++ code
-		    if [ `which c++` ] ; then
-			# use Sun c++
-			LINK="c++"
-		    elif [ `type g++` ] ; then
-			# use g++
-			LINK="g++"
-		    else
-			echo "mklib: warning: can't find C++ compiler, trying CC."
-			LINK="CC"
-		    fi
-		else
-		    # use native Sun linker for C code
-		    LINK="ld"
-		fi
-	    fi
-
-	    # linker options
-	    if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
-		# SunOS tools, -G to make shared libs
-		OPTS="-G"
-	    else
-		# gcc linker
-		# Check if objects are 32-bit and we're running in 64-bit
-		# environment.  If so, pass -m32 flag to linker.
-		set ${OBJECTS}
-		ABI32=`file $1 | grep 32-bit`
-		if [ "${ABI32}" ] ; then
-		    OPTS="-m32 -shared -Wl,-Bdynamic"
-		else
-		    OPTS="-m64 -shared -Wl,-Bdynamic"
-		fi
-	    fi
-
-	    # If using Sun C++ compiler, need to tell it not to add runpaths
-	    # that are specific to the build machine
-	    if [ ${LINK} = "CC" ] ; then
-		OPTS="${OPTS} -norunpath"
-	    fi
-
-	    # Solaris linker requires explicitly listing the Standard C & C++
-	    # libraries in the link path when building shared objects
-	    if [ ${LINK} = "CC" ] ; then
-		DEPS="${DEPS} -lCrun"
-	    fi
-	    DEPS="${DEPS} -lc"
-
-	    if [ $EXPORTS ] ; then
-		# Make the 'mapfile.scope' linker mapfile
-		echo "{" > mapfile.scope
-		echo "global:" >> mapfile.scope
-		sed 's/$/;/' ${EXPORTS} >> mapfile.scope
-		echo "local:" >> mapfile.scope
-		echo "    *;" >> mapfile.scope
-		echo "};" >> mapfile.scope
-		OPTS="${OPTS} -Wl,-Mmapfile.scope"
-	    fi
-
-	    # Check if objects are 64-bit
-	    # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
-	    set ${OBJECTS}
-	    if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
-		ABI64=`file $1 | grep "ELF 64-bit"`
-		if [ "${ABI64}" ] ; then
-		    case `uname -p` in
-			sparc)	    OPTS="${OPTS} -xarch=v9" ;;
-			i386)	    OPTS="${OPTS} -xarch=amd64" ;;
-		    esac
-		fi
-	    fi
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-
-	    # for debug:
-	    #echo "mklib: linker is" ${LINK} ${OPTS}
-	    if [ $NOPREFIX = 1 ] ; then
-		rm -f ${LIBNAME}
-		${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
-		FINAL_LIBS="${LIBNAME}"
-	    else
-		rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
-		${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
-		ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
-		FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
-	    fi
-	fi
-	;;
-
-    'FreeBSD')
-	# we assume gcc
-
-	if [ "x$LINK" = "x" ] ; then
-	    # -linker was not specified so set default link command now
-            if [ $CPLUSPLUS = 1 ] ; then
-                LINK=g++
-            else
-                LINK=gcc
-            fi
-	fi
-
-	if [ $NOPREFIX = 1 ] ; then
-	    # No "lib" or ".so" part
-	    echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
-	    OPTS="-shared"
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-	    rm -f ${LIBNAME}
-	    ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
-	    FINAL_LIBS=${LIBNAME}
-        elif [ $STATIC = 1 ] ; then
-	    # make a static .a library
-	    STLIB="lib${LIBNAME}.a"
-	    echo "mklib: Making FreeBSD static library: " ${STLIB}
-
-	    # expand .a into .o files
-	    NEW_OBJECTS=`expand_archives ${STLIB}.obj $OBJECTS`
-
-	    FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
-
-	    # remove temporary extracted .o files
-	    rm -rf ${STLIB}.obj
-	else
-	    # make dynamic library
-	    SHLIB="lib${LIBNAME}.so.${MAJOR}"
-	    OPTS="-shared -Wl,-soname,${SHLIB}"
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-	    echo "mklib: Making FreeBSD shared library: " ${SHLIB}
-	    rm -f ${SHLIB}
-	    ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
-	    ln -sf ${SHLIB} "lib${LIBNAME}.so"
-	    FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
-	fi
-	;;
-
-    'IRIX' | 'IRIX64')
-        if [ $STATIC = 1 ] ; then
-	    LIBNAME="lib${LIBNAME}.a"
-	    FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
-	else
-	    LIBNAME="lib${LIBNAME}.so"  # prefix with "lib", suffix with ".so"
-
-	    # examine first object to determine ABI
-    	    set ${OBJECTS}
-	    ABI_O32=`file $1 | grep 'ELF 32-bit'`
-	    ABI_N32=`file $1 | grep 'ELF N32'`
-	    ABI_N64=`file $1 | grep 'ELF 64-bit'`
-	    if [ "${ABI_O32}" ] ; then
-		OPTS="-32 -shared -all"
-		ABI="o32-bit"
-	    elif [ "${ABI_N32}" ] ; then
-		OPTS="-n32 -shared -all"
-		ABI="n32-bit"
-	    elif [ "${ABI_N64}" ] ; then
-		OPTS="-64 -shared -all"
-		ABI="64-bit"
-	    else
-		echo "Error: Unexpected IRIX ABI!"
-		exit 1
-	    fi
-
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-
-	    if [ $CPLUSPLUS = 1 ] ; then
-		LINK="CC"
-	    else
-		LINK="ld"
-	    fi
-
-	    echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
-	    ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
-	    FINAL_LIBS=${LIBNAME}
-	fi
-	;;
-
-    'linux-cygwin')
-	LIBNAME="lib${LIBNAME}.a"
-	echo "mklib: Making linux-cygwin library: " ${LIBNAME}
-	rm -f ${LIBNAME}
-	gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
-	FINAL_LIBS=${LIBNAME}
-	;;
-
-    'HP-UX')
-        if [ $STATIC = 1 ] ; then
-	    LIBNAME="lib${LIBNAME}.a"
-	    echo "mklib: Making HP-UX static library: " ${LIBNAME}
-    	    FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
-	else
-            # HP uses a .2 for their current GL/GLU libraries
-	    if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
-	       MAJOR=2
-	    fi
-	    RUNLIB="lib${LIBNAME}.${MAJOR}"
-	    DEVLIB="lib${LIBNAME}.sl"
-	    echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
-	    ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
-	    ln -s ${RUNLIB} ${DEVLIB}
-	    FINAL_LIBS="${RUNLIB} ${DEVLIB}"
-	fi
-	;;
-
-    'AIX' )
-	# examine first object to determine ABI
-    	set ${OBJECTS}
-	ABI_64=`file $1 | grep '64-bit'`
-	if [ "${ABI_64}" ] ; then
-	    X64="-X64"
-	    Q64="-q64"
-	    OFILE=shr_64.o
-	else
-	    OFILE=shr.o  #Want to be consistent with the IBM libGL.a
-	fi
-
-	if [ $STATIC = 1 ] ; then
-	    LIBNAME="lib${LIBNAME}.a"
-	    echo "mklib: Making AIX static library: " ${LIBNAME}
-    	    FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
-	else
-	    EXPFILE="lib${LIBNAME}.exp"
-	    LIBNAME="lib${LIBNAME}.a"  # shared objects are still stored in the .a libraries
-	    OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
-	    rm -f ${EXPFILE} ${OFILE}
-	    NM="/bin/nm -eC ${X64}"
-	    echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
-	    ${NM} ${OBJECTS} | awk '{
-	    if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
-	    && ( substr($1,1,1) != ".")) {
-		    if (substr ($1, 1, 7) != "__sinit" &&
-			    substr ($1, 1, 7) != "__sterm") {
-			    if (substr ($1, 1, 5) == "__tf1")
-				print (substr ($1, 7))
-			    else if (substr ($1, 1, 5) == "__tf9")
-				print (substr ($1, 15))
-			    else
-				print $1
-			}
-		}
-	    }' | sort -u >> ${EXPFILE}
-
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-
-            # On AIX a shared library is linked differently when
-            # you want to dlopen the file
-	    if [ $DLOPEN = "1" ] ; then
-		cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
-	    else
-		cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
-		ar ${X64} -r ${LIBNAME} ${OFILE}
-	    fi
-
-            FINAL_LIBS="${LIBNAME}"
-        fi
-        ;;
-
-    'OpenSTEP')
-	LIBNAME="lib${LIBNAME}.a"
-	echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
-	libtool -static -o ${LIBNAME} - ${OBJECTS}
-	FINAL_LIBS=${LIBNAME}
-	;;
-
-    'OSF1')
-        if [ $STATIC = 1 ] ; then
-	    LIBNAME="lib${LIBNAME}.a"
-	    echo "mklib: Making OSF/1 static library: " ${LIBNAME}
-    	    FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
-	else
-	    VERSION="${MAJOR}.${MINOR}"
-	    LIBNAME="lib${LIBNAME}.so"
-	    echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
-	    if [ "x$LINK" = "x" ] ; then
-		if [ $CPLUSPLUS = 1 ] ; then
-		    LINK=cxx
-		else
-		    LINK=cc
-		fi
-	    fi
-	    rm -f ${LIBNAME}.${VERSION}
-	    ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
-	    ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
-	    FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
-	fi
-	;;
-
-    'Darwin')
-        if [ $STATIC = 1 ] ; then
-            LIBNAME="lib${LIBNAME}.a"
-            echo "mklib: Making Darwin static library: " ${LIBNAME}
-            OPTS="-ruvs"
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-
-            # expand .a into .o files
-            NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
-
-            # make static lib
-            FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
-
-            # remove temporary extracted .o files
-            rm -rf ${LIBNAME}.obj
-
-            FINAL_LIBS=${LIBNAME}
-        else
-            # On Darwin a .bundle is used for a library that you want to dlopen
-            if [ $DLOPEN = "1" ] ; then
-                LIBSUFFIX="bundle"
-                OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
-            else
-                LIBSUFFIX="dylib"
-                if [ -z "$ID" ] ; then
-                    ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
-                fi
-                OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
-            fi
-
-            if [ ${EXPORTS} ] ; then
-                if [ -f ${EXPORTS}".darwin" ] ; then
-                    EXPORTS=$EXPORTS".darwin"
-                fi
-                OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
-            fi
-
-            LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
-            LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
-
-	    # examine first object to determine ABI
-    	    set ${OBJECTS}
-            ABIS=`lipo -info $1 | sed s/.*://`
-            for ABI in $ABIS; do
-                OPTS="${OPTS} -arch ${ABI}"
-            done
-
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-
-	    # determine linker
-	    if [ $CPLUSPLUS = 1 ] ; then
-		LINK="g++"
-	    else
-		LINK="cc"
-	    fi
-
-            echo "mklib: Making Darwin shared library: " ${LIBNAME}
-
-            ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
-            ln -s ${LIBNAME} ${LINKNAME}
-            FINAL_LIBS="${LIBNAME} ${LINKNAME}"
-        fi
-        ;;
-
-    'LynxOS')
-	LIBNAME="lib${LIBNAME}.a"
-	echo "mklib: Making LynxOS static library: " ${LIBNAME}
-        FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
-	;;
-
-    'QNX')
-	LIBNAME="lib${LIBNAME}.a"
-	echo "mklib: Making QNX library: " ${LIBNAME}
-	wlib ${LIBNAME} ${OBJECTS}
-	FINAL_LIBS=${LIBNAME}
-	;;
-
-    'MorphOS')
-	LIBNAME="lib${LIBNAME}.a"
-	echo "mklib: Making MorphOS library: " ${LIBNAME}
-	ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
-	FINAL_LIBS="${LIBNAME}"
-	;;
-
-    'icc' | 'icc-istatic')
-	# Intel C compiler
-	# This should get merged into the Linux code, above, since this isn't
-	# really a different architecture.
-	LIBNAME="lib${LIBNAME}"     # prefix with "lib"
-
-        if [ $STATIC = 1 ] ; then
-            echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
-            LINK="ar"
-            OPTS="-ruv"
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-            # make lib
-            ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
-            # finish up
-            FINAL_LIBS="${LIBNAME}.a"
-        else
-            if [ $ARCH = icc-istatic ] ; then
-                 OPTS="-shared -i-static -cxxlib-icc"
-            else
-                 OPTS="-shared"
-            fi
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-            VERSION="${MAJOR}.${MINOR}.${PATCH}"
-            echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
-
-            if [ $CPLUSPLUS = 1 ] ; then
-                LINK="icpc"
-            else
-                LINK="icc"
-            fi
-            # rm any old libs
-            rm -f ${LIBNAME}.so.${VERSION}
-            rm -f ${LIBNAME}.so.${MAJOR}
-            rm -f ${LIBNAME}.so
-            # make lib
-            ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
-            # make usual symlinks
-            ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
-            ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
-            # finish up
-            FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
-        fi
-	;;
-
-    'aix-gcc')
-	# AIX with gcc
-        if [ $STATIC = 1 ] ; then
-	    LIBNAME="lib${LIBNAME}.a"
-	    echo "mklib: Making AIX GCC static library: " ${LIBNAME}
-            FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
-	else
-	    LIBNAME="lib${LIBNAME}.so"  # prefix with "lib", suffix with ".so"
-	    echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
-	    # remove old lib
-	    rm -f ${LIBNAME}
-	    # make the lib
-	    gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
-	    # NOTE: the application linking with this library must specify
-	    # the -Wl,-brtl flags to gcc
-	    FINAL_LIBS=${LIBNAME}
-	fi
-	;;
-
-    'ultrix')
-	# XXX untested
-        if [ $STATIC = 0 ] ; then
-	    echo "mklib: Warning shared libs not supported on Ultrix"
-	fi
-	LIBNAME="lib${LIBNAME}.a"
-	echo "mklib: Making static library for Ultrix: " ${LIBNAME}
-        FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
-	;;
-
-     CYGWIN*)
-	# GCC-based environment
-
-	if [ "x$LINK" = "x" ] ; then
-	    # -linker was not specified so set default link command now
-            if [ $CPLUSPLUS = 1 ] ; then
-                LINK=g++
-            else
-                LINK=gcc
-            fi
-	fi
-
-	if [ $NOPREFIX = 1 ] ; then
-	    # No "lib" or ".so" part
-	    echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
-	    OPTS="-shared -Wl,--enable-auto-image-base"
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-	    rm -f ${LIBNAME}
-	    ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} || exit $?
-	    FINAL_LIBS=${LIBNAME}
-        else
-	CYGNAME="cyg${LIBNAME}"     # prefix with "cyg"
-	LIBNAME="lib${LIBNAME}"     # prefix with "lib"
-
-        if [ $STATIC = 1 ] ; then
-	    LIBNAME=${LIBNAME}.a
-            echo "mklib: Making CYGWIN static library: " ${LIBNAME}
-            OPTS="-ru"
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-
-            # expand .a into .o files
-            NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
-
-            FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
-
-            # remove temporary extracted .o files
-            rm -rf ${LIBNAME}.obj
-        else
-	    OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
-            if [ "${ALTOPTS}" ] ; then
-                OPTS=${ALTOPTS}
-            fi
-            echo "mklib: Making CYGWIN shared library: " ${CYGNAME}-${MAJOR}.dll
-
-            # rm any old libs
-            rm -f ${CYGNAME}-${MAJOR}.dll
-            rm -f ${LIBNAME}-${MAJOR}.dll.a
-            rm -f ${LIBNAME}.dll.a
-            rm -f ${LIBNAME}.a
-
-            # make lib
-            ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} || exit $?
-            # make usual symlinks
-            ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
-            # finish up
-            FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
-	    # special case for installing in bin
-            FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
-        fi
-        fi
-	;;
-
-	'Haiku')
-		if [ $STATIC = 1 ] ; then
-			LIBNAME="lib${LIBNAME}.a"
-			if [ "x$LINK" = "x" ] ; then
-				# -linker was not specified so set default link command now
-				if [ $CPLUSPLUS = 1 ] ; then
-					LINK=g++
-				else
-					LINK=gcc
-				fi
-			fi
-
-			OPTS="-ru"
-			if [ "${ALTOPTS}" ] ; then
-				OPTS=${ALTOPTS}
-			fi
-
-			echo "mklib: Making static library for Haiku: " ${LIBNAME}
-
-			# expand .a into .o files
-			NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
-
-			# make static lib
-			FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
-
-			# remove temporary extracted .o files
-			rm -rf ${LIBNAME}.obj
-		else
-			LIBNAME="lib${LIBNAME}.so"  # prefix with "lib", suffix with ".so"
-			OPTS="-shared"
-
-			echo "mklib: Making shared library for Haiku: " ${LIBNAME}
-			${LINK} ${OPTS} ${LDFLAGS} ${OBJECTS} ${DEPS} -o ${LIBNAME}
-			FINAL_LIBS="${LIBNAME}"
-		fi
-	;;
-
-    'example')
-	# If you're adding support for a new architecture, you can
-	# start with this:
-        if [ $STATIC = 1 ] ; then
-	    LIBNAME="lib${LIBNAME}.a"
-	    echo "mklib: Making static library for example arch: " ${LIBNAME}
-            FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
-	else
-	    LIBNAME="lib${LIBNAME}.so"  # prefix with "lib", suffix with ".so"
-	    echo "mklib: Making shared library for example arch: " ${LIBNAME}
-	    ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
-	    FINAL_LIBS="${LIBNAME}"
-	fi
-	;;
-
-    *)
-	echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
-	echo "mklib: Please add necessary commands to mklib script."
-	;;
-esac
-
-
-#
-# Put library files into installation directory if specified.
-#
-if [ ${INSTALLDIR} != "." ] ; then
-    echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
-    test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
-    mv ${FINAL_LIBS} ${INSTALLDIR}/
-
-    if [ "x${FINAL_BINS}" != "x" ] ; then
-        echo "mklib: Installing" ${FINAL_BINS} "in" ${INSTALLDIR}
-        mv ${FINAL_BINS} ${INSTALLDIR}/
-    fi
-fi
diff --git a/mesalib/configs/.gitignore b/mesalib/configs/.gitignore
deleted file mode 100644
index 97ac5b732..000000000
--- a/mesalib/configs/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-current
-autoconf
diff --git a/mesalib/configs/current.in b/mesalib/configs/current.in
deleted file mode 100644
index dc8e63f43..000000000
--- a/mesalib/configs/current.in
+++ /dev/null
@@ -1,222 +0,0 @@
-# Autoconf configuration
-
-# Pull in the defaults
-include $(TOP)/configs/default
-
-# This is generated by configure
-CONFIG_NAME = autoconf
-
-# Compiler and flags
-CC = @CC@
-CXX = @CXX@
-PIC_FLAGS = @PIC_FLAGS@
-DEFINES = @DEFINES@
-API_DEFINES = @API_DEFINES@
-SHARED_GLAPI = @SHARED_GLAPI@
-CFLAGS_NOVISIBILITY = @CPPFLAGS@ @CFLAGS@ \
-	$(PIC_FLAGS) $(DEFINES)
-CXXFLAGS_NOVISIBILITY = @CPPFLAGS@ @CXXFLAGS@ \
-	$(PIC_FLAGS) $(DEFINES)
-CFLAGS = $(CFLAGS_NOVISIBILITY) @VISIBILITY_CFLAGS@
-CXXFLAGS = $(CXXFLAGS_NOVISIBILITY) @VISIBILITY_CXXFLAGS@
-LDFLAGS = @LDFLAGS@
-RADEON_CFLAGS = @RADEON_CFLAGS@
-RADEON_LIBS = @RADEON_LIBS@
-NOUVEAU_CFLAGS = @NOUVEAU_CFLAGS@
-NOUVEAU_LIBS = @NOUVEAU_LIBS@
-INTEL_LIBS = @INTEL_LIBS@
-INTEL_CFLAGS = @INTEL_CFLAGS@
-X11_LIBS = @X11_LIBS@
-X11_CFLAGS = @X11_CFLAGS@
-LLVM_BINDIR = @LLVM_BINDIR@
-LLVM_CFLAGS = @LLVM_CFLAGS@
-LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
-LLVM_CXXFLAGS = @LLVM_CXXFLAGS@
-LLVM_LDFLAGS = @LLVM_LDFLAGS@
-LLVM_LIBDIR = @LLVM_LIBDIR@
-LLVM_LIBS = @LLVM_LIBS@
-LLVM_INCLUDEDIR = @LLVM_INCLUDEDIR@
-GLW_CFLAGS = @GLW_CFLAGS@
-GLX_TLS = @GLX_TLS@
-
-# dlopen
-DLOPEN_LIBS = @DLOPEN_LIBS@
-CLOCK_LIB = @CLOCK_LIB@
-
-# Source selection
-MESA_ASM_FILES = @MESA_ASM_FILES@
-
-# Misc tools and flags
-MAKE = @MAKE@
-SHELL = @SHELL@
-MKLIB_OPTIONS = @MKLIB_OPTIONS@
-MKDEP = @MKDEP@
-MKDEP_OPTIONS = @MKDEP_OPTIONS@
-INSTALL = @INSTALL@
-AWK = @AWK@
-GREP = @GREP@
-NM = @NM@
-
-# Perl
-PERL = @PERL@
-
-# Indent (used for generating dispatch tables)
-INDENT = @INDENT@
-INDENT_FLAGS = @INDENT_FLAGS@
-
-# Python and flags (generally only needed by the developers)
-PYTHON2 = @PYTHON2@
-PYTHON_FLAGS = -t -O -O
-
-# Flex and Bison for GLSL compiler
-FLEX = @LEX@
-BISON = @YACC@
-
-# Library names (base name)
-GL_LIB = @GL_LIB@
-GLU_LIB = @GLU_LIB@
-GLW_LIB = GLw
-OSMESA_LIB = @OSMESA_LIB@
-GLESv1_CM_LIB = GLESv1_CM
-GLESv2_LIB = GLESv2
-VG_LIB = OpenVG
-GLAPI_LIB = glapi
-
-# Library names (actual file names)
-GL_LIB_NAME = @GL_LIB_NAME@
-GLU_LIB_NAME = @GLU_LIB_NAME@
-GLW_LIB_NAME = @GLW_LIB_NAME@
-OSMESA_LIB_NAME = @OSMESA_LIB_NAME@
-EGL_LIB_NAME = @EGL_LIB_NAME@
-GLESv1_CM_LIB_NAME = @GLESv1_CM_LIB_NAME@
-GLESv2_LIB_NAME = @GLESv2_LIB_NAME@
-VG_LIB_NAME = @VG_LIB_NAME@
-GLAPI_LIB_NAME = @GLAPI_LIB_NAME@
-
-# Globs used to install the lib and all symlinks
-GL_LIB_GLOB = @GL_LIB_GLOB@
-GLU_LIB_GLOB = @GLU_LIB_GLOB@
-GLW_LIB_GLOB = @GLW_LIB_GLOB@
-EGL_LIB_GLOB = @EGL_LIB_GLOB@
-GLESv1_CM_LIB_GLOB = @GLESv1_CM_LIB_GLOB@
-GLESv2_LIB_GLOB = @GLESv2_LIB_GLOB@
-VG_LIB_GLOB = @VG_LIB_GLOB@
-GLAPI_LIB_GLOB = @GLAPI_LIB_GLOB@
-
-# Directories to build
-LIB_DIR = @LIB_DIR@
-SRC_DIRS = @SRC_DIRS@
-DRIVER_DIRS = @DRIVER_DIRS@
-GALLIUM_DIRS = @GALLIUM_DIRS@
-GALLIUM_DRIVERS_DIRS = @GALLIUM_DRIVERS_DIRS@
-GALLIUM_WINSYS_DIRS = @GALLIUM_WINSYS_DIRS@
-GALLIUM_TARGET_DIRS = @GALLIUM_TARGET_DIRS@
-GALLIUM_STATE_TRACKERS_DIRS = @GALLIUM_STATE_TRACKERS_DIRS@
-GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a
-GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
-
-# Driver specific build vars
-DRI_DIRS = @DRI_DIRS@
-EGL_PLATFORMS = @EGL_PLATFORMS@
-EGL_CLIENT_APIS = @EGL_CLIENT_APIS@
-
-# Dependencies
-X11_INCLUDES = @X11_INCLUDES@
-
-# GLw motif setup
-GLW_SOURCES = @GLW_SOURCES@
-MOTIF_CFLAGS = @MOTIF_CFLAGS@
-
-# Library/program dependencies
-GL_LIB_DEPS = @GL_LIB_DEPS@
-OSMESA_LIB_DEPS = -L$(TOP)/$(LIB_DIR) @OSMESA_MESA_DEPS@ \
-	@OSMESA_LIB_DEPS@
-EGL_LIB_DEPS = @EGL_LIB_DEPS@
-GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) @GLU_MESA_DEPS@ \
-	@GLU_LIB_DEPS@
-GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) @GLW_MESA_DEPS@ \
-	@GLW_LIB_DEPS@
-GLESv1_CM_LIB_DEPS = @GLESv1_CM_LIB_DEPS@
-GLESv2_LIB_DEPS = @GLESv2_LIB_DEPS@
-VG_LIB_DEPS = @VG_LIB_DEPS@
-GLAPI_LIB_DEPS = @GLAPI_LIB_DEPS@
-
-# DRI dependencies
-DRI_LIB_DEPS = @DRI_LIB_DEPS@
-GALLIUM_DRI_LIB_DEPS = @GALLIUM_DRI_LIB_DEPS@
-LIBDRM_CFLAGS = @LIBDRM_CFLAGS@
-LIBDRM_LIBS = @LIBDRM_LIBS@
-DRI2PROTO_CFLAGS = @DRI2PROTO_CFLAGS@
-GLPROTO_CFLAGS = @GLPROTO_CFLAGS@
-EXPAT_INCLUDES = @EXPAT_INCLUDES@
-
-# Autoconf directories
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-libdir = @libdir@
-includedir = @includedir@
-
-# Installation directories (for make install)
-INSTALL_DIR = $(prefix)
-INSTALL_LIB_DIR = $(libdir)
-INSTALL_INC_DIR = $(includedir)
-
-# DRI installation directories
-DRI_DRIVER_INSTALL_DIR = @DRI_DRIVER_INSTALL_DIR@
-
-# Where libGL will look for DRI hardware drivers
-DRI_DRIVER_SEARCH_DIR = @DRI_DRIVER_SEARCH_DIR@
-
-# EGL driver install directory
-EGL_DRIVER_INSTALL_DIR = @EGL_DRIVER_INSTALL_DIR@
-
-# XVMC library install directory
-XVMC_LIB_INSTALL_DIR=@XVMC_LIB_INSTALL_DIR@
-
-# VDPAU library install directory
-VDPAU_LIB_INSTALL_DIR=@VDPAU_LIB_INSTALL_DIR@
-
-# VA library install directory
-VA_LIB_INSTALL_DIR=@VA_LIB_INSTALL_DIR@
-
-# Xorg driver install directory (for xorg state-tracker)
-XORG_DRIVER_INSTALL_DIR = @XORG_DRIVER_INSTALL_DIR@
-
-# Path to OpenCL C library libclc
-LIBCLC_PATH = @LIBCLC_PATH@
-
-# pkg-config substitutions
-GL_PC_REQ_PRIV = @GL_PC_REQ_PRIV@
-GL_PC_LIB_PRIV = @GL_PC_LIB_PRIV@
-GL_PC_CFLAGS = @GL_PC_CFLAGS@
-DRI_PC_REQ_PRIV = @DRI_PC_REQ_PRIV@
-GLU_PC_REQ = @GLU_PC_REQ@
-GLU_PC_REQ_PRIV = @GLU_PC_REQ_PRIV@
-GLU_PC_LIB_PRIV = @GLU_PC_LIB_PRIV@
-GLU_PC_CFLAGS = @GLU_PC_CFLAGS@
-GLW_PC_REQ_PRIV = @GLW_PC_REQ_PRIV@
-GLW_PC_LIB_PRIV = @GLW_PC_LIB_PRIV@
-GLW_PC_CFLAGS = @GLW_PC_CFLAGS@
-OSMESA_PC_REQ = @OSMESA_PC_REQ@
-OSMESA_PC_LIB_PRIV = @OSMESA_PC_LIB_PRIV@
-GLESv1_CM_PC_LIB_PRIV = @GLESv1_CM_PC_LIB_PRIV@
-GLESv2_PC_LIB_PRIV = @GLESv2_PC_LIB_PRIV@
-EGL_PC_REQ_PRIV = @GL_PC_REQ_PRIV@
-EGL_PC_LIB_PRIV = @GL_PC_LIB_PRIV@
-EGL_PC_CFLAGS = @GL_PC_CFLAGS@
-
-XCB_DRI2_CFLAGS = @XCB_DRI2_CFLAGS@
-XCB_DRI2_LIBS = @XCB_DRI2_LIBS@
-LIBUDEV_CFLAGS = @LIBUDEV_CFLAGS@
-LIBUDEV_LIBS = @LIBUDEV_LIBS@
-WAYLAND_CFLAGS = @WAYLAND_CFLAGS@
-WAYLAND_LIBS = @WAYLAND_LIBS@
-
-MESA_LLVM = @MESA_LLVM@
-
-LLVM_VERSION = @LLVM_VERSION@
-
-HAVE_XF86VIDMODE = @HAVE_XF86VIDMODE@
-
-GALLIUM_PIPE_LOADER_DEFINES = @GALLIUM_PIPE_LOADER_DEFINES@
-GALLIUM_PIPE_LOADER_LIBS = @GALLIUM_PIPE_LOADER_LIBS@
diff --git a/mesalib/configs/default b/mesalib/configs/default
deleted file mode 100644
index 7b9e1c61a..000000000
--- a/mesalib/configs/default
+++ /dev/null
@@ -1,180 +0,0 @@
-# Default/template configuration
-
-# This is included by other config files which may override some
-# of these variables.
-# Think of this as a base class from which configs are derived.
-
-
-CONFIG_NAME = default
-
-# Version info
-MESA_MAJOR=9
-MESA_MINOR=1
-MESA_TINY=0
-MESA_VERSION = $(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY)
-
-# external projects.  This should be useless now that we use libdrm.
-DRM_SOURCE_PATH=$(TOP)/../drm
-
-# Compiler and flags
-CC = cc
-CXX = CC
-CFLAGS = -O
-CXXFLAGS = -O
-LDFLAGS =
-GLU_CFLAGS = 
-GLX_TLS = no
-
-# Compiler for building demos/tests/etc
-APP_CC = $(CC)
-APP_CXX = $(CXX)
-
-# Misc tools and flags
-SHELL = /bin/sh
-MKLIB = $(SHELL) $(TOP)/bin/mklib
-MKLIB_OPTIONS = 
-MKDEP = makedepend
-MKDEP_OPTIONS = -fdepend
-MAKE = make
-FLEX = flex
-BISON = bison
-PKG_CONFIG = pkg-config
-
-# Use MINSTALL for installing libraries, INSTALL for everything else
-MINSTALL = $(SHELL) $(TOP)/bin/minstall
-INSTALL = $(MINSTALL)
-
-# Tools for regenerating glapi (generally only needed by the developers)
-PYTHON2 = python
-PYTHON_FLAGS = -t -O -O
-INDENT = indent
-INDENT_FLAGS = -i4 -nut -br -brs -npcs -ce -T GLubyte -T GLbyte -T Bool
-
-# Library names (base name)
-GL_LIB = GL
-GLU_LIB = GLU
-GLW_LIB = GLw
-OSMESA_LIB = OSMesa
-EGL_LIB = EGL
-GLESv1_CM_LIB = GLESv1_CM
-GLESv2_LIB = GLESv2
-VG_LIB = OpenVG
-GLAPI_LIB = glapi
-
-# Library names (actual file names)
-GL_LIB_NAME = lib$(GL_LIB).so
-GLU_LIB_NAME = lib$(GLU_LIB).so
-GLW_LIB_NAME = lib$(GLW_LIB).so
-OSMESA_LIB_NAME = lib$(OSMESA_LIB).so
-EGL_LIB_NAME = lib$(EGL_LIB).so
-GLESv1_CM_LIB_NAME = lib$(GLESv1_CM_LIB).so
-GLESv2_LIB_NAME = lib$(GLESv2_LIB).so
-VG_LIB_NAME = lib$(VG_LIB).so
-GLAPI_LIB_NAME = lib$(GLAPI_LIB).so
-
-# globs used to install the lib and all symlinks
-GL_LIB_GLOB = $(GL_LIB_NAME)*
-GLU_LIB_GLOB = $(GLU_LIB_NAME)*
-GLW_LIB_GLOB = $(GLW_LIB_NAME)*
-EGL_LIB_GLOB = $(EGL_LIB_NAME)*
-GLESv1_CM_LIB_GLOB = $(GLESv1_CM_LIB_NAME)*
-GLESv2_LIB_GLOB = $(GLESv2_LIB_NAME)*
-VG_LIB_GLOB = $(VG_LIB_NAME)*
-GLAPI_LIB_GLOB = $(GLAPI_LIB_NAME)*
-
-# Optional assembly language optimization files for libGL
-MESA_ASM_FILES =
-
-# GLw widget sources (Append "GLwMDrawA.c" here and add -lXm to GLW_LIB_DEPS in
-# order to build the Motif widget too)
-GLW_SOURCES = GLwDrawA.c
-MOTIF_CFLAGS = -I/usr/include/Motif1.2
-
-
-# Directories to build
-LIB_DIR = lib
-SRC_DIRS = glsl mapi/glapi mapi/vgapi mesa \
-	gallium egl gallium/winsys gallium/targets
-DRIVER_DIRS = x11 osmesa
-
-# Gallium directories and
-GALLIUM_DIRS = auxiliary drivers state_trackers
-GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a
-GALLIUM_DRIVERS_DIRS = softpipe trace rbug noop identity galahad i915 svga r300 nvfx nv50
-GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
-GALLIUM_WINSYS_DIRS = sw sw/xlib
-GALLIUM_TARGET_DIRS = libgl-xlib
-GALLIUM_STATE_TRACKERS_DIRS = glx vega
-
-# native platforms EGL should support
-EGL_PLATFORMS = x11
-EGL_CLIENT_APIS = $(GL_LIB)
-
-# Library dependencies
-#EXTRA_LIB_PATH ?=
-GL_LIB_DEPS     = -lX11 -lXext -lm -lpthread
-EGL_LIB_DEPS    = -ldl -lpthread
-OSMESA_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB)
-GLU_LIB_DEPS    = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm
-GLW_LIB_DEPS    = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lXt -lX11
-GLESv1_CM_LIB_DEPS = -lpthread
-GLESv2_LIB_DEPS = -lpthread
-VG_LIB_DEPS    = -lpthread
-GLAPI_LIB_DEPS = -lpthread
-
-# Program dependencies - specific GL libraries added in Makefiles
-X11_LIBS = -lX11
-
-DLOPEN_LIBS = -ldl
-
-# Installation directories (for make install)
-INSTALL_DIR = /usr/local
-INSTALL_LIB_DIR = $(INSTALL_DIR)/$(LIB_DIR)
-INSTALL_INC_DIR = $(INSTALL_DIR)/include
-DRI_DRIVER_INSTALL_DIR = $(INSTALL_LIB_DIR)/dri
-
-# Where libGL will look for DRI hardware drivers
-DRI_DRIVER_SEARCH_DIR = $(DRI_DRIVER_INSTALL_DIR)
-
-# EGL driver install directory
-EGL_DRIVER_INSTALL_DIR = $(INSTALL_LIB_DIR)/egl
-
-# Xorg driver install directory (for xorg state-tracker)
-XORG_DRIVER_INSTALL_DIR = $(INSTALL_LIB_DIR)/xorg/modules/drivers
-
-# pkg-config substitutions
-GL_PC_REQ_PRIV =
-GL_PC_LIB_PRIV =
-GL_PC_CFLAGS =
-DRI_PC_REQ_PRIV =
-GLU_PC_REQ = gl
-GLU_PC_REQ_PRIV =
-GLU_PC_LIB_PRIV =
-GLU_PC_CFLAGS =
-GLW_PC_REQ_PRIV =
-GLW_PC_LIB_PRIV =
-GLW_PC_CFLAGS =
-OSMESA_PC_REQ =
-OSMESA_PC_LIB_PRIV =
-GLESv1_CM_PC_REQ_PRIV =
-GLESv1_CM_PC_LIB_PRIV =
-GLESv1_CM_PC_CFLAGS =
-GLESv2_PC_REQ_PRIV =
-GLESv2_PC_LIB_PRIV =
-GLESv2_PC_CFLAGS =
-VG_PC_REQ_PRIV =
-VG_PC_LIB_PRIV =
-VG_PC_CFLAGS =
-
-# default targets
-# this helps reduce the mismatch between our automake Makefiles and the old
-# custom Makefiles while we transition.
-
-all: default
-
-am--refresh:
-
-distclean: clean
-
-check:
-test:
diff --git a/mesalib/configure.ac b/mesalib/configure.ac
index 1414ce826..1b2083df5 100644
--- a/mesalib/configure.ac
+++ b/mesalib/configure.ac
@@ -51,15 +51,10 @@ AC_CHECK_PROGS([MAKE], [gmake make])
 AC_CHECK_PROGS([PYTHON2], [python2 python])
 AC_PROG_SED
 AC_PROG_MKDIR_P
-AC_PATH_PROG([MKDEP], [makedepend])
 
 LT_PREREQ([2.2])
 LT_INIT([disable-static])
 
-if test "x$MKDEP" = "x"; then
-    AC_MSG_ERROR([makedepend is required to build Mesa])
-fi
-
 AC_PROG_YACC
 AC_PATH_PROG([YACC_INST], $YACC)
 if test ! -f "$srcdir/src/glsl/glcpp/glcpp-parse.c"; then
@@ -76,10 +71,7 @@ if test "x$INDENT" != "xcat"; then
     AC_SUBST(INDENT_FLAGS, '-i4 -nut -br -brs -npcs -ce -TGLubyte -TGLbyte -TBool')
 fi
 
-dnl Our fallback install-sh is a symlink to minstall. Use the existing
-dnl configuration in that case.
 AC_PROG_INSTALL
-test "x$INSTALL" = "x$ac_install_sh" && INSTALL='$(MINSTALL)'
 
 dnl We need a POSIX shell for parts of the build. Assume we have one
 dnl in most cases.
@@ -126,21 +118,6 @@ if test "x$GCC" = xyes -a "x$acv_mesa_CLANG" = xno; then
     fi
 fi
 
-
-MKDEP_OPTIONS=-fdepend
-dnl Ask gcc where it's keeping its secret headers
-if test "x$GCC" = xyes; then
-    for dir in include include-fixed; do
-        GCC_INCLUDES=`$CC -print-file-name=$dir`
-        if test "x$GCC_INCLUDES" != x && \
-           test "$GCC_INCLUDES" != "$dir" && \
-           test -d "$GCC_INCLUDES"; then
-            MKDEP_OPTIONS="$MKDEP_OPTIONS -I$GCC_INCLUDES"
-        fi
-    done
-fi
-AC_SUBST([MKDEP_OPTIONS])
-
 dnl Make sure the pkg-config macros are defined
 m4_ifndef([PKG_PROG_PKG_CONFIG],
     [m4_fatal([Could not locate the pkg-config autoconf macros.
@@ -320,15 +297,6 @@ esac
 
 AM_CONDITIONAL(BUILD_SHARED, test "x$enable_shared" = xyes)
 
-dnl
-dnl mklib options
-dnl
-AC_ARG_VAR([MKLIB_OPTIONS],[Options for the Mesa library script, mklib])
-if test "$enable_static" = yes; then
-    MKLIB_OPTIONS="$MKLIB_OPTIONS -static"
-fi
-AC_SUBST([MKLIB_OPTIONS])
-
 dnl
 dnl other compiler options
 dnl
@@ -525,9 +493,6 @@ if test "x$enable_asm" = xyes; then
 fi
 AC_SUBST([MESA_ASM_FILES])
 
-dnl PIC code macro
-MESA_PIC_FLAGS
-
 dnl Check to see if dlopen is in default libraries (like Solaris, which
 dnl has it in libc), or if libdl is needed to get it.
 AC_CHECK_FUNC([dlopen], [DEFINES="$DEFINES -DHAVE_DLOPEN"],
@@ -1398,6 +1363,7 @@ if test "x$enable_openvg" = xyes; then
     VG_PC_LIB_PRIV="-lm $CLOCK_LIB $PTHREAD_LIBS $DLOPEN_LIBS"
     AC_SUBST([VG_PC_LIB_PRIV])
 fi
+AM_CONDITIONAL(HAVE_OPENVG, test "x$enable_openvg" = xyes)
 
 dnl
 dnl D3D1X configuration
@@ -1452,17 +1418,27 @@ dnl
 
 AC_ARG_WITH([libclc-path],
    [AS_HELP_STRING([--with-libclc-path],
-         [Path to libclc builtins library.  Example: --with-libclc-path=\$HOME/libclc/])],
+         [DEPRECATED: See http://dri.freedesktop.org/wiki/GalliumCompute#How_to_Install])],
    [LIBCLC_PATH="$withval"],
    [LIBCLC_PATH=""])
 
+if test "x$LIBCLC_PATH" != x; then
+   AC_MSG_ERROR([The --with-libclc-path option has been deprecated.
+                  Please review the updated build instructions for clover:
+		  http://dri.freedesktop.org/wiki/GalliumCompute])
+fi
+
+
 AC_ARG_WITH([clang-libdir],
    [AS_HELP_STRING([--with-clang-libdir],
          [Path to Clang libraries @<:@default=llvm-config --libdir@:>@])],
    [CLANG_LIBDIR="$withval"],
    [CLANG_LIBDIR=""])
 
-AC_SUBST([LIBCLC_PATH])
+LIBCLC_INCLUDEDIR=`pkg-config --variable=includedir libclc`
+LIBCLC_LIBEXECDIR=`pkg-config --variable=libexecdir libclc`
+AC_SUBST([LIBCLC_INCLUDEDIR])
+AC_SUBST([LIBCLC_LIBEXECDIR])
 
 if test "x$enable_opencl" = xyes; then
     if test "x$with_gallium_drivers" = x; then
@@ -1473,11 +1449,19 @@ if test "x$enable_opencl" = xyes; then
         AC_MSG_ERROR([gcc >= 4.6 is required to build clover])
     fi
 
+    if test "x$LIBCLC_INCLUDEDIR" == x || test "x$LIBCLC_LIBEXECDIR" == x; then
+        AC_MSG_ERROR([pkg-config cannot use libclc.pc which is required to build clover])
+    fi
+
     GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS clover"
     GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS opencl"
     enable_gallium_loader=yes
 fi
 
+if test "x$enable_gallium_gbm" = xyes || test "x$enable_opencl" = xyes; then
+    GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS pipe-loader"
+fi
+
 dnl
 dnl Gallium configuration
 dnl
@@ -1500,8 +1484,10 @@ AC_SUBST([CLANG_RESOURCE_DIR])
 case "x$enable_opengl$enable_gles1$enable_gles2" in
 x*yes*)
     EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(GL_LIB)'
+    HAVE_OPENGL=yes
     ;;
 esac
+AM_CONDITIONAL(HAVE_OPENGL, test "x$HAVE_OPENGL" = xyes)
 
 AC_SUBST([VG_LIB_DEPS])
 AC_SUBST([EGL_CLIENT_APIS])
@@ -1699,7 +1685,7 @@ if test "x$enable_gallium_llvm" = xyes; then
 	LLVM_CXXFLAGS=`strip_unwanted_llvm_flags "$LLVM_CONFIG --cxxflags"`
 	LLVM_INCLUDEDIR=`$LLVM_CONFIG --includedir`
 	LLVM_LIBDIR=`$LLVM_CONFIG --libdir`
-	DEFINES="${DEFINES} -DHAVE_LLVM=`echo $LLVM_VERSION | sed -e 's/\([[0-9]]\)\.\([[0-9]]\)/0x0\10\2/g'`"
+	DEFINES="${DEFINES} -DHAVE_LLVM=0x0$LLVM_VERSION_INT"
 	MESA_LLVM=1
 
 	dnl Check for Clang interanl headers
@@ -1713,9 +1699,11 @@ if test "x$enable_gallium_llvm" = xyes; then
         fi
     else
 	MESA_LLVM=0
+	LLVM_VERSION_INT=0
     fi
 else
     MESA_LLVM=0
+    LLVM_VERSION_INT=0
 fi
 
 dnl Directory for XVMC libs
@@ -1730,7 +1718,7 @@ dnl
 dnl Gallium Tests
 dnl
 if test "x$enable_gallium_tests" = xyes; then
-    SRC_DIRS="$SRC_DIRS gallium/tests/trivial"
+    SRC_DIRS="$SRC_DIRS gallium/tests/trivial gallium/tests/unit"
     enable_gallium_loader=yes
 fi
 
@@ -1790,7 +1778,7 @@ gallium_require_llvm() {
 gallium_require_drm_loader() {
     if test "x$enable_gallium_loader" = xyes; then
         PKG_CHECK_MODULES([LIBUDEV], [libudev], [],
-                          AC_MSG_ERROR([Gallium drm loader requrires libudev]))
+                          AC_MSG_ERROR([Gallium drm loader requires libudev]))
         if test "x$have_libdrm" != xyes; then
             AC_MSG_ERROR([Gallium drm loader requires libdrm >= $LIBDRM_REQUIRED])
         fi
@@ -1823,10 +1811,12 @@ if test "x$with_gallium_drivers" != x; then
     for driver in $gallium_drivers; do
         case "x$driver" in
         xsvga)
+            HAVE_GALLIUM_SVGA=yes
             GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga softpipe"
             gallium_check_st "svga/drm" "dri-vmwgfx" "" "xa-vmwgfx"
             ;;
         xi915)
+            HAVE_GALLIUM_I915=yes
             PKG_CHECK_MODULES([INTEL], [libdrm_intel >= $LIBDRM_INTEL_REQUIRED])
             GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 softpipe"
             if test "x$MESA_LLVM" = x1; then
@@ -1836,12 +1826,14 @@ if test "x$with_gallium_drivers" != x; then
             gallium_check_st "i915/drm" "dri-i915" "xorg-i915"
             ;;
         xr300)
+            HAVE_GALLIUM_R300=yes
             PKG_CHECK_MODULES([RADEON], [libdrm_radeon >= $LIBDRM_RADEON_REQUIRED])
             gallium_require_llvm "Gallium R300"
             GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
             gallium_check_st "radeon/drm" "dri-r300" "xorg-r300" "" "xvmc-r300" "vdpau-r300"
             ;;
         xr600)
+            HAVE_GALLIUM_R600=yes
             PKG_CHECK_MODULES([RADEON], [libdrm_radeon >= $LIBDRM_RADEON_REQUIRED])
             gallium_require_drm_loader
             GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r600"
@@ -1858,6 +1850,7 @@ if test "x$with_gallium_drivers" != x; then
             gallium_check_st "radeon/drm" "dri-r600" "xorg-r600" "" "xvmc-r600" "vdpau-r600"
             ;;
         xradeonsi)
+            HAVE_GALLIUM_RADEONSI=yes
             PKG_CHECK_MODULES([RADEON], [libdrm_radeon >= $LIBDRM_RADEON_REQUIRED])
             gallium_require_drm_loader
             GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS radeonsi"
@@ -1866,14 +1859,17 @@ if test "x$with_gallium_drivers" != x; then
             gallium_check_st "radeon/drm" "dri-radeonsi" "xorg-radeonsi" "" "" "vdpau-radeonsi" ""
             ;;
         xnouveau)
+            HAVE_GALLIUM_NOUVEAU=yes
             PKG_CHECK_MODULES([NOUVEAU], [libdrm_nouveau >= $LIBDRM_NOUVEAU_REQUIRED])
             gallium_require_drm_loader
             GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nv30 nv50 nvc0"
             gallium_check_st "nouveau/drm" "dri-nouveau" "xorg-nouveau" "" "xvmc-nouveau" "vdpau-nouveau"
             ;;
         xswrast)
+            HAVE_GALLIUM_SOFTPIPE=yes
             GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS softpipe"
             if test "x$MESA_LLVM" = x1; then
+                HAVE_GALLIUM_LLVMPIPE=yes
                 GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe"
             fi
 
@@ -1899,16 +1895,24 @@ if test "x$with_gallium_drivers" != x; then
         esac
     done
 fi
+AM_CONDITIONAL(HAVE_GALLIUM_SVGA, test "x$HAVE_GALLIUM_SVGA" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_I915, test "x$HAVE_GALLIUM_I915" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_R300, test "x$HAVE_GALLIUM_R300" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_R600, test "x$HAVE_GALLIUM_R600" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_RADEONSI, test "x$HAVE_GALLIUM_RADEONSI" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_NOUVEAU, test "x$HAVE_GALLIUM_NOUVEAU" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_SOFTPIPE, test "x$HAVE_GALLIUM_SOFTPIPE" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_LLVMPIPE, test "x$HAVE_GALLIUM_LLVMPIPE" = xyes)
 
 if test "x$enable_gallium_loader" = xyes; then
     GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/null"
     GALLIUM_PIPE_LOADER_DEFINES="-DHAVE_PIPE_LOADER_SW"
-    GALLIUM_PIPE_LOADER_LIBS="\$(TOP)/src/gallium/auxiliary/pipe-loader/libpipe_loader.a"
-    GALLIUM_PIPE_LOADER_LIBS="$GALLIUM_PIPE_LOADER_LIBS \$(TOP)/src/gallium/winsys/sw/null/libws_null.a"
+    GALLIUM_PIPE_LOADER_LIBS="\$(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la"
+    GALLIUM_PIPE_LOADER_LIBS="$GALLIUM_PIPE_LOADER_LIBS \$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la"
 
     if test "x$HAVE_WINSYS_XLIB" = xyes; then
         GALLIUM_PIPE_LOADER_DEFINES="$GALLIUM_PIPE_LOADER_DEFINES -DHAVE_PIPE_LOADER_XLIB"
-        GALLIUM_PIPE_LOADER_LIBS="$GALLIUM_PIPE_LOADER_LIBS \$(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a"
+        GALLIUM_PIPE_LOADER_LIBS="$GALLIUM_PIPE_LOADER_LIBS \$(top_builddir)/src/gallium/winsys/sw/xlib/libws_xlib.la"
     fi
 
     if test "x$enable_gallium_drm_loader" = xyes; then
@@ -1951,14 +1955,31 @@ AM_CONDITIONAL(USE_R600_LLVM_COMPILER, test x$USE_R600_LLVM_COMPILER = xyes)
 AM_CONDITIONAL(HAVE_LOADER_GALLIUM, test x$enable_gallium_loader = xyes)
 AM_CONDITIONAL(HAVE_DRM_LOADER_GALLIUM, test x$enable_gallium_drm_loader = xyes)
 AM_CONDITIONAL(HAVE_GALLIUM_COMPUTE, test x$enable_opencl = xyes)
+AM_CONDITIONAL(HAVE_MESA_LLVM, test x$MESA_LLVM = x1)
+AM_CONDITIONAL(LLVM_NEEDS_FNORTTI, test $LLVM_VERSION_INT -ge 302)
+
 AC_SUBST([GALLIUM_MAKE_DIRS])
 
+AM_CONDITIONAL(NEED_LIBPROGRAM, test "x$with_gallium_drivers" != x -o \
+                                     "x$enable_xlib_glx" = xyes -o \
+                                     "x$enable_osmesa" = xyes)
 AM_CONDITIONAL(HAVE_X11_DRIVER, echo "$DRIVER_DIRS" | grep 'x11' >/dev/null 2>&1)
 
 AM_CONDITIONAL(HAVE_X86_ASM, echo "$DEFINES" | grep 'X86_ASM' >/dev/null 2>&1)
 AM_CONDITIONAL(HAVE_X86_64_ASM, echo "$DEFINES" | grep 'X86_64_ASM' >/dev/null 2>&1)
 AM_CONDITIONAL(HAVE_SPARC_ASM, echo "$DEFINES" | grep 'SPARC_ASM' >/dev/null 2>&1)
 
+AC_SUBST([VDPAU_MAJOR], 1)
+AC_SUBST([VDPAU_MINOR], 0)
+
+AC_SUBST([XVMC_MAJOR], 1)
+AC_SUBST([XVMC_MINOR], 0)
+
+AC_SUBST([XA_MAJOR], 1)
+AC_SUBST([XA_MINOR], 0)
+AC_SUBST([XA_TINY], 0)
+AC_SUBST([XA_VERSION], "$XA_MAJOR.$XA_MINOR.$XA_TINY")
+
 dnl prepend CORE_DIRS to SRC_DIRS
 SRC_DIRS="$CORE_DIRS $SRC_DIRS"
 
@@ -1971,8 +1992,7 @@ CFLAGS="$CFLAGS $USER_CFLAGS"
 CXXFLAGS="$CXXFLAGS $USER_CXXFLAGS"
 
 dnl Substitute the config
-AC_CONFIG_FILES([configs/current
-		Makefile
+AC_CONFIG_FILES([Makefile
 		src/Makefile
 		src/egl/Makefile
 		src/egl/drivers/Makefile
@@ -1985,12 +2005,80 @@ AC_CONFIG_FILES([configs/current
 		src/egl/wayland/wayland-egl/Makefile
 		src/egl/wayland/wayland-egl/wayland-egl.pc
 		src/gallium/Makefile
+		src/gallium/auxiliary/Makefile
 		src/gallium/auxiliary/pipe-loader/Makefile
 		src/gallium/drivers/Makefile
+		src/gallium/drivers/i915/Makefile
+		src/gallium/drivers/llvmpipe/Makefile
+		src/gallium/drivers/nouveau/Makefile
+		src/gallium/drivers/nv30/Makefile
+		src/gallium/drivers/nv50/Makefile
+		src/gallium/drivers/nvc0/Makefile
 		src/gallium/drivers/r300/Makefile
 		src/gallium/drivers/r600/Makefile
+		src/gallium/drivers/radeon/Makefile
+		src/gallium/drivers/radeonsi/Makefile
+		src/gallium/drivers/rbug/Makefile
+		src/gallium/drivers/softpipe/Makefile
+		src/gallium/drivers/svga/Makefile
+		src/gallium/drivers/trace/Makefile
+		src/gallium/state_trackers/Makefile
 		src/gallium/state_trackers/clover/Makefile
+		src/gallium/state_trackers/dri/Makefile
+		src/gallium/state_trackers/dri/drm/Makefile
+		src/gallium/state_trackers/dri/sw/Makefile
+		src/gallium/state_trackers/egl/Makefile
+		src/gallium/state_trackers/gbm/Makefile
+		src/gallium/state_trackers/glx/Makefile
+		src/gallium/state_trackers/vdpau/Makefile
+		src/gallium/state_trackers/vega/Makefile
+		src/gallium/state_trackers/xa/Makefile
+		src/gallium/state_trackers/xorg/Makefile
+		src/gallium/state_trackers/xvmc/Makefile
+		src/gallium/targets/Makefile
+		src/gallium/targets/dri-i915/Makefile
+		src/gallium/targets/dri-nouveau/Makefile
+		src/gallium/targets/dri-r300/Makefile
+		src/gallium/targets/dri-r600/Makefile
+		src/gallium/targets/dri-radeonsi/Makefile
+		src/gallium/targets/dri-swrast/Makefile
+		src/gallium/targets/dri-vmwgfx/Makefile
+		src/gallium/targets/egl-static/Makefile
+		src/gallium/targets/gbm/Makefile
 		src/gallium/targets/opencl/Makefile
+		src/gallium/targets/pipe-loader/Makefile
+		src/gallium/targets/libgl-xlib/Makefile
+		src/gallium/targets/vdpau-nouveau/Makefile
+		src/gallium/targets/vdpau-r300/Makefile
+		src/gallium/targets/vdpau-r600/Makefile
+		src/gallium/targets/vdpau-radeonsi/Makefile
+		src/gallium/targets/vdpau-softpipe/Makefile
+		src/gallium/targets/xa-vmwgfx/Makefile
+		src/gallium/targets/xa-vmwgfx/xatracker.pc
+		src/gallium/targets/xorg-i915/Makefile
+		src/gallium/targets/xorg-nouveau/Makefile
+		src/gallium/targets/xorg-r300/Makefile
+		src/gallium/targets/xorg-r600/Makefile
+		src/gallium/targets/xorg-radeonsi/Makefile
+		src/gallium/targets/xvmc-nouveau/Makefile
+		src/gallium/targets/xvmc-r300/Makefile
+		src/gallium/targets/xvmc-r600/Makefile
+		src/gallium/targets/xvmc-softpipe/Makefile
+		src/gallium/tests/trivial/Makefile
+		src/gallium/tests/unit/Makefile
+		src/gallium/winsys/Makefile
+		src/gallium/winsys/i915/drm/Makefile
+		src/gallium/winsys/i915/sw/Makefile
+		src/gallium/winsys/nouveau/drm/Makefile
+		src/gallium/winsys/radeon/drm/Makefile
+		src/gallium/winsys/svga/drm/Makefile
+		src/gallium/winsys/sw/Makefile
+		src/gallium/winsys/sw/dri/Makefile
+		src/gallium/winsys/sw/fbdev/Makefile
+		src/gallium/winsys/sw/null/Makefile
+		src/gallium/winsys/sw/wayland/Makefile
+		src/gallium/winsys/sw/wrapper/Makefile
+		src/gallium/winsys/sw/xlib/Makefile
 		src/gbm/Makefile
 		src/gbm/main/gbm.pc
 		src/glsl/Makefile
@@ -2139,9 +2227,9 @@ echo "        Shared-glapi:    $enable_shared_glapi"
 
 dnl Compiler options
 # cleanup the CFLAGS/CXXFLAGS/DEFINES vars
-cflags=`echo $CFLAGS $PIC_FLAGS | \
+cflags=`echo $CFLAGS | \
     $SED 's/^ *//;s/  */ /;s/ *$//'`
-cxxflags=`echo $CXXFLAGS $PIC_FLAGS | \
+cxxflags=`echo $CXXFLAGS | \
     $SED 's/^ *//;s/  */ /;s/ *$//'`
 defines=`echo $DEFINES | $SED 's/^ *//;s/  */ /;s/ *$//'`
 echo ""
diff --git a/mesalib/docs/devinfo.html b/mesalib/docs/devinfo.html
index 8f4aeef5f..15a885fcf 100644
--- a/mesalib/docs/devinfo.html
+++ b/mesalib/docs/devinfo.html
@@ -196,8 +196,6 @@ branch is relevant.
 <h3>Verify and update version info</h3>
 
 <dl>
-  <dt>configs/default</dt>
-  <dd>MESA_MAJOR, MESA_MINOR and MESA_TINY</dd>
   <dt>Makefile.am</dt>
   <dd>PACKAGE_VERSION</dd>
   <dt>configure.ac</dt>
diff --git a/mesalib/src/.gitignore b/mesalib/src/.gitignore
deleted file mode 100644
index ddfb40586..000000000
--- a/mesalib/src/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/Makefile
-*.trs
-*.log
diff --git a/mesalib/src/gallium/.gitignore b/mesalib/src/gallium/.gitignore
deleted file mode 100644
index 5fc607b9e..000000000
--- a/mesalib/src/gallium/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/Makefile
diff --git a/mesalib/src/gallium/Automake.inc b/mesalib/src/gallium/Automake.inc
new file mode 100644
index 000000000..fabc2af9a
--- /dev/null
+++ b/mesalib/src/gallium/Automake.inc
@@ -0,0 +1,5 @@
+GALLIUM_CFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/src/gallium/include \
+	-I$(top_srcdir)/src/gallium/auxiliary \
+	$(DEFINES)
diff --git a/mesalib/src/gallium/Makefile.template b/mesalib/src/gallium/Makefile.template
deleted file mode 100644
index 036c11986..000000000
--- a/mesalib/src/gallium/Makefile.template
+++ /dev/null
@@ -1,73 +0,0 @@
-# src/gallium/Makefile.template
-
-# Template makefile for gallium libraries.
-#
-# Usage:
-#   The minimum that the including makefile needs to define
-#   is TOP, LIBNAME and one of of the *_SOURCES.
-#
-# Optional defines:
-#   LIBRARY_INCLUDES are appended to the list of includes directories.
-#   LIBRARY_DEFINES is not used for makedepend, but for compilation.
-
-### Basic defines ###
-
-OBJECTS = $(C_SOURCES:.c=.o) \
-	$(CPP_SOURCES:.cpp=.o) \
-	$(ASM_SOURCES:.S=.o)
-
-INCLUDES = \
-	-I. \
-	-I$(TOP)/src/gallium/include \
-	-I$(TOP)/src/gallium/auxiliary \
-	-I$(TOP)/src/gallium/drivers \
-	$(LIBRARY_INCLUDES)
-
-ifeq ($(MESA_LLVM),1)
-LIBRARY_DEFINES += $(LLVM_CFLAGS)
-endif
-
-
-##### TARGETS #####
-
-default: depend lib$(LIBNAME).a $(PROGS)
-
-lib$(LIBNAME).a: $(OBJECTS) $(EXTRA_OBJECTS) Makefile $(TOP)/src/gallium/Makefile.template
-	$(MKLIB) -o $(LIBNAME) -static $(OBJECTS) $(EXTRA_OBJECTS)
-
-depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES)
-	rm -f depend
-	touch depend
-	$(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null
-
-$(PROGS): % : %.o $(PROGS_DEPS)
-	$(LD) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group  $(LIBS) -Wl,--end-group
-
-# Emacs tags
-tags:
-	etags `find . -name \*.[ch]` `find $(TOP)/src/gallium/include -name \*.h`
-
-# Remove .o and backup files
-clean:
-	rm -f $(OBJECTS) $(GENERATED_SOURCES) $(PROGS) lib$(LIBNAME).a depend depend.bak $(CLEAN_EXTRA)
-
-# Dummy target
-install:
-	@echo -n ""
-
-##### RULES #####
-
-%.s: %.c
-	$(CC) -S $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@
-
-%.o: %.c
-	$(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@
-
-%.o: %.cpp
-	$(CXX) -c $(INCLUDES) $(CXXFLAGS) $(LIBRARY_DEFINES) $< -o $@
-
-%.o: %.S
-	$(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES)  $< -o $@
-
-
-sinclude depend
diff --git a/mesalib/src/gallium/auxiliary/Makefile b/mesalib/src/gallium/auxiliary/Makefile
deleted file mode 100644
index 72208f1a7..000000000
--- a/mesalib/src/gallium/auxiliary/Makefile
+++ /dev/null
@@ -1,47 +0,0 @@
-TOP = ../../..
-include $(TOP)/configs/current
-
-LIBNAME = gallium
-
-# get source lists
-include Makefile.sources
-
-C_SOURCES += $(GENERATED_SOURCES)
-
-ifeq ($(MESA_LLVM),1)
-C_SOURCES += \
-	$(GALLIVM_SOURCES)
-CPP_SOURCES += \
-	$(GALLIVM_CPP_SOURCES)
-
-# LLVM >= 3.2 requires -fno-rtti
-ifeq ($(shell expr `echo $(LLVM_VERSION) | sed -e 's/\([0-9]\)\.\([0-9]\)/\10\2/g'` \>= 302),1)
-CXXFLAGS += -fno-rtti
-endif
-endif
-
-
-include ../Makefile.template
-
-default install clean: %: subdirs-%
-
-subdirs-%:
-	@for dir in $(SUBDIRS) ; do \
-		if [ -d $$dir ] ; then \
-			(cd $$dir && $(MAKE) $*) || exit 1; \
-		fi \
-	done
-
-indices/u_indices_gen.c: indices/u_indices_gen.py
-	$(PYTHON2) $< > $@
-
-indices/u_unfilled_gen.c: indices/u_unfilled_gen.py
-	$(PYTHON2) $< > $@
-
-util/u_format_srgb.c: util/u_format_srgb.py
-	$(PYTHON2) $< > $@
-
-util/u_format_table.c: util/u_format_table.py util/u_format_pack.py util/u_format_parse.py util/u_format.csv
-	$(PYTHON2) util/u_format_table.py util/u_format.csv > $@
-
-# DO NOT DELETE
diff --git a/mesalib/src/gallium/auxiliary/Makefile.am b/mesalib/src/gallium/auxiliary/Makefile.am
new file mode 100644
index 000000000..b8ac7c9dd
--- /dev/null
+++ b/mesalib/src/gallium/auxiliary/Makefile.am
@@ -0,0 +1,51 @@
+AUTOMAKE_OPTIONS = subdir-objects
+
+include Makefile.sources
+include $(top_srcdir)/src/gallium/Automake.inc
+
+noinst_LTLIBRARIES = libgallium.la
+
+AM_CFLAGS = \
+	-I$(top_srcdir)/src/gallium/auxiliary/util \
+	$(GALLIUM_CFLAGS)
+
+libgallium_la_SOURCES = \
+	$(C_SOURCES) \
+	$(GENERATED_SOURCES)
+
+if HAVE_MESA_LLVM
+
+AM_CFLAGS += \
+	$(LLVM_CFLAGS)
+
+AM_CXXFLAGS = \
+	$(GALLIUM_CFLAGS) \
+	$(LLVM_CXXFLAGS)
+
+if LLVM_NEEDS_FNORTTI
+
+AM_CXXFLAGS += -fno-rtti
+
+endif
+
+libgallium_la_SOURCES += \
+	$(GALLIVM_SOURCES) \
+	$(GALLIVM_CPP_SOURCES)
+
+endif
+
+indices/u_indices_gen.c: $(srcdir)/indices/u_indices_gen.py
+	$(AM_V_GEN) $(PYTHON2) $< > $@
+
+indices/u_unfilled_gen.c: $(srcdir)/indices/u_unfilled_gen.py
+	$(AM_V_GEN) $(PYTHON2) $< > $@
+
+util/u_format_srgb.c: $(srcdir)/util/u_format_srgb.py
+	$(AM_V_GEN) $(PYTHON2) $< > $@
+
+util/u_format_table.c: $(srcdir)/util/u_format_table.py $(srcdir)/util/u_format_pack.py $(srcdir)/util/u_format_parse.py $(srcdir)/util/u_format.csv
+	$(AM_V_GEN) $(PYTHON2) $(srcdir)/util/u_format_table.py $(srcdir)/util/u_format.csv > $@
+
+#XXX: Delete this when all targets are converted to automake.
+all-local: libgallium.la
+	ln -f $(builddir)/.libs/libgallium.a $(builddir)/libgallium.a
diff --git a/mesalib/src/gallium/auxiliary/util/u_pack_color.h b/mesalib/src/gallium/auxiliary/util/u_pack_color.h
index 50ec226d8..6c6d9669c 100644
--- a/mesalib/src/gallium/auxiliary/util/u_pack_color.h
+++ b/mesalib/src/gallium/auxiliary/util/u_pack_color.h
@@ -329,6 +329,8 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
 
 /**
  * Note rgba outside [0,1] will be clamped for int pixel formats.
+ * This will not work (and might not really be useful with float input)
+ * for pure integer formats (which lack the pack_rgba_float function).
  */
 static INLINE void
 util_pack_color(const float rgba[4], enum pipe_format format, union util_color *uc)
diff --git a/mesalib/src/glsl/.gitignore b/mesalib/src/glsl/.gitignore
index 068d4874b..4eb4fef9b 100644
--- a/mesalib/src/glsl/.gitignore
+++ b/mesalib/src/glsl/.gitignore
@@ -5,4 +5,3 @@ glsl_parser.h
 glsl_parser.output
 builtin_function.cpp
 glsl_test
-/Makefile
diff --git a/mesalib/src/glsl/Makefile.sources b/mesalib/src/glsl/Makefile.sources
index d984c5ca7..2227c5ef5 100644
--- a/mesalib/src/glsl/Makefile.sources
+++ b/mesalib/src/glsl/Makefile.sources
@@ -46,6 +46,7 @@ LIBGLSL_FILES = \
 	$(GLSL_SRCDIR)/link_functions.cpp \
 	$(GLSL_SRCDIR)/link_uniforms.cpp \
 	$(GLSL_SRCDIR)/link_uniform_initializers.cpp \
+	$(GLSL_SRCDIR)/link_varyings.cpp \
 	$(GLSL_SRCDIR)/loop_analysis.cpp \
 	$(GLSL_SRCDIR)/loop_controls.cpp \
 	$(GLSL_SRCDIR)/loop_unroll.cpp \
diff --git a/mesalib/src/glsl/Makefile.template b/mesalib/src/glsl/Makefile.template
deleted file mode 100644
index 974987a0a..000000000
--- a/mesalib/src/glsl/Makefile.template
+++ /dev/null
@@ -1,50 +0,0 @@
-# src/glsl/Makefile.template
-
-# Template makefile for glsl libraries.
-#
-# Usage:
-#   The minimum that the including makefile needs to define
-#   is TOP, LIBNAME and one of of the *_SOURCES.
-#
-# Optional defines:
-#   LIBRARY_INCLUDES are appended to the list of includes directories.
-#   LIBRARY_DEFINES is not used for makedepend, but for compilation.
-
-
-### Basic defines ###
-
-OBJECTS = $(C_SOURCES:.c=.o)
-
-INCLUDES = \
-	-I. \
-	$(LIBRARY_INCLUDES)
-
-
-##### TARGETS #####
-
-default: depend lib$(LIBNAME).a
-
-lib$(LIBNAME).a: $(OBJECTS) Makefile $(TOP)/src/glsl/Makefile.template
-	$(MKLIB) -o $(LIBNAME) -static $(OBJECTS)
-
-depend: $(C_SOURCES)
-	rm -f depend
-	touch depend
-	$(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) 2> /dev/null
-
-# Remove .o and backup files
-clean:
-	rm -f $(OBJECTS) lib$(LIBNAME).a depend depend.bak
-
-# Dummy target
-install:
-	@echo -n ""
-
-
-##### RULES #####
-
-.c.o:
-	$(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@
-
--include depend
-
diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp
index 94b63f682..f934c8e2d 100644
--- a/mesalib/src/glsl/ast_to_hir.cpp
+++ b/mesalib/src/glsl/ast_to_hir.cpp
@@ -1910,12 +1910,36 @@ ast_type_specifier::glsl_type(const char **name,
 }
 
 
+/**
+ * Determine whether a toplevel variable declaration declares a varying.  This
+ * function operates by examining the variable's mode and the shader target,
+ * so it correctly identifies linkage variables regardless of whether they are
+ * declared using the deprecated "varying" syntax or the new "in/out" syntax.
+ *
+ * Passing a non-toplevel variable declaration (e.g. a function parameter) to
+ * this function will produce undefined results.
+ */
+static bool
+is_varying_var(ir_variable *var, _mesa_glsl_parser_targets target)
+{
+   switch (target) {
+   case vertex_shader:
+      return var->mode == ir_var_out;
+   case fragment_shader:
+      return var->mode == ir_var_in;
+   default:
+      return var->mode == ir_var_out || var->mode == ir_var_in;
+   }
+}
+
+
 static void
 apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
 				 ir_variable *var,
 				 struct _mesa_glsl_parse_state *state,
 				 YYLTYPE *loc,
-				 bool ubo_qualifiers_valid)
+				 bool ubo_qualifiers_valid,
+                                 bool is_parameter)
 {
    if (qual->flags.q.invariant) {
       if (var->used) {
@@ -1944,27 +1968,6 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
 		       _mesa_glsl_shader_target_name(state->target));
    }
 
-   /* From page 25 (page 31 of the PDF) of the GLSL 1.10 spec:
-    *
-    *     "The varying qualifier can be used only with the data types
-    *     float, vec2, vec3, vec4, mat2, mat3, and mat4, or arrays of
-    *     these."
-    */
-   if (qual->flags.q.varying) {
-      const glsl_type *non_array_type;
-
-      if (var->type && var->type->is_array())
-	 non_array_type = var->type->fields.array;
-      else
-	 non_array_type = var->type;
-
-      if (non_array_type && non_array_type->base_type != GLSL_TYPE_FLOAT) {
-	 var->type = glsl_type::error_type;
-	 _mesa_glsl_error(loc, state,
-			  "varying variables must be of base type float");
-      }
-   }
-
    /* If there is no qualifier that changes the mode of the variable, leave
     * the setting alone.
     */
@@ -1979,6 +1982,54 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
    else if (qual->flags.q.uniform)
       var->mode = ir_var_uniform;
 
+   if (!is_parameter && is_varying_var(var, state->target)) {
+      /* This variable is being used to link data between shader stages (in
+       * pre-glsl-1.30 parlance, it's a "varying").  Check that it has a type
+       * that is allowed for such purposes.
+       *
+       * From page 25 (page 31 of the PDF) of the GLSL 1.10 spec:
+       *
+       *     "The varying qualifier can be used only with the data types
+       *     float, vec2, vec3, vec4, mat2, mat3, and mat4, or arrays of
+       *     these."
+       *
+       * This was relaxed in GLSL version 1.30 and GLSL ES version 3.00.  From
+       * page 31 (page 37 of the PDF) of the GLSL 1.30 spec:
+       *
+       *     "Fragment inputs can only be signed and unsigned integers and
+       *     integer vectors, float, floating-point vectors, matrices, or
+       *     arrays of these. Structures cannot be input.
+       *
+       * Similar text exists in the section on vertex shader outputs.
+       *
+       * Similar text exists in the GLSL ES 3.00 spec, except that the GLSL ES
+       * 3.00 spec claims to allow structs as well.  However, this is likely
+       * an error, since section 11 of the spec ("Counting of Inputs and
+       * Outputs") enumerates all possible types of interstage linkage
+       * variables, and it does not mention structs.
+       */
+      switch (var->type->get_scalar_type()->base_type) {
+      case GLSL_TYPE_FLOAT:
+         /* Ok in all GLSL versions */
+         break;
+      case GLSL_TYPE_UINT:
+      case GLSL_TYPE_INT:
+         if (state->is_version(130, 300))
+            break;
+         _mesa_glsl_error(loc, state,
+                          "varying variables must be of base type float in %s",
+                          state->get_version_string());
+         break;
+      case GLSL_TYPE_STRUCT:
+         _mesa_glsl_error(loc, state,
+                          "varying variables may not be of type struct");
+         break;
+      default:
+         _mesa_glsl_error(loc, state, "illegal type for a varying variable");
+         break;
+      }
+   }
+
    if (state->all_invariant && (state->current_function == NULL)) {
       switch (state->target) {
       case vertex_shader:
@@ -2626,7 +2677,7 @@ ast_declarator_list::hir(exec_list *instructions,
       }
 
       apply_type_qualifier_to_variable(& this->type->qualifier, var, state,
-				       & loc, this->ubo_qualifiers_valid);
+				       & loc, this->ubo_qualifiers_valid, false);
 
       if (this->type->qualifier.flags.q.invariant) {
 	 if ((state->target == vertex_shader) && !(var->mode == ir_var_out ||
@@ -3065,7 +3116,7 @@ ast_parameter_declarator::hir(exec_list *instructions,
     * for function parameters the default mode is 'in'.
     */
    apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc,
-				    false);
+				    false, true);
 
    /* From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
     *
diff --git a/mesalib/src/glsl/builtin_compiler/.gitignore b/mesalib/src/glsl/builtin_compiler/.gitignore
index 40c551baa..ea7d5de9c 100644
--- a/mesalib/src/glsl/builtin_compiler/.gitignore
+++ b/mesalib/src/glsl/builtin_compiler/.gitignore
@@ -3,4 +3,3 @@ glcpp-lex.c
 glcpp-parse.c
 glcpp-parse.h
 glcpp-parse.output
-/Makefile
diff --git a/mesalib/src/glsl/glcpp/.gitignore b/mesalib/src/glsl/glcpp/.gitignore
index 64033e2aa..01d2888e7 100644
--- a/mesalib/src/glsl/glcpp/.gitignore
+++ b/mesalib/src/glsl/glcpp/.gitignore
@@ -3,5 +3,3 @@ glcpp-lex.c
 glcpp-parse.output
 glcpp-parse.c
 glcpp-parse.h
-tests/*.out
-/Makefile
diff --git a/mesalib/src/glsl/glsl_parser.yy b/mesalib/src/glsl/glsl_parser.yy
index d8494667b..88aae64d4 100644
--- a/mesalib/src/glsl/glsl_parser.yy
+++ b/mesalib/src/glsl/glsl_parser.yy
@@ -1542,7 +1542,6 @@ struct_declarator:
 	   void *ctx = state;
 	   $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
 	   $$->set_location(yylloc);
-	   state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
 	}
 	| any_identifier '[' constant_expression ']'
 	{
diff --git a/mesalib/src/glsl/link_varyings.cpp b/mesalib/src/glsl/link_varyings.cpp
new file mode 100644
index 000000000..5c27f231e
--- /dev/null
+++ b/mesalib/src/glsl/link_varyings.cpp
@@ -0,0 +1,1051 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file link_varyings.cpp
+ *
+ * Linker functions related specifically to linking varyings between shader
+ * stages.
+ */
+
+
+#include "main/mtypes.h"
+#include "glsl_symbol_table.h"
+#include "ir_optimization.h"
+#include "linker.h"
+#include "link_varyings.h"
+#include "main/macros.h"
+
+
+/**
+ * Validate that outputs from one stage match inputs of another
+ */
+bool
+cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
+				 gl_shader *producer, gl_shader *consumer)
+{
+   glsl_symbol_table parameters;
+   /* FINISHME: Figure these out dynamically. */
+   const char *const producer_stage = "vertex";
+   const char *const consumer_stage = "fragment";
+
+   /* Find all shader outputs in the "producer" stage.
+    */
+   foreach_list(node, producer->ir) {
+      ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+      /* FINISHME: For geometry shaders, this should also look for inout
+       * FINISHME: variables.
+       */
+      if ((var == NULL) || (var->mode != ir_var_out))
+	 continue;
+
+      parameters.add_variable(var);
+   }
+
+
+   /* Find all shader inputs in the "consumer" stage.  Any variables that have
+    * matching outputs already in the symbol table must have the same type and
+    * qualifiers.
+    */
+   foreach_list(node, consumer->ir) {
+      ir_variable *const input = ((ir_instruction *) node)->as_variable();
+
+      /* FINISHME: For geometry shaders, this should also look for inout
+       * FINISHME: variables.
+       */
+      if ((input == NULL) || (input->mode != ir_var_in))
+	 continue;
+
+      ir_variable *const output = parameters.get_variable(input->name);
+      if (output != NULL) {
+	 /* Check that the types match between stages.
+	  */
+	 if (input->type != output->type) {
+	    /* There is a bit of a special case for gl_TexCoord.  This
+	     * built-in is unsized by default.  Applications that variable
+	     * access it must redeclare it with a size.  There is some
+	     * language in the GLSL spec that implies the fragment shader
+	     * and vertex shader do not have to agree on this size.  Other
+	     * driver behave this way, and one or two applications seem to
+	     * rely on it.
+	     *
+	     * Neither declaration needs to be modified here because the array
+	     * sizes are fixed later when update_array_sizes is called.
+	     *
+	     * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec:
+	     *
+	     *     "Unlike user-defined varying variables, the built-in
+	     *     varying variables don't have a strict one-to-one
+	     *     correspondence between the vertex language and the
+	     *     fragment language."
+	     */
+	    if (!output->type->is_array()
+		|| (strncmp("gl_", output->name, 3) != 0)) {
+	       linker_error(prog,
+			    "%s shader output `%s' declared as type `%s', "
+			    "but %s shader input declared as type `%s'\n",
+			    producer_stage, output->name,
+			    output->type->name,
+			    consumer_stage, input->type->name);
+	       return false;
+	    }
+	 }
+
+	 /* Check that all of the qualifiers match between stages.
+	  */
+	 if (input->centroid != output->centroid) {
+	    linker_error(prog,
+			 "%s shader output `%s' %s centroid qualifier, "
+			 "but %s shader input %s centroid qualifier\n",
+			 producer_stage,
+			 output->name,
+			 (output->centroid) ? "has" : "lacks",
+			 consumer_stage,
+			 (input->centroid) ? "has" : "lacks");
+	    return false;
+	 }
+
+	 if (input->invariant != output->invariant) {
+	    linker_error(prog,
+			 "%s shader output `%s' %s invariant qualifier, "
+			 "but %s shader input %s invariant qualifier\n",
+			 producer_stage,
+			 output->name,
+			 (output->invariant) ? "has" : "lacks",
+			 consumer_stage,
+			 (input->invariant) ? "has" : "lacks");
+	    return false;
+	 }
+
+	 if (input->interpolation != output->interpolation) {
+	    linker_error(prog,
+			 "%s shader output `%s' specifies %s "
+			 "interpolation qualifier, "
+			 "but %s shader input specifies %s "
+			 "interpolation qualifier\n",
+			 producer_stage,
+			 output->name,
+			 output->interpolation_string(),
+			 consumer_stage,
+			 input->interpolation_string());
+	    return false;
+	 }
+      }
+   }
+
+   return true;
+}
+
+
+/**
+ * Initialize this object based on a string that was passed to
+ * glTransformFeedbackVaryings.  If there is a parse error, the error is
+ * reported using linker_error(), and false is returned.
+ */
+bool
+tfeedback_decl::init(struct gl_context *ctx, struct gl_shader_program *prog,
+                     const void *mem_ctx, const char *input)
+{
+   /* We don't have to be pedantic about what is a valid GLSL variable name,
+    * because any variable with an invalid name can't exist in the IR anyway.
+    */
+
+   this->location = -1;
+   this->orig_name = input;
+   this->is_clip_distance_mesa = false;
+   this->skip_components = 0;
+   this->next_buffer_separator = false;
+
+   if (ctx->Extensions.ARB_transform_feedback3) {
+      /* Parse gl_NextBuffer. */
+      if (strcmp(input, "gl_NextBuffer") == 0) {
+         this->next_buffer_separator = true;
+         return true;
+      }
+
+      /* Parse gl_SkipComponents. */
+      if (strcmp(input, "gl_SkipComponents1") == 0)
+         this->skip_components = 1;
+      else if (strcmp(input, "gl_SkipComponents2") == 0)
+         this->skip_components = 2;
+      else if (strcmp(input, "gl_SkipComponents3") == 0)
+         this->skip_components = 3;
+      else if (strcmp(input, "gl_SkipComponents4") == 0)
+         this->skip_components = 4;
+
+      if (this->skip_components)
+         return true;
+   }
+
+   /* Parse a declaration. */
+   const char *bracket = strrchr(input, '[');
+
+   if (bracket) {
+      this->var_name = ralloc_strndup(mem_ctx, input, bracket - input);
+      if (sscanf(bracket, "[%u]", &this->array_subscript) != 1) {
+         linker_error(prog, "Cannot parse transform feedback varying %s", input);
+         return false;
+      }
+      this->is_subscripted = true;
+   } else {
+      this->var_name = ralloc_strdup(mem_ctx, input);
+      this->is_subscripted = false;
+   }
+
+   /* For drivers that lower gl_ClipDistance to gl_ClipDistanceMESA, this
+    * class must behave specially to account for the fact that gl_ClipDistance
+    * is converted from a float[8] to a vec4[2].
+    */
+   if (ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].LowerClipDistance &&
+       strcmp(this->var_name, "gl_ClipDistance") == 0) {
+      this->is_clip_distance_mesa = true;
+   }
+
+   return true;
+}
+
+
+/**
+ * Determine whether two tfeedback_decl objects refer to the same variable and
+ * array index (if applicable).
+ */
+bool
+tfeedback_decl::is_same(const tfeedback_decl &x, const tfeedback_decl &y)
+{
+   assert(x.is_varying() && y.is_varying());
+
+   if (strcmp(x.var_name, y.var_name) != 0)
+      return false;
+   if (x.is_subscripted != y.is_subscripted)
+      return false;
+   if (x.is_subscripted && x.array_subscript != y.array_subscript)
+      return false;
+   return true;
+}
+
+
+/**
+ * Assign a location for this tfeedback_decl object based on the location
+ * assignment in output_var.
+ *
+ * If an error occurs, the error is reported through linker_error() and false
+ * is returned.
+ */
+bool
+tfeedback_decl::assign_location(struct gl_context *ctx,
+                                struct gl_shader_program *prog,
+                                ir_variable *output_var)
+{
+   assert(this->is_varying());
+
+   if (output_var->type->is_array()) {
+      /* Array variable */
+      const unsigned matrix_cols =
+         output_var->type->fields.array->matrix_columns;
+      const unsigned vector_elements =
+         output_var->type->fields.array->vector_elements;
+      unsigned actual_array_size = this->is_clip_distance_mesa ?
+         prog->Vert.ClipDistanceArraySize : output_var->type->array_size();
+
+      if (this->is_subscripted) {
+         /* Check array bounds. */
+         if (this->array_subscript >= actual_array_size) {
+            linker_error(prog, "Transform feedback varying %s has index "
+                         "%i, but the array size is %u.",
+                         this->orig_name, this->array_subscript,
+                         actual_array_size);
+            return false;
+         }
+         if (this->is_clip_distance_mesa) {
+            this->location =
+               output_var->location + this->array_subscript / 4;
+            this->location_frac = this->array_subscript % 4;
+         } else {
+            unsigned fine_location
+               = output_var->location * 4 + output_var->location_frac;
+            unsigned array_elem_size = vector_elements * matrix_cols;
+            fine_location += array_elem_size * this->array_subscript;
+            this->location = fine_location / 4;
+            this->location_frac = fine_location % 4;
+         }
+         this->size = 1;
+      } else {
+         this->location = output_var->location;
+         this->location_frac = output_var->location_frac;
+         this->size = actual_array_size;
+      }
+      this->vector_elements = vector_elements;
+      this->matrix_columns = matrix_cols;
+      if (this->is_clip_distance_mesa)
+         this->type = GL_FLOAT;
+      else
+         this->type = output_var->type->fields.array->gl_type;
+   } else {
+      /* Regular variable (scalar, vector, or matrix) */
+      if (this->is_subscripted) {
+         linker_error(prog, "Transform feedback varying %s requested, "
+                      "but %s is not an array.",
+                      this->orig_name, this->var_name);
+         return false;
+      }
+      this->location = output_var->location;
+      this->location_frac = output_var->location_frac;
+      this->size = 1;
+      this->vector_elements = output_var->type->vector_elements;
+      this->matrix_columns = output_var->type->matrix_columns;
+      this->type = output_var->type->gl_type;
+   }
+
+   /* From GL_EXT_transform_feedback:
+    *   A program will fail to link if:
+    *
+    *   * the total number of components to capture in any varying
+    *     variable in <varyings> is greater than the constant
+    *     MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT and the
+    *     buffer mode is SEPARATE_ATTRIBS_EXT;
+    */
+   if (prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS &&
+       this->num_components() >
+       ctx->Const.MaxTransformFeedbackSeparateComponents) {
+      linker_error(prog, "Transform feedback varying %s exceeds "
+                   "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS.",
+                   this->orig_name);
+      return false;
+   }
+
+   return true;
+}
+
+
+unsigned
+tfeedback_decl::get_num_outputs() const
+{
+   if (!this->is_varying()) {
+      return 0;
+   }
+
+   return (this->num_components() + this->location_frac + 3)/4;
+}
+
+
+/**
+ * Update gl_transform_feedback_info to reflect this tfeedback_decl.
+ *
+ * If an error occurs, the error is reported through linker_error() and false
+ * is returned.
+ */
+bool
+tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
+                      struct gl_transform_feedback_info *info,
+                      unsigned buffer, const unsigned max_outputs) const
+{
+   assert(!this->next_buffer_separator);
+
+   /* Handle gl_SkipComponents. */
+   if (this->skip_components) {
+      info->BufferStride[buffer] += this->skip_components;
+      return true;
+   }
+
+   /* From GL_EXT_transform_feedback:
+    *   A program will fail to link if:
+    *
+    *     * the total number of components to capture is greater than
+    *       the constant MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT
+    *       and the buffer mode is INTERLEAVED_ATTRIBS_EXT.
+    */
+   if (prog->TransformFeedback.BufferMode == GL_INTERLEAVED_ATTRIBS &&
+       info->BufferStride[buffer] + this->num_components() >
+       ctx->Const.MaxTransformFeedbackInterleavedComponents) {
+      linker_error(prog, "The MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS "
+                   "limit has been exceeded.");
+      return false;
+   }
+
+   unsigned location = this->location;
+   unsigned location_frac = this->location_frac;
+   unsigned num_components = this->num_components();
+   while (num_components > 0) {
+      unsigned output_size = MIN2(num_components, 4 - location_frac);
+      assert(info->NumOutputs < max_outputs);
+      info->Outputs[info->NumOutputs].ComponentOffset = location_frac;
+      info->Outputs[info->NumOutputs].OutputRegister = location;
+      info->Outputs[info->NumOutputs].NumComponents = output_size;
+      info->Outputs[info->NumOutputs].OutputBuffer = buffer;
+      info->Outputs[info->NumOutputs].DstOffset = info->BufferStride[buffer];
+      ++info->NumOutputs;
+      info->BufferStride[buffer] += output_size;
+      num_components -= output_size;
+      location++;
+      location_frac = 0;
+   }
+
+   info->Varyings[info->NumVarying].Name = ralloc_strdup(prog, this->orig_name);
+   info->Varyings[info->NumVarying].Type = this->type;
+   info->Varyings[info->NumVarying].Size = this->size;
+   info->NumVarying++;
+
+   return true;
+}
+
+
+ir_variable *
+tfeedback_decl::find_output_var(gl_shader_program *prog,
+                                gl_shader *producer) const
+{
+   const char *name = this->is_clip_distance_mesa
+      ? "gl_ClipDistanceMESA" : this->var_name;
+   ir_variable *var = producer->symbols->get_variable(name);
+   if (var && var->mode == ir_var_out)
+      return var;
+
+   /* From GL_EXT_transform_feedback:
+    *   A program will fail to link if:
+    *
+    *   * any variable name specified in the <varyings> array is not
+    *     declared as an output in the geometry shader (if present) or
+    *     the vertex shader (if no geometry shader is present);
+    */
+   linker_error(prog, "Transform feedback varying %s undeclared.",
+                this->orig_name);
+   return NULL;
+}
+
+
+/**
+ * Parse all the transform feedback declarations that were passed to
+ * glTransformFeedbackVaryings() and store them in tfeedback_decl objects.
+ *
+ * If an error occurs, the error is reported through linker_error() and false
+ * is returned.
+ */
+bool
+parse_tfeedback_decls(struct gl_context *ctx, struct gl_shader_program *prog,
+                      const void *mem_ctx, unsigned num_names,
+                      char **varying_names, tfeedback_decl *decls)
+{
+   for (unsigned i = 0; i < num_names; ++i) {
+      if (!decls[i].init(ctx, prog, mem_ctx, varying_names[i]))
+         return false;
+
+      if (!decls[i].is_varying())
+         continue;
+
+      /* From GL_EXT_transform_feedback:
+       *   A program will fail to link if:
+       *
+       *   * any two entries in the <varyings> array specify the same varying
+       *     variable;
+       *
+       * We interpret this to mean "any two entries in the <varyings> array
+       * specify the same varying variable and array index", since transform
+       * feedback of arrays would be useless otherwise.
+       */
+      for (unsigned j = 0; j < i; ++j) {
+         if (!decls[j].is_varying())
+            continue;
+
+         if (tfeedback_decl::is_same(decls[i], decls[j])) {
+            linker_error(prog, "Transform feedback varying %s specified "
+                         "more than once.", varying_names[i]);
+            return false;
+         }
+      }
+   }
+   return true;
+}
+
+
+/**
+ * Store transform feedback location assignments into
+ * prog->LinkedTransformFeedback based on the data stored in tfeedback_decls.
+ *
+ * If an error occurs, the error is reported through linker_error() and false
+ * is returned.
+ */
+bool
+store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
+                     unsigned num_tfeedback_decls,
+                     tfeedback_decl *tfeedback_decls)
+{
+   bool separate_attribs_mode =
+      prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS;
+
+   ralloc_free(prog->LinkedTransformFeedback.Varyings);
+   ralloc_free(prog->LinkedTransformFeedback.Outputs);
+
+   memset(&prog->LinkedTransformFeedback, 0,
+          sizeof(prog->LinkedTransformFeedback));
+
+   prog->LinkedTransformFeedback.Varyings =
+      rzalloc_array(prog,
+		    struct gl_transform_feedback_varying_info,
+		    num_tfeedback_decls);
+
+   unsigned num_outputs = 0;
+   for (unsigned i = 0; i < num_tfeedback_decls; ++i)
+      num_outputs += tfeedback_decls[i].get_num_outputs();
+
+   prog->LinkedTransformFeedback.Outputs =
+      rzalloc_array(prog,
+                    struct gl_transform_feedback_output,
+                    num_outputs);
+
+   unsigned num_buffers = 0;
+
+   if (separate_attribs_mode) {
+      /* GL_SEPARATE_ATTRIBS */
+      for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
+         if (!tfeedback_decls[i].store(ctx, prog, &prog->LinkedTransformFeedback,
+                                       num_buffers, num_outputs))
+            return false;
+
+         num_buffers++;
+      }
+   }
+   else {
+      /* GL_INVERLEAVED_ATTRIBS */
+      for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
+         if (tfeedback_decls[i].is_next_buffer_separator()) {
+            num_buffers++;
+            continue;
+         }
+
+         if (!tfeedback_decls[i].store(ctx, prog,
+                                       &prog->LinkedTransformFeedback,
+                                       num_buffers, num_outputs))
+            return false;
+      }
+      num_buffers++;
+   }
+
+   assert(prog->LinkedTransformFeedback.NumOutputs == num_outputs);
+
+   prog->LinkedTransformFeedback.NumBuffers = num_buffers;
+   return true;
+}
+
+
+/**
+ * Data structure recording the relationship between outputs of one shader
+ * stage (the "producer") and inputs of another (the "consumer").
+ */
+class varying_matches
+{
+public:
+   varying_matches(bool disable_varying_packing);
+   ~varying_matches();
+   void record(ir_variable *producer_var, ir_variable *consumer_var);
+   unsigned assign_locations();
+   void store_locations(unsigned producer_base, unsigned consumer_base) const;
+
+private:
+   /**
+    * If true, this driver disables varying packing, so all varyings need to
+    * be aligned on slot boundaries, and take up a number of slots equal to
+    * their number of matrix columns times their array size.
+    */
+   const bool disable_varying_packing;
+
+   /**
+    * Enum representing the order in which varyings are packed within a
+    * packing class.
+    *
+    * Currently we pack vec4's first, then vec2's, then scalar values, then
+    * vec3's.  This order ensures that the only vectors that are at risk of
+    * having to be "double parked" (split between two adjacent varying slots)
+    * are the vec3's.
+    */
+   enum packing_order_enum {
+      PACKING_ORDER_VEC4,
+      PACKING_ORDER_VEC2,
+      PACKING_ORDER_SCALAR,
+      PACKING_ORDER_VEC3,
+   };
+
+   static unsigned compute_packing_class(ir_variable *var);
+   static packing_order_enum compute_packing_order(ir_variable *var);
+   static int match_comparator(const void *x_generic, const void *y_generic);
+
+   /**
+    * Structure recording the relationship between a single producer output
+    * and a single consumer input.
+    */
+   struct match {
+      /**
+       * Packing class for this varying, computed by compute_packing_class().
+       */
+      unsigned packing_class;
+
+      /**
+       * Packing order for this varying, computed by compute_packing_order().
+       */
+      packing_order_enum packing_order;
+      unsigned num_components;
+
+      /**
+       * The output variable in the producer stage.
+       */
+      ir_variable *producer_var;
+
+      /**
+       * The input variable in the consumer stage.
+       */
+      ir_variable *consumer_var;
+
+      /**
+       * The location which has been assigned for this varying.  This is
+       * expressed in multiples of a float, with the first generic varying
+       * (i.e. the one referred to by VERT_RESULT_VAR0 or FRAG_ATTRIB_VAR0)
+       * represented by the value 0.
+       */
+      unsigned generic_location;
+   } *matches;
+
+   /**
+    * The number of elements in the \c matches array that are currently in
+    * use.
+    */
+   unsigned num_matches;
+
+   /**
+    * The number of elements that were set aside for the \c matches array when
+    * it was allocated.
+    */
+   unsigned matches_capacity;
+};
+
+
+varying_matches::varying_matches(bool disable_varying_packing)
+   : disable_varying_packing(disable_varying_packing)
+{
+   /* Note: this initial capacity is rather arbitrarily chosen to be large
+    * enough for many cases without wasting an unreasonable amount of space.
+    * varying_matches::record() will resize the array if there are more than
+    * this number of varyings.
+    */
+   this->matches_capacity = 8;
+   this->matches = (match *)
+      malloc(sizeof(*this->matches) * this->matches_capacity);
+   this->num_matches = 0;
+}
+
+
+varying_matches::~varying_matches()
+{
+   free(this->matches);
+}
+
+
+/**
+ * Record the given producer/consumer variable pair in the list of variables
+ * that should later be assigned locations.
+ *
+ * It is permissible for \c consumer_var to be NULL (this happens if a
+ * variable is output by the producer and consumed by transform feedback, but
+ * not consumed by the consumer).
+ *
+ * If \c producer_var has already been paired up with a consumer_var, or
+ * producer_var is part of fixed pipeline functionality (and hence already has
+ * a location assigned), this function has no effect.
+ */
+void
+varying_matches::record(ir_variable *producer_var, ir_variable *consumer_var)
+{
+   if (!producer_var->is_unmatched_generic_inout) {
+      /* Either a location already exists for this variable (since it is part
+       * of fixed functionality), or it has already been recorded as part of a
+       * previous match.
+       */
+      return;
+   }
+
+   if (this->num_matches == this->matches_capacity) {
+      this->matches_capacity *= 2;
+      this->matches = (match *)
+         realloc(this->matches,
+                 sizeof(*this->matches) * this->matches_capacity);
+   }
+   this->matches[this->num_matches].packing_class
+      = this->compute_packing_class(producer_var);
+   this->matches[this->num_matches].packing_order
+      = this->compute_packing_order(producer_var);
+   if (this->disable_varying_packing) {
+      unsigned slots = producer_var->type->is_array()
+         ? (producer_var->type->length
+            * producer_var->type->fields.array->matrix_columns)
+         : producer_var->type->matrix_columns;
+      this->matches[this->num_matches].num_components = 4 * slots;
+   } else {
+      this->matches[this->num_matches].num_components
+         = producer_var->type->component_slots();
+   }
+   this->matches[this->num_matches].producer_var = producer_var;
+   this->matches[this->num_matches].consumer_var = consumer_var;
+   this->num_matches++;
+   producer_var->is_unmatched_generic_inout = 0;
+   if (consumer_var)
+      consumer_var->is_unmatched_generic_inout = 0;
+}
+
+
+/**
+ * Choose locations for all of the variable matches that were previously
+ * passed to varying_matches::record().
+ */
+unsigned
+varying_matches::assign_locations()
+{
+   /* Sort varying matches into an order that makes them easy to pack. */
+   qsort(this->matches, this->num_matches, sizeof(*this->matches),
+         &varying_matches::match_comparator);
+
+   unsigned generic_location = 0;
+
+   for (unsigned i = 0; i < this->num_matches; i++) {
+      /* Advance to the next slot if this varying has a different packing
+       * class than the previous one, and we're not already on a slot
+       * boundary.
+       */
+      if (i > 0 &&
+          this->matches[i - 1].packing_class
+          != this->matches[i].packing_class) {
+         generic_location = ALIGN(generic_location, 4);
+      }
+
+      this->matches[i].generic_location = generic_location;
+
+      generic_location += this->matches[i].num_components;
+   }
+
+   return (generic_location + 3) / 4;
+}
+
+
+/**
+ * Update the producer and consumer shaders to reflect the locations
+ * assignments that were made by varying_matches::assign_locations().
+ */
+void
+varying_matches::store_locations(unsigned producer_base,
+                                 unsigned consumer_base) const
+{
+   for (unsigned i = 0; i < this->num_matches; i++) {
+      ir_variable *producer_var = this->matches[i].producer_var;
+      ir_variable *consumer_var = this->matches[i].consumer_var;
+      unsigned generic_location = this->matches[i].generic_location;
+      unsigned slot = generic_location / 4;
+      unsigned offset = generic_location % 4;
+
+      producer_var->location = producer_base + slot;
+      producer_var->location_frac = offset;
+      if (consumer_var) {
+         assert(consumer_var->location == -1);
+         consumer_var->location = consumer_base + slot;
+         consumer_var->location_frac = offset;
+      }
+   }
+}
+
+
+/**
+ * Compute the "packing class" of the given varying.  This is an unsigned
+ * integer with the property that two variables in the same packing class can
+ * be safely backed into the same vec4.
+ */
+unsigned
+varying_matches::compute_packing_class(ir_variable *var)
+{
+   /* Without help from the back-end, there is no way to pack together
+    * variables with different interpolation types, because
+    * lower_packed_varyings must choose exactly one interpolation type for
+    * each packed varying it creates.
+    *
+    * However, we can safely pack together floats, ints, and uints, because:
+    *
+    * - varyings of base type "int" and "uint" must use the "flat"
+    *   interpolation type, which can only occur in GLSL 1.30 and above.
+    *
+    * - On platforms that support GLSL 1.30 and above, lower_packed_varyings
+    *   can store flat floats as ints without losing any information (using
+    *   the ir_unop_bitcast_* opcodes).
+    *
+    * Therefore, the packing class depends only on the interpolation type.
+    */
+   unsigned packing_class = var->centroid ? 1 : 0;
+   packing_class *= 4;
+   packing_class += var->interpolation;
+   return packing_class;
+}
+
+
+/**
+ * Compute the "packing order" of the given varying.  This is a sort key we
+ * use to determine when to attempt to pack the given varying relative to
+ * other varyings in the same packing class.
+ */
+varying_matches::packing_order_enum
+varying_matches::compute_packing_order(ir_variable *var)
+{
+   const glsl_type *element_type = var->type;
+
+   /* FINISHME: Support for "varying" records in GLSL 1.50. */
+   while (element_type->base_type == GLSL_TYPE_ARRAY) {
+      element_type = element_type->fields.array;
+   }
+
+   switch (element_type->vector_elements) {
+   case 1: return PACKING_ORDER_SCALAR;
+   case 2: return PACKING_ORDER_VEC2;
+   case 3: return PACKING_ORDER_VEC3;
+   case 4: return PACKING_ORDER_VEC4;
+   default:
+      assert(!"Unexpected value of vector_elements");
+      return PACKING_ORDER_VEC4;
+   }
+}
+
+
+/**
+ * Comparison function passed to qsort() to sort varyings by packing_class and
+ * then by packing_order.
+ */
+int
+varying_matches::match_comparator(const void *x_generic, const void *y_generic)
+{
+   const match *x = (const match *) x_generic;
+   const match *y = (const match *) y_generic;
+
+   if (x->packing_class != y->packing_class)
+      return x->packing_class - y->packing_class;
+   return x->packing_order - y->packing_order;
+}
+
+
+/**
+ * Is the given variable a varying variable to be counted against the
+ * limit in ctx->Const.MaxVarying?
+ * This includes variables such as texcoords, colors and generic
+ * varyings, but excludes variables such as gl_FrontFacing and gl_FragCoord.
+ */
+static bool
+is_varying_var(GLenum shaderType, const ir_variable *var)
+{
+   /* Only fragment shaders will take a varying variable as an input */
+   if (shaderType == GL_FRAGMENT_SHADER &&
+       var->mode == ir_var_in) {
+      switch (var->location) {
+      case FRAG_ATTRIB_WPOS:
+      case FRAG_ATTRIB_FACE:
+      case FRAG_ATTRIB_PNTC:
+         return false;
+      default:
+         return true;
+      }
+   }
+   return false;
+}
+
+
+/**
+ * Assign locations for all variables that are produced in one pipeline stage
+ * (the "producer") and consumed in the next stage (the "consumer").
+ *
+ * Variables produced by the producer may also be consumed by transform
+ * feedback.
+ *
+ * \param num_tfeedback_decls is the number of declarations indicating
+ *        variables that may be consumed by transform feedback.
+ *
+ * \param tfeedback_decls is a pointer to an array of tfeedback_decl objects
+ *        representing the result of parsing the strings passed to
+ *        glTransformFeedbackVaryings().  assign_location() will be called for
+ *        each of these objects that matches one of the outputs of the
+ *        producer.
+ *
+ * When num_tfeedback_decls is nonzero, it is permissible for the consumer to
+ * be NULL.  In this case, varying locations are assigned solely based on the
+ * requirements of transform feedback.
+ */
+bool
+assign_varying_locations(struct gl_context *ctx,
+			 void *mem_ctx,
+			 struct gl_shader_program *prog,
+			 gl_shader *producer, gl_shader *consumer,
+                         unsigned num_tfeedback_decls,
+                         tfeedback_decl *tfeedback_decls)
+{
+   /* FINISHME: Set dynamically when geometry shader support is added. */
+   const unsigned producer_base = VERT_RESULT_VAR0;
+   const unsigned consumer_base = FRAG_ATTRIB_VAR0;
+   varying_matches matches(ctx->Const.DisableVaryingPacking);
+
+   /* Operate in a total of three passes.
+    *
+    * 1. Assign locations for any matching inputs and outputs.
+    *
+    * 2. Mark output variables in the producer that do not have locations as
+    *    not being outputs.  This lets the optimizer eliminate them.
+    *
+    * 3. Mark input variables in the consumer that do not have locations as
+    *    not being inputs.  This lets the optimizer eliminate them.
+    */
+
+   foreach_list(node, producer->ir) {
+      ir_variable *const output_var = ((ir_instruction *) node)->as_variable();
+
+      if ((output_var == NULL) || (output_var->mode != ir_var_out))
+	 continue;
+
+      ir_variable *input_var =
+	 consumer ? consumer->symbols->get_variable(output_var->name) : NULL;
+
+      if (input_var && input_var->mode != ir_var_in)
+         input_var = NULL;
+
+      if (input_var) {
+         matches.record(output_var, input_var);
+      }
+   }
+
+   for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
+      if (!tfeedback_decls[i].is_varying())
+         continue;
+
+      ir_variable *output_var
+         = tfeedback_decls[i].find_output_var(prog, producer);
+
+      if (output_var == NULL)
+         return false;
+
+      if (output_var->is_unmatched_generic_inout) {
+         matches.record(output_var, NULL);
+      }
+   }
+
+   const unsigned slots_used = matches.assign_locations();
+   matches.store_locations(producer_base, consumer_base);
+
+   for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
+      if (!tfeedback_decls[i].is_varying())
+         continue;
+
+      ir_variable *output_var
+         = tfeedback_decls[i].find_output_var(prog, producer);
+
+      if (!tfeedback_decls[i].assign_location(ctx, prog, output_var))
+         return false;
+   }
+
+   if (ctx->Const.DisableVaryingPacking) {
+      /* Transform feedback code assumes varyings are packed, so if the driver
+       * has disabled varying packing, make sure it does not support transform
+       * feedback.
+       */
+      assert(!ctx->Extensions.EXT_transform_feedback);
+   } else {
+      lower_packed_varyings(mem_ctx, producer_base, slots_used, ir_var_out,
+                            producer);
+      if (consumer) {
+         lower_packed_varyings(mem_ctx, consumer_base, slots_used, ir_var_in,
+                               consumer);
+      }
+   }
+
+   unsigned varying_vectors = 0;
+
+   if (consumer) {
+      foreach_list(node, consumer->ir) {
+         ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+         if ((var == NULL) || (var->mode != ir_var_in))
+            continue;
+
+         if (var->is_unmatched_generic_inout) {
+            if (prog->Version <= 120) {
+               /* On page 25 (page 31 of the PDF) of the GLSL 1.20 spec:
+                *
+                *     Only those varying variables used (i.e. read) in
+                *     the fragment shader executable must be written to
+                *     by the vertex shader executable; declaring
+                *     superfluous varying variables in a vertex shader is
+                *     permissible.
+                *
+                * We interpret this text as meaning that the VS must
+                * write the variable for the FS to read it.  See
+                * "glsl1-varying read but not written" in piglit.
+                */
+
+               linker_error(prog, "fragment shader varying %s not written "
+                            "by vertex shader\n.", var->name);
+            }
+
+            /* An 'in' variable is only really a shader input if its
+             * value is written by the previous stage.
+             */
+            var->mode = ir_var_auto;
+         } else if (is_varying_var(consumer->Type, var)) {
+            /* The packing rules are used for vertex shader inputs are also
+             * used for fragment shader inputs.
+             */
+            varying_vectors += count_attribute_slots(var->type);
+         }
+      }
+   }
+
+   if (ctx->API == API_OPENGLES2 || prog->IsES) {
+      if (varying_vectors > ctx->Const.MaxVarying) {
+         if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
+            linker_warning(prog, "shader uses too many varying vectors "
+                           "(%u > %u), but the driver will try to optimize "
+                           "them out; this is non-portable out-of-spec "
+                           "behavior\n",
+                           varying_vectors, ctx->Const.MaxVarying);
+         } else {
+            linker_error(prog, "shader uses too many varying vectors "
+                         "(%u > %u)\n",
+                         varying_vectors, ctx->Const.MaxVarying);
+            return false;
+         }
+      }
+   } else {
+      const unsigned float_components = varying_vectors * 4;
+      if (float_components > ctx->Const.MaxVarying * 4) {
+         if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
+            linker_warning(prog, "shader uses too many varying components "
+                           "(%u > %u), but the driver will try to optimize "
+                           "them out; this is non-portable out-of-spec "
+                           "behavior\n",
+                           float_components, ctx->Const.MaxVarying * 4);
+         } else {
+            linker_error(prog, "shader uses too many varying components "
+                         "(%u > %u)\n",
+                         float_components, ctx->Const.MaxVarying * 4);
+            return false;
+         }
+      }
+   }
+
+   return true;
+}
diff --git a/mesalib/src/glsl/link_varyings.h b/mesalib/src/glsl/link_varyings.h
new file mode 100644
index 000000000..057e4b219
--- /dev/null
+++ b/mesalib/src/glsl/link_varyings.h
@@ -0,0 +1,186 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+#ifndef GLSL_LINK_VARYINGS_H
+#define GLSL_LINK_VARYINGS_H
+
+/**
+ * \file link_varyings.h
+ *
+ * Linker functions related specifically to linking varyings between shader
+ * stages.
+ */
+
+
+#include "main/glheader.h"
+
+
+struct gl_shader_program;
+struct gl_shader;
+class ir_variable;
+
+
+/**
+ * Data structure tracking information about a transform feedback declaration
+ * during linking.
+ */
+class tfeedback_decl
+{
+public:
+   bool init(struct gl_context *ctx, struct gl_shader_program *prog,
+             const void *mem_ctx, const char *input);
+   static bool is_same(const tfeedback_decl &x, const tfeedback_decl &y);
+   bool assign_location(struct gl_context *ctx, struct gl_shader_program *prog,
+                        ir_variable *output_var);
+   unsigned get_num_outputs() const;
+   bool store(struct gl_context *ctx, struct gl_shader_program *prog,
+              struct gl_transform_feedback_info *info, unsigned buffer,
+              const unsigned max_outputs) const;
+   ir_variable *find_output_var(gl_shader_program *prog,
+                                gl_shader *producer) const;
+
+   bool is_next_buffer_separator() const
+   {
+      return this->next_buffer_separator;
+   }
+
+   bool is_varying() const
+   {
+      return !this->next_buffer_separator && !this->skip_components;
+   }
+
+   /**
+    * The total number of varying components taken up by this variable.  Only
+    * valid if assign_location() has been called.
+    */
+   unsigned num_components() const
+   {
+      if (this->is_clip_distance_mesa)
+         return this->size;
+      else
+         return this->vector_elements * this->matrix_columns * this->size;
+   }
+
+private:
+   /**
+    * The name that was supplied to glTransformFeedbackVaryings.  Used for
+    * error reporting and glGetTransformFeedbackVarying().
+    */
+   const char *orig_name;
+
+   /**
+    * The name of the variable, parsed from orig_name.
+    */
+   const char *var_name;
+
+   /**
+    * True if the declaration in orig_name represents an array.
+    */
+   bool is_subscripted;
+
+   /**
+    * If is_subscripted is true, the subscript that was specified in orig_name.
+    */
+   unsigned array_subscript;
+
+   /**
+    * True if the variable is gl_ClipDistance and the driver lowers
+    * gl_ClipDistance to gl_ClipDistanceMESA.
+    */
+   bool is_clip_distance_mesa;
+
+   /**
+    * The vertex shader output location that the linker assigned for this
+    * variable.  -1 if a location hasn't been assigned yet.
+    */
+   int location;
+
+   /**
+    * If non-zero, then this variable may be packed along with other variables
+    * into a single varying slot, so this offset should be applied when
+    * accessing components.  For example, an offset of 1 means that the x
+    * component of this variable is actually stored in component y of the
+    * location specified by \c location.
+    *
+    * Only valid if location != -1.
+    */
+   unsigned location_frac;
+
+   /**
+    * If location != -1, the number of vector elements in this variable, or 1
+    * if this variable is a scalar.
+    */
+   unsigned vector_elements;
+
+   /**
+    * If location != -1, the number of matrix columns in this variable, or 1
+    * if this variable is not a matrix.
+    */
+   unsigned matrix_columns;
+
+   /** Type of the varying returned by glGetTransformFeedbackVarying() */
+   GLenum type;
+
+   /**
+    * If location != -1, the size that should be returned by
+    * glGetTransformFeedbackVarying().
+    */
+   unsigned size;
+
+   /**
+    * How many components to skip. If non-zero, this is
+    * gl_SkipComponents{1,2,3,4} from ARB_transform_feedback3.
+    */
+   unsigned skip_components;
+
+   /**
+    * Whether this is gl_NextBuffer from ARB_transform_feedback3.
+    */
+   bool next_buffer_separator;
+};
+
+
+bool
+cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
+				 gl_shader *producer, gl_shader *consumer);
+
+bool
+parse_tfeedback_decls(struct gl_context *ctx, struct gl_shader_program *prog,
+                      const void *mem_ctx, unsigned num_names,
+                      char **varying_names, tfeedback_decl *decls);
+
+bool
+store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
+                     unsigned num_tfeedback_decls,
+                     tfeedback_decl *tfeedback_decls);
+
+bool
+assign_varying_locations(struct gl_context *ctx,
+			 void *mem_ctx,
+			 struct gl_shader_program *prog,
+			 gl_shader *producer, gl_shader *consumer,
+                         unsigned num_tfeedback_decls,
+                         tfeedback_decl *tfeedback_decls);
+
+#endif /* GLSL_LINK_VARYINGS_H */
diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp
index be08156e0..70f3d5bed 100644
--- a/mesalib/src/glsl/linker.cpp
+++ b/mesalib/src/glsl/linker.cpp
@@ -70,14 +70,13 @@
 #include "program.h"
 #include "program/hash_table.h"
 #include "linker.h"
+#include "link_varyings.h"
 #include "ir_optimization.h"
 
 extern "C" {
 #include "main/shaderobj.h"
 }
 
-#define ALIGN(value, alignment)  (((value) + alignment - 1) & ~(alignment - 1))
-
 /**
  * Visitor that determines whether or not a variable is ever written.
  */
@@ -651,126 +650,6 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog)
    return true;
 }
 
-/**
- * Validate that outputs from one stage match inputs of another
- */
-bool
-cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
-				 gl_shader *producer, gl_shader *consumer)
-{
-   glsl_symbol_table parameters;
-   /* FINISHME: Figure these out dynamically. */
-   const char *const producer_stage = "vertex";
-   const char *const consumer_stage = "fragment";
-
-   /* Find all shader outputs in the "producer" stage.
-    */
-   foreach_list(node, producer->ir) {
-      ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
-      /* FINISHME: For geometry shaders, this should also look for inout
-       * FINISHME: variables.
-       */
-      if ((var == NULL) || (var->mode != ir_var_out))
-	 continue;
-
-      parameters.add_variable(var);
-   }
-
-
-   /* Find all shader inputs in the "consumer" stage.  Any variables that have
-    * matching outputs already in the symbol table must have the same type and
-    * qualifiers.
-    */
-   foreach_list(node, consumer->ir) {
-      ir_variable *const input = ((ir_instruction *) node)->as_variable();
-
-      /* FINISHME: For geometry shaders, this should also look for inout
-       * FINISHME: variables.
-       */
-      if ((input == NULL) || (input->mode != ir_var_in))
-	 continue;
-
-      ir_variable *const output = parameters.get_variable(input->name);
-      if (output != NULL) {
-	 /* Check that the types match between stages.
-	  */
-	 if (input->type != output->type) {
-	    /* There is a bit of a special case for gl_TexCoord.  This
-	     * built-in is unsized by default.  Applications that variable
-	     * access it must redeclare it with a size.  There is some
-	     * language in the GLSL spec that implies the fragment shader
-	     * and vertex shader do not have to agree on this size.  Other
-	     * driver behave this way, and one or two applications seem to
-	     * rely on it.
-	     *
-	     * Neither declaration needs to be modified here because the array
-	     * sizes are fixed later when update_array_sizes is called.
-	     *
-	     * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec:
-	     *
-	     *     "Unlike user-defined varying variables, the built-in
-	     *     varying variables don't have a strict one-to-one
-	     *     correspondence between the vertex language and the
-	     *     fragment language."
-	     */
-	    if (!output->type->is_array()
-		|| (strncmp("gl_", output->name, 3) != 0)) {
-	       linker_error(prog,
-			    "%s shader output `%s' declared as type `%s', "
-			    "but %s shader input declared as type `%s'\n",
-			    producer_stage, output->name,
-			    output->type->name,
-			    consumer_stage, input->type->name);
-	       return false;
-	    }
-	 }
-
-	 /* Check that all of the qualifiers match between stages.
-	  */
-	 if (input->centroid != output->centroid) {
-	    linker_error(prog,
-			 "%s shader output `%s' %s centroid qualifier, "
-			 "but %s shader input %s centroid qualifier\n",
-			 producer_stage,
-			 output->name,
-			 (output->centroid) ? "has" : "lacks",
-			 consumer_stage,
-			 (input->centroid) ? "has" : "lacks");
-	    return false;
-	 }
-
-	 if (input->invariant != output->invariant) {
-	    linker_error(prog,
-			 "%s shader output `%s' %s invariant qualifier, "
-			 "but %s shader input %s invariant qualifier\n",
-			 producer_stage,
-			 output->name,
-			 (output->invariant) ? "has" : "lacks",
-			 consumer_stage,
-			 (input->invariant) ? "has" : "lacks");
-	    return false;
-	 }
-
-	 if (input->interpolation != output->interpolation) {
-	    linker_error(prog,
-			 "%s shader output `%s' specifies %s "
-			 "interpolation qualifier, "
-			 "but %s shader input specifies %s "
-			 "interpolation qualifier\n",
-			 producer_stage,
-			 output->name,
-			 output->interpolation_string(),
-			 consumer_stage,
-			 input->interpolation_string());
-	    return false;
-	 }
-      }
-   }
-
-   return true;
-}
-
 
 /**
  * Populates a shaders symbol table with all global declarations
@@ -1527,1010 +1406,6 @@ demote_shader_inputs_and_outputs(gl_shader *sh, enum ir_variable_mode mode)
 }
 
 
-/**
- * Data structure tracking information about a transform feedback declaration
- * during linking.
- */
-class tfeedback_decl
-{
-public:
-   bool init(struct gl_context *ctx, struct gl_shader_program *prog,
-             const void *mem_ctx, const char *input);
-   static bool is_same(const tfeedback_decl &x, const tfeedback_decl &y);
-   bool assign_location(struct gl_context *ctx, struct gl_shader_program *prog,
-                        ir_variable *output_var);
-   unsigned get_num_outputs() const;
-   bool store(struct gl_context *ctx, struct gl_shader_program *prog,
-              struct gl_transform_feedback_info *info, unsigned buffer,
-              const unsigned max_outputs) const;
-   ir_variable *find_output_var(gl_shader_program *prog,
-                                gl_shader *producer) const;
-
-   bool is_next_buffer_separator() const
-   {
-      return this->next_buffer_separator;
-   }
-
-   bool is_varying() const
-   {
-      return !this->next_buffer_separator && !this->skip_components;
-   }
-
-   /**
-    * The total number of varying components taken up by this variable.  Only
-    * valid if assign_location() has been called.
-    */
-   unsigned num_components() const
-   {
-      if (this->is_clip_distance_mesa)
-         return this->size;
-      else
-         return this->vector_elements * this->matrix_columns * this->size;
-   }
-
-private:
-   /**
-    * The name that was supplied to glTransformFeedbackVaryings.  Used for
-    * error reporting and glGetTransformFeedbackVarying().
-    */
-   const char *orig_name;
-
-   /**
-    * The name of the variable, parsed from orig_name.
-    */
-   const char *var_name;
-
-   /**
-    * True if the declaration in orig_name represents an array.
-    */
-   bool is_subscripted;
-
-   /**
-    * If is_subscripted is true, the subscript that was specified in orig_name.
-    */
-   unsigned array_subscript;
-
-   /**
-    * True if the variable is gl_ClipDistance and the driver lowers
-    * gl_ClipDistance to gl_ClipDistanceMESA.
-    */
-   bool is_clip_distance_mesa;
-
-   /**
-    * The vertex shader output location that the linker assigned for this
-    * variable.  -1 if a location hasn't been assigned yet.
-    */
-   int location;
-
-   /**
-    * If non-zero, then this variable may be packed along with other variables
-    * into a single varying slot, so this offset should be applied when
-    * accessing components.  For example, an offset of 1 means that the x
-    * component of this variable is actually stored in component y of the
-    * location specified by \c location.
-    *
-    * Only valid if location != -1.
-    */
-   unsigned location_frac;
-
-   /**
-    * If location != -1, the number of vector elements in this variable, or 1
-    * if this variable is a scalar.
-    */
-   unsigned vector_elements;
-
-   /**
-    * If location != -1, the number of matrix columns in this variable, or 1
-    * if this variable is not a matrix.
-    */
-   unsigned matrix_columns;
-
-   /** Type of the varying returned by glGetTransformFeedbackVarying() */
-   GLenum type;
-
-   /**
-    * If location != -1, the size that should be returned by
-    * glGetTransformFeedbackVarying().
-    */
-   unsigned size;
-
-   /**
-    * How many components to skip. If non-zero, this is
-    * gl_SkipComponents{1,2,3,4} from ARB_transform_feedback3.
-    */
-   unsigned skip_components;
-
-   /**
-    * Whether this is gl_NextBuffer from ARB_transform_feedback3.
-    */
-   bool next_buffer_separator;
-};
-
-
-/**
- * Initialize this object based on a string that was passed to
- * glTransformFeedbackVaryings.  If there is a parse error, the error is
- * reported using linker_error(), and false is returned.
- */
-bool
-tfeedback_decl::init(struct gl_context *ctx, struct gl_shader_program *prog,
-                     const void *mem_ctx, const char *input)
-{
-   /* We don't have to be pedantic about what is a valid GLSL variable name,
-    * because any variable with an invalid name can't exist in the IR anyway.
-    */
-
-   this->location = -1;
-   this->orig_name = input;
-   this->is_clip_distance_mesa = false;
-   this->skip_components = 0;
-   this->next_buffer_separator = false;
-
-   if (ctx->Extensions.ARB_transform_feedback3) {
-      /* Parse gl_NextBuffer. */
-      if (strcmp(input, "gl_NextBuffer") == 0) {
-         this->next_buffer_separator = true;
-         return true;
-      }
-
-      /* Parse gl_SkipComponents. */
-      if (strcmp(input, "gl_SkipComponents1") == 0)
-         this->skip_components = 1;
-      else if (strcmp(input, "gl_SkipComponents2") == 0)
-         this->skip_components = 2;
-      else if (strcmp(input, "gl_SkipComponents3") == 0)
-         this->skip_components = 3;
-      else if (strcmp(input, "gl_SkipComponents4") == 0)
-         this->skip_components = 4;
-
-      if (this->skip_components)
-         return true;
-   }
-
-   /* Parse a declaration. */
-   const char *bracket = strrchr(input, '[');
-
-   if (bracket) {
-      this->var_name = ralloc_strndup(mem_ctx, input, bracket - input);
-      if (sscanf(bracket, "[%u]", &this->array_subscript) != 1) {
-         linker_error(prog, "Cannot parse transform feedback varying %s", input);
-         return false;
-      }
-      this->is_subscripted = true;
-   } else {
-      this->var_name = ralloc_strdup(mem_ctx, input);
-      this->is_subscripted = false;
-   }
-
-   /* For drivers that lower gl_ClipDistance to gl_ClipDistanceMESA, this
-    * class must behave specially to account for the fact that gl_ClipDistance
-    * is converted from a float[8] to a vec4[2].
-    */
-   if (ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].LowerClipDistance &&
-       strcmp(this->var_name, "gl_ClipDistance") == 0) {
-      this->is_clip_distance_mesa = true;
-   }
-
-   return true;
-}
-
-
-/**
- * Determine whether two tfeedback_decl objects refer to the same variable and
- * array index (if applicable).
- */
-bool
-tfeedback_decl::is_same(const tfeedback_decl &x, const tfeedback_decl &y)
-{
-   assert(x.is_varying() && y.is_varying());
-
-   if (strcmp(x.var_name, y.var_name) != 0)
-      return false;
-   if (x.is_subscripted != y.is_subscripted)
-      return false;
-   if (x.is_subscripted && x.array_subscript != y.array_subscript)
-      return false;
-   return true;
-}
-
-
-/**
- * Assign a location for this tfeedback_decl object based on the location
- * assignment in output_var.
- *
- * If an error occurs, the error is reported through linker_error() and false
- * is returned.
- */
-bool
-tfeedback_decl::assign_location(struct gl_context *ctx,
-                                struct gl_shader_program *prog,
-                                ir_variable *output_var)
-{
-   assert(this->is_varying());
-
-   if (output_var->type->is_array()) {
-      /* Array variable */
-      const unsigned matrix_cols =
-         output_var->type->fields.array->matrix_columns;
-      const unsigned vector_elements =
-         output_var->type->fields.array->vector_elements;
-      unsigned actual_array_size = this->is_clip_distance_mesa ?
-         prog->Vert.ClipDistanceArraySize : output_var->type->array_size();
-
-      if (this->is_subscripted) {
-         /* Check array bounds. */
-         if (this->array_subscript >= actual_array_size) {
-            linker_error(prog, "Transform feedback varying %s has index "
-                         "%i, but the array size is %u.",
-                         this->orig_name, this->array_subscript,
-                         actual_array_size);
-            return false;
-         }
-         if (this->is_clip_distance_mesa) {
-            this->location =
-               output_var->location + this->array_subscript / 4;
-            this->location_frac = this->array_subscript % 4;
-         } else {
-            unsigned fine_location
-               = output_var->location * 4 + output_var->location_frac;
-            unsigned array_elem_size = vector_elements * matrix_cols;
-            fine_location += array_elem_size * this->array_subscript;
-            this->location = fine_location / 4;
-            this->location_frac = fine_location % 4;
-         }
-         this->size = 1;
-      } else {
-         this->location = output_var->location;
-         this->location_frac = output_var->location_frac;
-         this->size = actual_array_size;
-      }
-      this->vector_elements = vector_elements;
-      this->matrix_columns = matrix_cols;
-      if (this->is_clip_distance_mesa)
-         this->type = GL_FLOAT;
-      else
-         this->type = output_var->type->fields.array->gl_type;
-   } else {
-      /* Regular variable (scalar, vector, or matrix) */
-      if (this->is_subscripted) {
-         linker_error(prog, "Transform feedback varying %s requested, "
-                      "but %s is not an array.",
-                      this->orig_name, this->var_name);
-         return false;
-      }
-      this->location = output_var->location;
-      this->location_frac = output_var->location_frac;
-      this->size = 1;
-      this->vector_elements = output_var->type->vector_elements;
-      this->matrix_columns = output_var->type->matrix_columns;
-      this->type = output_var->type->gl_type;
-   }
-
-   /* From GL_EXT_transform_feedback:
-    *   A program will fail to link if:
-    *
-    *   * the total number of components to capture in any varying
-    *     variable in <varyings> is greater than the constant
-    *     MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT and the
-    *     buffer mode is SEPARATE_ATTRIBS_EXT;
-    */
-   if (prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS &&
-       this->num_components() >
-       ctx->Const.MaxTransformFeedbackSeparateComponents) {
-      linker_error(prog, "Transform feedback varying %s exceeds "
-                   "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS.",
-                   this->orig_name);
-      return false;
-   }
-
-   return true;
-}
-
-
-unsigned
-tfeedback_decl::get_num_outputs() const
-{
-   if (!this->is_varying()) {
-      return 0;
-   }
-
-   return (this->num_components() + this->location_frac + 3)/4;
-}
-
-
-/**
- * Update gl_transform_feedback_info to reflect this tfeedback_decl.
- *
- * If an error occurs, the error is reported through linker_error() and false
- * is returned.
- */
-bool
-tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
-                      struct gl_transform_feedback_info *info,
-                      unsigned buffer, const unsigned max_outputs) const
-{
-   assert(!this->next_buffer_separator);
-
-   /* Handle gl_SkipComponents. */
-   if (this->skip_components) {
-      info->BufferStride[buffer] += this->skip_components;
-      return true;
-   }
-
-   /* From GL_EXT_transform_feedback:
-    *   A program will fail to link if:
-    *
-    *     * the total number of components to capture is greater than
-    *       the constant MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT
-    *       and the buffer mode is INTERLEAVED_ATTRIBS_EXT.
-    */
-   if (prog->TransformFeedback.BufferMode == GL_INTERLEAVED_ATTRIBS &&
-       info->BufferStride[buffer] + this->num_components() >
-       ctx->Const.MaxTransformFeedbackInterleavedComponents) {
-      linker_error(prog, "The MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS "
-                   "limit has been exceeded.");
-      return false;
-   }
-
-   unsigned location = this->location;
-   unsigned location_frac = this->location_frac;
-   unsigned num_components = this->num_components();
-   while (num_components > 0) {
-      unsigned output_size = MIN2(num_components, 4 - location_frac);
-      assert(info->NumOutputs < max_outputs);
-      info->Outputs[info->NumOutputs].ComponentOffset = location_frac;
-      info->Outputs[info->NumOutputs].OutputRegister = location;
-      info->Outputs[info->NumOutputs].NumComponents = output_size;
-      info->Outputs[info->NumOutputs].OutputBuffer = buffer;
-      info->Outputs[info->NumOutputs].DstOffset = info->BufferStride[buffer];
-      ++info->NumOutputs;
-      info->BufferStride[buffer] += output_size;
-      num_components -= output_size;
-      location++;
-      location_frac = 0;
-   }
-
-   info->Varyings[info->NumVarying].Name = ralloc_strdup(prog, this->orig_name);
-   info->Varyings[info->NumVarying].Type = this->type;
-   info->Varyings[info->NumVarying].Size = this->size;
-   info->NumVarying++;
-
-   return true;
-}
-
-
-ir_variable *
-tfeedback_decl::find_output_var(gl_shader_program *prog,
-                                gl_shader *producer) const
-{
-   const char *name = this->is_clip_distance_mesa
-      ? "gl_ClipDistanceMESA" : this->var_name;
-   ir_variable *var = producer->symbols->get_variable(name);
-   if (var && var->mode == ir_var_out)
-      return var;
-
-   /* From GL_EXT_transform_feedback:
-    *   A program will fail to link if:
-    *
-    *   * any variable name specified in the <varyings> array is not
-    *     declared as an output in the geometry shader (if present) or
-    *     the vertex shader (if no geometry shader is present);
-    */
-   linker_error(prog, "Transform feedback varying %s undeclared.",
-                this->orig_name);
-   return NULL;
-}
-
-
-/**
- * Parse all the transform feedback declarations that were passed to
- * glTransformFeedbackVaryings() and store them in tfeedback_decl objects.
- *
- * If an error occurs, the error is reported through linker_error() and false
- * is returned.
- */
-static bool
-parse_tfeedback_decls(struct gl_context *ctx, struct gl_shader_program *prog,
-                      const void *mem_ctx, unsigned num_names,
-                      char **varying_names, tfeedback_decl *decls)
-{
-   for (unsigned i = 0; i < num_names; ++i) {
-      if (!decls[i].init(ctx, prog, mem_ctx, varying_names[i]))
-         return false;
-
-      if (!decls[i].is_varying())
-         continue;
-
-      /* From GL_EXT_transform_feedback:
-       *   A program will fail to link if:
-       *
-       *   * any two entries in the <varyings> array specify the same varying
-       *     variable;
-       *
-       * We interpret this to mean "any two entries in the <varyings> array
-       * specify the same varying variable and array index", since transform
-       * feedback of arrays would be useless otherwise.
-       */
-      for (unsigned j = 0; j < i; ++j) {
-         if (!decls[j].is_varying())
-            continue;
-
-         if (tfeedback_decl::is_same(decls[i], decls[j])) {
-            linker_error(prog, "Transform feedback varying %s specified "
-                         "more than once.", varying_names[i]);
-            return false;
-         }
-      }
-   }
-   return true;
-}
-
-
-/**
- * Data structure recording the relationship between outputs of one shader
- * stage (the "producer") and inputs of another (the "consumer").
- */
-class varying_matches
-{
-public:
-   varying_matches(bool disable_varying_packing);
-   ~varying_matches();
-   void record(ir_variable *producer_var, ir_variable *consumer_var);
-   unsigned assign_locations();
-   void store_locations(unsigned producer_base, unsigned consumer_base) const;
-
-private:
-   /**
-    * If true, this driver disables varying packing, so all varyings need to
-    * be aligned on slot boundaries, and take up a number of slots equal to
-    * their number of matrix columns times their array size.
-    */
-   const bool disable_varying_packing;
-
-   /**
-    * Enum representing the order in which varyings are packed within a
-    * packing class.
-    *
-    * Currently we pack vec4's first, then vec2's, then scalar values, then
-    * vec3's.  This order ensures that the only vectors that are at risk of
-    * having to be "double parked" (split between two adjacent varying slots)
-    * are the vec3's.
-    */
-   enum packing_order_enum {
-      PACKING_ORDER_VEC4,
-      PACKING_ORDER_VEC2,
-      PACKING_ORDER_SCALAR,
-      PACKING_ORDER_VEC3,
-   };
-
-   static unsigned compute_packing_class(ir_variable *var);
-   static packing_order_enum compute_packing_order(ir_variable *var);
-   static int match_comparator(const void *x_generic, const void *y_generic);
-
-   /**
-    * Structure recording the relationship between a single producer output
-    * and a single consumer input.
-    */
-   struct match {
-      /**
-       * Packing class for this varying, computed by compute_packing_class().
-       */
-      unsigned packing_class;
-
-      /**
-       * Packing order for this varying, computed by compute_packing_order().
-       */
-      packing_order_enum packing_order;
-      unsigned num_components;
-
-      /**
-       * The output variable in the producer stage.
-       */
-      ir_variable *producer_var;
-
-      /**
-       * The input variable in the consumer stage.
-       */
-      ir_variable *consumer_var;
-
-      /**
-       * The location which has been assigned for this varying.  This is
-       * expressed in multiples of a float, with the first generic varying
-       * (i.e. the one referred to by VERT_RESULT_VAR0 or FRAG_ATTRIB_VAR0)
-       * represented by the value 0.
-       */
-      unsigned generic_location;
-   } *matches;
-
-   /**
-    * The number of elements in the \c matches array that are currently in
-    * use.
-    */
-   unsigned num_matches;
-
-   /**
-    * The number of elements that were set aside for the \c matches array when
-    * it was allocated.
-    */
-   unsigned matches_capacity;
-};
-
-
-varying_matches::varying_matches(bool disable_varying_packing)
-   : disable_varying_packing(disable_varying_packing)
-{
-   /* Note: this initial capacity is rather arbitrarily chosen to be large
-    * enough for many cases without wasting an unreasonable amount of space.
-    * varying_matches::record() will resize the array if there are more than
-    * this number of varyings.
-    */
-   this->matches_capacity = 8;
-   this->matches = (match *)
-      malloc(sizeof(*this->matches) * this->matches_capacity);
-   this->num_matches = 0;
-}
-
-
-varying_matches::~varying_matches()
-{
-   free(this->matches);
-}
-
-
-/**
- * Record the given producer/consumer variable pair in the list of variables
- * that should later be assigned locations.
- *
- * It is permissible for \c consumer_var to be NULL (this happens if a
- * variable is output by the producer and consumed by transform feedback, but
- * not consumed by the consumer).
- *
- * If \c producer_var has already been paired up with a consumer_var, or
- * producer_var is part of fixed pipeline functionality (and hence already has
- * a location assigned), this function has no effect.
- */
-void
-varying_matches::record(ir_variable *producer_var, ir_variable *consumer_var)
-{
-   if (!producer_var->is_unmatched_generic_inout) {
-      /* Either a location already exists for this variable (since it is part
-       * of fixed functionality), or it has already been recorded as part of a
-       * previous match.
-       */
-      return;
-   }
-
-   if (this->num_matches == this->matches_capacity) {
-      this->matches_capacity *= 2;
-      this->matches = (match *)
-         realloc(this->matches,
-                 sizeof(*this->matches) * this->matches_capacity);
-   }
-   this->matches[this->num_matches].packing_class
-      = this->compute_packing_class(producer_var);
-   this->matches[this->num_matches].packing_order
-      = this->compute_packing_order(producer_var);
-   if (this->disable_varying_packing) {
-      unsigned slots = producer_var->type->is_array()
-         ? (producer_var->type->length
-            * producer_var->type->fields.array->matrix_columns)
-         : producer_var->type->matrix_columns;
-      this->matches[this->num_matches].num_components = 4 * slots;
-   } else {
-      this->matches[this->num_matches].num_components
-         = producer_var->type->component_slots();
-   }
-   this->matches[this->num_matches].producer_var = producer_var;
-   this->matches[this->num_matches].consumer_var = consumer_var;
-   this->num_matches++;
-   producer_var->is_unmatched_generic_inout = 0;
-   if (consumer_var)
-      consumer_var->is_unmatched_generic_inout = 0;
-}
-
-
-/**
- * Choose locations for all of the variable matches that were previously
- * passed to varying_matches::record().
- */
-unsigned
-varying_matches::assign_locations()
-{
-   /* Sort varying matches into an order that makes them easy to pack. */
-   qsort(this->matches, this->num_matches, sizeof(*this->matches),
-         &varying_matches::match_comparator);
-
-   unsigned generic_location = 0;
-
-   for (unsigned i = 0; i < this->num_matches; i++) {
-      /* Advance to the next slot if this varying has a different packing
-       * class than the previous one, and we're not already on a slot
-       * boundary.
-       */
-      if (i > 0 &&
-          this->matches[i - 1].packing_class
-          != this->matches[i].packing_class) {
-         generic_location = ALIGN(generic_location, 4);
-      }
-
-      this->matches[i].generic_location = generic_location;
-
-      generic_location += this->matches[i].num_components;
-   }
-
-   return (generic_location + 3) / 4;
-}
-
-
-/**
- * Update the producer and consumer shaders to reflect the locations
- * assignments that were made by varying_matches::assign_locations().
- */
-void
-varying_matches::store_locations(unsigned producer_base,
-                                 unsigned consumer_base) const
-{
-   for (unsigned i = 0; i < this->num_matches; i++) {
-      ir_variable *producer_var = this->matches[i].producer_var;
-      ir_variable *consumer_var = this->matches[i].consumer_var;
-      unsigned generic_location = this->matches[i].generic_location;
-      unsigned slot = generic_location / 4;
-      unsigned offset = generic_location % 4;
-
-      producer_var->location = producer_base + slot;
-      producer_var->location_frac = offset;
-      if (consumer_var) {
-         assert(consumer_var->location == -1);
-         consumer_var->location = consumer_base + slot;
-         consumer_var->location_frac = offset;
-      }
-   }
-}
-
-
-/**
- * Compute the "packing class" of the given varying.  This is an unsigned
- * integer with the property that two variables in the same packing class can
- * be safely backed into the same vec4.
- */
-unsigned
-varying_matches::compute_packing_class(ir_variable *var)
-{
-   /* In this initial implementation we conservatively assume that variables
-    * can only be packed if their base type (float/int/uint/bool) matches and
-    * their interpolation and centroid qualifiers match.
-    *
-    * TODO: relax these restrictions when the driver back-end permits.
-    */
-   unsigned packing_class = var->centroid ? 1 : 0;
-   packing_class *= 4;
-   packing_class += var->interpolation;
-   packing_class *= GLSL_TYPE_ERROR;
-   packing_class += var->type->get_scalar_type()->base_type;
-   return packing_class;
-}
-
-
-/**
- * Compute the "packing order" of the given varying.  This is a sort key we
- * use to determine when to attempt to pack the given varying relative to
- * other varyings in the same packing class.
- */
-varying_matches::packing_order_enum
-varying_matches::compute_packing_order(ir_variable *var)
-{
-   const glsl_type *element_type = var->type;
-
-   /* FINISHME: Support for "varying" records in GLSL 1.50. */
-   while (element_type->base_type == GLSL_TYPE_ARRAY) {
-      element_type = element_type->fields.array;
-   }
-
-   switch (element_type->vector_elements) {
-   case 1: return PACKING_ORDER_SCALAR;
-   case 2: return PACKING_ORDER_VEC2;
-   case 3: return PACKING_ORDER_VEC3;
-   case 4: return PACKING_ORDER_VEC4;
-   default:
-      assert(!"Unexpected value of vector_elements");
-      return PACKING_ORDER_VEC4;
-   }
-}
-
-
-/**
- * Comparison function passed to qsort() to sort varyings by packing_class and
- * then by packing_order.
- */
-int
-varying_matches::match_comparator(const void *x_generic, const void *y_generic)
-{
-   const match *x = (const match *) x_generic;
-   const match *y = (const match *) y_generic;
-
-   if (x->packing_class != y->packing_class)
-      return x->packing_class - y->packing_class;
-   return x->packing_order - y->packing_order;
-}
-
-
-/**
- * Is the given variable a varying variable to be counted against the
- * limit in ctx->Const.MaxVarying?
- * This includes variables such as texcoords, colors and generic
- * varyings, but excludes variables such as gl_FrontFacing and gl_FragCoord.
- */
-static bool
-is_varying_var(GLenum shaderType, const ir_variable *var)
-{
-   /* Only fragment shaders will take a varying variable as an input */
-   if (shaderType == GL_FRAGMENT_SHADER &&
-       var->mode == ir_var_in) {
-      switch (var->location) {
-      case FRAG_ATTRIB_WPOS:
-      case FRAG_ATTRIB_FACE:
-      case FRAG_ATTRIB_PNTC:
-         return false;
-      default:
-         return true;
-      }
-   }
-   return false;
-}
-
-
-/**
- * Assign locations for all variables that are produced in one pipeline stage
- * (the "producer") and consumed in the next stage (the "consumer").
- *
- * Variables produced by the producer may also be consumed by transform
- * feedback.
- *
- * \param num_tfeedback_decls is the number of declarations indicating
- *        variables that may be consumed by transform feedback.
- *
- * \param tfeedback_decls is a pointer to an array of tfeedback_decl objects
- *        representing the result of parsing the strings passed to
- *        glTransformFeedbackVaryings().  assign_location() will be called for
- *        each of these objects that matches one of the outputs of the
- *        producer.
- *
- * When num_tfeedback_decls is nonzero, it is permissible for the consumer to
- * be NULL.  In this case, varying locations are assigned solely based on the
- * requirements of transform feedback.
- */
-bool
-assign_varying_locations(struct gl_context *ctx,
-			 void *mem_ctx,
-			 struct gl_shader_program *prog,
-			 gl_shader *producer, gl_shader *consumer,
-                         unsigned num_tfeedback_decls,
-                         tfeedback_decl *tfeedback_decls)
-{
-   /* FINISHME: Set dynamically when geometry shader support is added. */
-   const unsigned producer_base = VERT_RESULT_VAR0;
-   const unsigned consumer_base = FRAG_ATTRIB_VAR0;
-   varying_matches matches(ctx->Const.DisableVaryingPacking);
-
-   /* Operate in a total of three passes.
-    *
-    * 1. Assign locations for any matching inputs and outputs.
-    *
-    * 2. Mark output variables in the producer that do not have locations as
-    *    not being outputs.  This lets the optimizer eliminate them.
-    *
-    * 3. Mark input variables in the consumer that do not have locations as
-    *    not being inputs.  This lets the optimizer eliminate them.
-    */
-
-   foreach_list(node, producer->ir) {
-      ir_variable *const output_var = ((ir_instruction *) node)->as_variable();
-
-      if ((output_var == NULL) || (output_var->mode != ir_var_out))
-	 continue;
-
-      ir_variable *input_var =
-	 consumer ? consumer->symbols->get_variable(output_var->name) : NULL;
-
-      if (input_var && input_var->mode != ir_var_in)
-         input_var = NULL;
-
-      if (input_var) {
-         matches.record(output_var, input_var);
-      }
-   }
-
-   for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
-      if (!tfeedback_decls[i].is_varying())
-         continue;
-
-      ir_variable *output_var
-         = tfeedback_decls[i].find_output_var(prog, producer);
-
-      if (output_var == NULL)
-         return false;
-
-      if (output_var->is_unmatched_generic_inout) {
-         matches.record(output_var, NULL);
-      }
-   }
-
-   const unsigned slots_used = matches.assign_locations();
-   matches.store_locations(producer_base, consumer_base);
-
-   for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
-      if (!tfeedback_decls[i].is_varying())
-         continue;
-
-      ir_variable *output_var
-         = tfeedback_decls[i].find_output_var(prog, producer);
-
-      if (!tfeedback_decls[i].assign_location(ctx, prog, output_var))
-         return false;
-   }
-
-   if (ctx->Const.DisableVaryingPacking) {
-      /* Transform feedback code assumes varyings are packed, so if the driver
-       * has disabled varying packing, make sure it does not support transform
-       * feedback.
-       */
-      assert(!ctx->Extensions.EXT_transform_feedback);
-   } else {
-      lower_packed_varyings(mem_ctx, producer_base, slots_used, ir_var_out,
-                            producer);
-      if (consumer) {
-         lower_packed_varyings(mem_ctx, consumer_base, slots_used, ir_var_in,
-                               consumer);
-      }
-   }
-
-   unsigned varying_vectors = 0;
-
-   if (consumer) {
-      foreach_list(node, consumer->ir) {
-         ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
-         if ((var == NULL) || (var->mode != ir_var_in))
-            continue;
-
-         if (var->is_unmatched_generic_inout) {
-            if (prog->Version <= 120) {
-               /* On page 25 (page 31 of the PDF) of the GLSL 1.20 spec:
-                *
-                *     Only those varying variables used (i.e. read) in
-                *     the fragment shader executable must be written to
-                *     by the vertex shader executable; declaring
-                *     superfluous varying variables in a vertex shader is
-                *     permissible.
-                *
-                * We interpret this text as meaning that the VS must
-                * write the variable for the FS to read it.  See
-                * "glsl1-varying read but not written" in piglit.
-                */
-
-               linker_error(prog, "fragment shader varying %s not written "
-                            "by vertex shader\n.", var->name);
-            }
-
-            /* An 'in' variable is only really a shader input if its
-             * value is written by the previous stage.
-             */
-            var->mode = ir_var_auto;
-         } else if (is_varying_var(consumer->Type, var)) {
-            /* The packing rules are used for vertex shader inputs are also
-             * used for fragment shader inputs.
-             */
-            varying_vectors += count_attribute_slots(var->type);
-         }
-      }
-   }
-
-   if (ctx->API == API_OPENGLES2 || prog->IsES) {
-      if (varying_vectors > ctx->Const.MaxVarying) {
-         if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
-            linker_warning(prog, "shader uses too many varying vectors "
-                           "(%u > %u), but the driver will try to optimize "
-                           "them out; this is non-portable out-of-spec "
-                           "behavior\n",
-                           varying_vectors, ctx->Const.MaxVarying);
-         } else {
-            linker_error(prog, "shader uses too many varying vectors "
-                         "(%u > %u)\n",
-                         varying_vectors, ctx->Const.MaxVarying);
-            return false;
-         }
-      }
-   } else {
-      const unsigned float_components = varying_vectors * 4;
-      if (float_components > ctx->Const.MaxVarying * 4) {
-         if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
-            linker_warning(prog, "shader uses too many varying components "
-                           "(%u > %u), but the driver will try to optimize "
-                           "them out; this is non-portable out-of-spec "
-                           "behavior\n",
-                           float_components, ctx->Const.MaxVarying * 4);
-         } else {
-            linker_error(prog, "shader uses too many varying components "
-                         "(%u > %u)\n",
-                         float_components, ctx->Const.MaxVarying * 4);
-            return false;
-         }
-      }
-   }
-
-   return true;
-}
-
-
-/**
- * Store transform feedback location assignments into
- * prog->LinkedTransformFeedback based on the data stored in tfeedback_decls.
- *
- * If an error occurs, the error is reported through linker_error() and false
- * is returned.
- */
-static bool
-store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
-                     unsigned num_tfeedback_decls,
-                     tfeedback_decl *tfeedback_decls)
-{
-   bool separate_attribs_mode =
-      prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS;
-
-   ralloc_free(prog->LinkedTransformFeedback.Varyings);
-   ralloc_free(prog->LinkedTransformFeedback.Outputs);
-
-   memset(&prog->LinkedTransformFeedback, 0,
-          sizeof(prog->LinkedTransformFeedback));
-
-   prog->LinkedTransformFeedback.Varyings =
-      rzalloc_array(prog,
-		    struct gl_transform_feedback_varying_info,
-		    num_tfeedback_decls);
-
-   unsigned num_outputs = 0;
-   for (unsigned i = 0; i < num_tfeedback_decls; ++i)
-      num_outputs += tfeedback_decls[i].get_num_outputs();
-
-   prog->LinkedTransformFeedback.Outputs =
-      rzalloc_array(prog,
-                    struct gl_transform_feedback_output,
-                    num_outputs);
-
-   unsigned num_buffers = 0;
-
-   if (separate_attribs_mode) {
-      /* GL_SEPARATE_ATTRIBS */
-      for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
-         if (!tfeedback_decls[i].store(ctx, prog, &prog->LinkedTransformFeedback,
-                                       num_buffers, num_outputs))
-            return false;
-
-         num_buffers++;
-      }
-   }
-   else {
-      /* GL_INVERLEAVED_ATTRIBS */
-      for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
-         if (tfeedback_decls[i].is_next_buffer_separator()) {
-            num_buffers++;
-            continue;
-         }
-
-         if (!tfeedback_decls[i].store(ctx, prog,
-                                       &prog->LinkedTransformFeedback,
-                                       num_buffers, num_outputs))
-            return false;
-      }
-      num_buffers++;
-   }
-
-   assert(prog->LinkedTransformFeedback.NumOutputs == num_outputs);
-
-   prog->LinkedTransformFeedback.NumBuffers = num_buffers;
-   return true;
-}
-
 /**
  * Store the gl_FragDepth layout in the gl_shader_program struct.
  */
diff --git a/mesalib/src/glsl/linker.h b/mesalib/src/glsl/linker.h
index 7d2e98a15..67c7f3488 100644
--- a/mesalib/src/glsl/linker.h
+++ b/mesalib/src/glsl/linker.h
@@ -91,4 +91,13 @@ private:
    void recursion(const glsl_type *t, char **name, size_t name_length);
 };
 
+void
+linker_error(gl_shader_program *prog, const char *fmt, ...);
+
+void
+linker_warning(gl_shader_program *prog, const char *fmt, ...);
+
+unsigned
+count_attribute_slots(const glsl_type *t);
+
 #endif /* GLSL_LINKER_H */
diff --git a/mesalib/src/glsl/loop_controls.cpp b/mesalib/src/glsl/loop_controls.cpp
index 9acbadc50..79c820436 100644
--- a/mesalib/src/glsl/loop_controls.cpp
+++ b/mesalib/src/glsl/loop_controls.cpp
@@ -222,10 +222,10 @@ loop_control_visitor::visit_leave(ir_loop *ir)
 	    limit = cond->operands[0]->as_constant();
 
 	    switch (cmp) {
-	    case ir_binop_less:    cmp = ir_binop_gequal;  break;
-	    case ir_binop_greater: cmp = ir_binop_lequal;  break;
-	    case ir_binop_lequal:  cmp = ir_binop_greater; break;
-	    case ir_binop_gequal:  cmp = ir_binop_less;    break;
+	    case ir_binop_less:    cmp = ir_binop_greater; break;
+	    case ir_binop_greater: cmp = ir_binop_less;    break;
+	    case ir_binop_lequal:  cmp = ir_binop_gequal;  break;
+	    case ir_binop_gequal:  cmp = ir_binop_lequal;  break;
 	    default: assert(!"Should not get here.");
 	    }
 	 }
diff --git a/mesalib/src/glsl/lower_packed_varyings.cpp b/mesalib/src/glsl/lower_packed_varyings.cpp
index 09c551c4e..9e7f274b7 100644
--- a/mesalib/src/glsl/lower_packed_varyings.cpp
+++ b/mesalib/src/glsl/lower_packed_varyings.cpp
@@ -66,6 +66,10 @@
  * performance.  However, hopefully in most cases the performance loss will
  * either be absorbed by a later optimization pass, or it will be offset by
  * memory bandwidth savings (because fewer varyings are used).
+ *
+ * This lowering pass also packs flat floats, ints, and uints together, by
+ * using ivec4 as the base type of flat "varyings", and using appropriate
+ * casts to convert floats and uints into ints.
  */
 
 #include "glsl_symbol_table.h"
@@ -90,6 +94,8 @@ public:
    void run(exec_list *instructions);
 
 private:
+   ir_assignment *bitwise_assign_pack(ir_rvalue *lhs, ir_rvalue *rhs);
+   ir_assignment *bitwise_assign_unpack(ir_rvalue *lhs, ir_rvalue *rhs);
    unsigned lower_rvalue(ir_rvalue *rvalue, unsigned fine_location,
                          ir_variable *unpacked_var, const char *name);
    unsigned lower_arraylike(ir_rvalue *rvalue, unsigned array_size,
@@ -181,6 +187,75 @@ lower_packed_varyings_visitor::run(exec_list *instructions)
    }
 }
 
+
+/**
+ * Make an ir_assignment from \c rhs to \c lhs, performing appropriate
+ * bitcasts if necessary to match up types.
+ *
+ * This function is called when packing varyings.
+ */
+ir_assignment *
+lower_packed_varyings_visitor::bitwise_assign_pack(ir_rvalue *lhs,
+                                                   ir_rvalue *rhs)
+{
+   if (lhs->type->base_type != rhs->type->base_type) {
+      /* Since we only mix types in flat varyings, and we always store flat
+       * varyings as type ivec4, we need only produce conversions from (uint
+       * or float) to int.
+       */
+      assert(lhs->type->base_type == GLSL_TYPE_INT);
+      switch (rhs->type->base_type) {
+      case GLSL_TYPE_UINT:
+         rhs = new(this->mem_ctx)
+            ir_expression(ir_unop_u2i, lhs->type, rhs);
+         break;
+      case GLSL_TYPE_FLOAT:
+         rhs = new(this->mem_ctx)
+            ir_expression(ir_unop_bitcast_f2i, lhs->type, rhs);
+         break;
+      default:
+         assert(!"Unexpected type conversion while lowering varyings");
+         break;
+      }
+   }
+   return new(this->mem_ctx) ir_assignment(lhs, rhs);
+}
+
+
+/**
+ * Make an ir_assignment from \c rhs to \c lhs, performing appropriate
+ * bitcasts if necessary to match up types.
+ *
+ * This function is called when unpacking varyings.
+ */
+ir_assignment *
+lower_packed_varyings_visitor::bitwise_assign_unpack(ir_rvalue *lhs,
+                                                     ir_rvalue *rhs)
+{
+   if (lhs->type->base_type != rhs->type->base_type) {
+      /* Since we only mix types in flat varyings, and we always store flat
+       * varyings as type ivec4, we need only produce conversions from int to
+       * (uint or float).
+       */
+      assert(rhs->type->base_type == GLSL_TYPE_INT);
+      switch (lhs->type->base_type) {
+      case GLSL_TYPE_UINT:
+         rhs = new(this->mem_ctx)
+            ir_expression(ir_unop_i2u, lhs->type, rhs);
+         break;
+      case GLSL_TYPE_FLOAT:
+         rhs = new(this->mem_ctx)
+            ir_expression(ir_unop_bitcast_i2f, lhs->type, rhs);
+         break;
+      default:
+         assert(!"Unexpected type conversion while lowering varyings");
+         break;
+      }
+   }
+   return new(this->mem_ctx) ir_assignment(lhs, rhs);
+}
+
+
 /**
  * Recursively pack or unpack the given varying (or portion of a varying) by
  * traversing all of its constituent vectors.
@@ -262,12 +337,12 @@ lower_packed_varyings_visitor::lower_rvalue(ir_rvalue *rvalue,
       ir_swizzle *swizzle = new(this->mem_ctx)
          ir_swizzle(packed_deref, swizzle_values, components);
       if (this->mode == ir_var_out) {
-         ir_assignment *assignment = new(this->mem_ctx)
-            ir_assignment(swizzle, rvalue);
+         ir_assignment *assignment
+            = this->bitwise_assign_pack(swizzle, rvalue);
          this->main_instructions->push_tail(assignment);
       } else {
-         ir_assignment *assignment = new(this->mem_ctx)
-            ir_assignment(rvalue, swizzle);
+         ir_assignment *assignment
+            = this->bitwise_assign_unpack(rvalue, swizzle);
          this->main_instructions->push_head(assignment);
       }
       return fine_location + components;
@@ -306,8 +381,9 @@ lower_packed_varyings_visitor::lower_arraylike(ir_rvalue *rvalue,
  * If no packed varying has been created for the given varying location yet,
  * create it and add it to the shader before returning it.
  *
- * The newly created varying inherits its base type (float, uint, or int) and
- * interpolation parameters from \c unpacked_var.
+ * The newly created varying inherits its interpolation parameters from \c
+ * unpacked_var.  Its base type is ivec4 if we are lowering a flat varying,
+ * vec4 otherwise.
  */
 ir_variable *
 lower_packed_varyings_visitor::get_packed_varying(unsigned location,
@@ -318,8 +394,11 @@ lower_packed_varyings_visitor::get_packed_varying(unsigned location,
    assert(slot < locations_used);
    if (this->packed_varyings[slot] == NULL) {
       char *packed_name = ralloc_asprintf(this->mem_ctx, "packed:%s", name);
-      const glsl_type *packed_type = glsl_type::get_instance(
-            unpacked_var->type->get_scalar_type()->base_type, 4, 1);
+      const glsl_type *packed_type;
+      if (unpacked_var->interpolation == INTERP_QUALIFIER_FLAT)
+         packed_type = glsl_type::ivec4_type;
+      else
+         packed_type = glsl_type::vec4_type;
       ir_variable *packed_var = new(this->mem_ctx)
          ir_variable(packed_type, packed_name, this->mode);
       packed_var->centroid = unpacked_var->centroid;
diff --git a/mesalib/src/mapi/glapi/.gitignore b/mesalib/src/mapi/glapi/.gitignore
index 25d3dfdcf..ecae56a3f 100644
--- a/mesalib/src/mapi/glapi/.gitignore
+++ b/mesalib/src/mapi/glapi/.gitignore
@@ -7,4 +7,3 @@ glapi_x86.S
 glapitable.h
 glapitemp.h
 glprocs.h
-\Makefile
diff --git a/mesalib/src/mapi/glapi/gen/.gitignore b/mesalib/src/mapi/glapi/gen/.gitignore
deleted file mode 100644
index 5fc607b9e..000000000
--- a/mesalib/src/mapi/glapi/gen/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/Makefile
diff --git a/mesalib/src/mapi/glapi/gen/ARB_ES3_compatibility.xml b/mesalib/src/mapi/glapi/gen/ARB_ES3_compatibility.xml
new file mode 100644
index 000000000..3944bc7d8
--- /dev/null
+++ b/mesalib/src/mapi/glapi/gen/ARB_ES3_compatibility.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd">
+
+<OpenGLAPI>
+
+<category name="GL_ARB_ES3_compatibility" number="127">
+    <enum name="COMPRESSED_RGB8_ETC2"				value="0x9274"/>
+    <enum name="COMPRESSED_SRGB8_ETC2"				value="0x9275"/>
+    <enum name="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2"	value="0x9276"/>
+    <enum name="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2"	value="0x9277"/>
+    <enum name="COMPRESSED_RGBA8_ETC2_EAC"			value="0x9278"/>
+    <enum name="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC"		value="0x9279"/>
+    <enum name="COMPRESSED_R11_EAC"				value="0x9270"/>
+    <enum name="COMPRESSED_SIGNED_R11_EAC"			value="0x9271"/>
+    <enum name="COMPRESSED_RG11_EAC"				value="0x9272"/>
+    <enum name="COMPRESSED_SIGNED_RG11_EAC"			value="0x9273"/>
+    <enum name="PRIMITIVE_RESTART_FIXED_INDEX"			value="0x8D69"/>
+    <enum name="ANY_SAMPLES_PASSED_CONSERVATIVE"		value="0x8D6A"/>
+    <enum name="MAX_ELEMENT_INDEX"				value="0x8D6B"/>
+    <enum name="TEXTURE_IMMUTABLE_LEVELS"			value="0x82DF"/>
+</category>
+
+</OpenGLAPI>
diff --git a/mesalib/src/mapi/glapi/gen/GL3x.xml b/mesalib/src/mapi/glapi/gen/GL3x.xml
index 1b7adddfa..c17a64402 100644
--- a/mesalib/src/mapi/glapi/gen/GL3x.xml
+++ b/mesalib/src/mapi/glapi/gen/GL3x.xml
@@ -595,7 +595,7 @@
   <enum name="MAX_FRAGMENT_INPUT_COMPONENTS"        value="0x9125"/>
   <enum name="CONTEXT_PROFILE_MASK"                 value="0x9126"/>
 
-  <function name="GetInteger64i_v" offset="assign" es2="3.0" exec="skip">
+  <function name="GetInteger64i_v" offset="assign" es2="3.0">
     <param name="cap" type="GLenum"/>
     <param name="index" type="GLuint"/>
     <param name="data" type="GLint64 *"/>
diff --git a/mesalib/src/mapi/glapi/gen/Makefile.am b/mesalib/src/mapi/glapi/gen/Makefile.am
index 13943e839..ff22c8e0d 100644
--- a/mesalib/src/mapi/glapi/gen/Makefile.am
+++ b/mesalib/src/mapi/glapi/gen/Makefile.am
@@ -51,7 +51,7 @@ if HAVE_SPARC_ASM
 MESA_GLAPI_ASM_OUTPUTS += $(MESA_GLAPI_DIR)/glapi_sparc.S
 endif
 
-MESA_OUTPUTS = \
+BUILT_SOURCES = \
 	$(MESA_GLAPI_OUTPUTS) \
 	$(MESA_GLAPI_ASM_OUTPUTS) \
 	$(MESA_DIR)/main/enums.c \
@@ -63,6 +63,11 @@ MESA_OUTPUTS = \
 	$(MESA_GLX_DIR)/indirect_init.c \
 	$(MESA_GLX_DIR)/indirect_size.h \
 	$(MESA_GLX_DIR)/indirect_size.c
+EXTRA_DIST= \
+	$(BUILT_SOURCES) \
+	$(MESA_GLAPI_DIR)/glapi_x86.S \
+	$(MESA_GLAPI_DIR)/glapi_x86-64.S \
+	$(MESA_GLAPI_DIR)/glapi_sparc.S
 
 ######################################################################
 
@@ -101,6 +106,7 @@ API_XML = \
 	ARB_draw_elements_base_vertex.xml \
 	ARB_draw_instanced.xml \
 	ARB_ES2_compatibility.xml \
+	ARB_ES3_compatibility.xml \
 	ARB_framebuffer_object.xml \
 	ARB_geometry_shader4.xml \
 	ARB_instanced_arrays.xml \
@@ -144,6 +150,7 @@ COMMON = $(API_XML) \
 	gl_and_es_API.xml \
 	es_EXT.xml \
 	ARB_ES2_compatibility.xml \
+	ARB_ES3_compatibility.xml \
 	ARB_get_program_binary.xml \
 	OES_fixed_point.xml \
 	OES_single_precision.xml
@@ -154,8 +161,6 @@ PYTHON_GEN = $(AM_V_GEN) $(PYTHON2) $(PYTHON_FLAGS)
 
 ######################################################################
 
-all-local: $(MESA_OUTPUTS)
-
 xorg: check-xorg-source $(XORG_OUTPUTS)
 
 check-xorg-source:
@@ -169,7 +174,6 @@ check-xorg-source:
 
 clean-local:
 	-rm -f *~ *.pyo
-	-rm -f $(MESA_OUTPUTS)
 
 ######################################################################
 
diff --git a/mesalib/src/mapi/glapi/gen/gl_API.xml b/mesalib/src/mapi/glapi/gen/gl_API.xml
index a47316a83..8a8a1ee03 100644
--- a/mesalib/src/mapi/glapi/gen/gl_API.xml
+++ b/mesalib/src/mapi/glapi/gen/gl_API.xml
@@ -8277,7 +8277,11 @@
 
 <xi:include href="ARB_robustness.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 
-<!-- ARB extensions #106...#108 -->
+<!-- ARB extensions #106 -->
+
+<xi:include href="ARB_base_instance.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+
+<!-- ARB extensions #108 -->
 
 <category name="GL_ARB_transform_feedback_instanced" number="109">
   <function name="DrawTransformFeedbackInstanced" offset="assign"
@@ -8304,10 +8308,14 @@
 
 <!-- ARB extensions #114...#116 -->
 
-<xi:include href="ARB_base_instance.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
-
 <xi:include href="ARB_texture_storage.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 
+<!-- ARB extensions #118...#126 -->
+
+<xi:include href="ARB_ES3_compatibility.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+
+<!-- ARB extensions #128...#131 -->
+
 <xi:include href="ARB_invalidate_subdata.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 
 <!-- Non-ARB extensions sorted by extension number. -->
diff --git a/mesalib/src/mesa/.gitignore b/mesalib/src/mesa/.gitignore
deleted file mode 100644
index 5fc607b9e..000000000
--- a/mesalib/src/mesa/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/Makefile
diff --git a/mesalib/src/mesa/drivers/.gitignore b/mesalib/src/mesa/drivers/.gitignore
deleted file mode 100644
index 5fc607b9e..000000000
--- a/mesalib/src/mesa/drivers/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/Makefile
diff --git a/mesalib/src/mesa/drivers/dri/.gitignore b/mesalib/src/mesa/drivers/dri/.gitignore
deleted file mode 100644
index f3c7a7c5d..000000000
--- a/mesalib/src/mesa/drivers/dri/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/mesalib/src/mesa/drivers/dri/swrast/.gitignore b/mesalib/src/mesa/drivers/dri/swrast/.gitignore
deleted file mode 100644
index f3c7a7c5d..000000000
--- a/mesalib/src/mesa/drivers/dri/swrast/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/mesalib/src/mesa/main/context.c b/mesalib/src/mesa/main/context.c
index fc2db1271..561eb4685 100644
--- a/mesalib/src/mesa/main/context.c
+++ b/mesalib/src/mesa/main/context.c
@@ -656,6 +656,9 @@ _mesa_init_constants(struct gl_context *ctx)
 
    /* PrimitiveRestart */
    ctx->Const.PrimitiveRestartInSoftware = GL_FALSE;
+
+   /* ES 3.0 or ARB_ES3_compatibility */
+   ctx->Const.MaxElementIndex = 0xffffffffu;
 }
 
 
diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c
index 98711b395..3486b65a4 100644
--- a/mesalib/src/mesa/main/extensions.c
+++ b/mesalib/src/mesa/main/extensions.c
@@ -34,11 +34,10 @@
 #include "imports.h"
 #include "context.h"
 #include "extensions.h"
+#include "macros.h"
 #include "mfeatures.h"
 #include "mtypes.h"
 
-#define ALIGN(value, alignment)  (((value) + alignment - 1) & ~(alignment - 1))
-
 enum {
    DISABLE = 0,
    GLL = 1 << API_OPENGL_COMPAT,       /* GL Legacy / Compatibility */
diff --git a/mesalib/src/mesa/main/fbobject.c b/mesalib/src/mesa/main/fbobject.c
index 281cdd05c..50ad84c56 100644
--- a/mesalib/src/mesa/main/fbobject.c
+++ b/mesalib/src/mesa/main/fbobject.c
@@ -222,7 +222,7 @@ _mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
       }
       return &fb->Attachment[BUFFER_COLOR0 + i];
    case GL_DEPTH_STENCIL_ATTACHMENT:
-      if (!_mesa_is_desktop_gl(ctx))
+      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
 	 return NULL;
       /* fall-through */
    case GL_DEPTH_ATTACHMENT_EXT:
diff --git a/mesalib/src/mesa/main/get.c b/mesalib/src/mesa/main/get.c
index 273a79f7f..7d922ca15 100644
--- a/mesalib/src/mesa/main/get.c
+++ b/mesalib/src/mesa/main/get.c
@@ -131,6 +131,7 @@ enum value_extra {
    EXTRA_API_GL,
    EXTRA_API_GL_CORE,
    EXTRA_API_ES2,
+   EXTRA_API_ES3,
    EXTRA_NEW_BUFFERS, 
    EXTRA_NEW_FRAG_CLAMP,
    EXTRA_VALID_DRAW_BUFFER,
@@ -290,14 +291,30 @@ static const int extra_texture_buffer_object[] = {
    EXTRA_END
 };
 
+static const int extra_ARB_transform_feedback2_api_es3[] = {
+   EXT(ARB_transform_feedback2),
+   EXTRA_API_ES3,
+   EXTRA_END
+};
+
 static const int extra_ARB_uniform_buffer_object_and_geometry_shader[] = {
    EXT(ARB_uniform_buffer_object),
    EXT(ARB_geometry_shader4),
    EXTRA_END
 };
 
+static const int extra_ARB_ES2_compatibility_api_es2[] = {
+   EXT(ARB_ES2_compatibility),
+   EXTRA_API_ES2,
+   EXTRA_END
+};
+
+static const int extra_ARB_ES3_compatibility_api_es3[] = {
+   EXT(ARB_ES3_compatibility),
+   EXTRA_API_ES3,
+   EXTRA_END
+};
 
-EXTRA_EXT(ARB_ES2_compatibility);
 EXTRA_EXT(ARB_texture_cube_map);
 EXTRA_EXT(MESA_texture_array);
 EXTRA_EXT2(EXT_secondary_color, ARB_vertex_program);
@@ -322,7 +339,6 @@ EXTRA_EXT(ARB_seamless_cube_map);
 EXTRA_EXT(ARB_sync);
 EXTRA_EXT(ARB_vertex_shader);
 EXTRA_EXT(EXT_transform_feedback);
-EXTRA_EXT(ARB_transform_feedback2);
 EXTRA_EXT(ARB_transform_feedback3);
 EXTRA_EXT(EXT_pixel_buffer_object);
 EXTRA_EXT(ARB_vertex_program);
@@ -348,6 +364,12 @@ static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
 static const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
 static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
 
+static const int extra_gl30_es3[] = {
+    EXTRA_VERSION_30,
+    EXTRA_API_ES3,
+    EXTRA_END,
+};
+
 static const int
 extra_ARB_vertex_program_api_es2[] = {
    EXT(ARB_vertex_program),
@@ -874,6 +896,12 @@ check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d
 	    enabled++;
 	 }
 	 break;
+      case EXTRA_API_ES3:
+	 if (_mesa_is_gles3(ctx)) {
+	    total++;
+	    enabled++;
+	 }
+	 break;
       case EXTRA_API_GL:
 	 if (_mesa_is_desktop_gl(ctx)) {
 	    total++;
@@ -973,6 +1001,15 @@ find_value(const char *func, GLenum pname, void **p, union value *v)
    int api;
 
    api = ctx->API;
+   /* We index into the table_set[] list of per-API hash tables using the API's
+    * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
+    * value since it's compatible with GLES2 its entry in table_set[] is at the
+    * end.
+    */
+   STATIC_ASSERT(Elements(table_set) == API_OPENGL_LAST + 2);
+   if (_mesa_is_gles3(ctx)) {
+      api = API_OPENGL_LAST + 1;
+   }
    mask = Elements(table(api)) - 1;
    hash = (pname * prime_factor);
    while (1) {
@@ -1626,7 +1663,7 @@ _mesa_GetBooleani_v( GLenum pname, GLuint index, GLboolean *params )
 {
    union value v;
    enum value_type type =
-      find_value_indexed("glGetBooleanIndexedv", pname, index, &v);
+      find_value_indexed("glGetBooleani_v", pname, index, &v);
 
    switch (type) {
    case TYPE_INT:
@@ -1651,7 +1688,7 @@ _mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params )
 {
    union value v;
    enum value_type type =
-      find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
+      find_value_indexed("glGetIntegeri_v", pname, index, &v);
 
    switch (type) {
    case TYPE_INT:
@@ -1672,11 +1709,11 @@ _mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params )
 }
 
 void GLAPIENTRY
-_mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params )
+_mesa_GetInteger64i_v( GLenum pname, GLuint index, GLint64 *params )
 {
    union value v;
    enum value_type type =
-      find_value_indexed("glGetIntegerIndexedv", pname, index, &v);      
+      find_value_indexed("glGetInteger64i_v", pname, index, &v);
 
    switch (type) {
    case TYPE_INT:
diff --git a/mesalib/src/mesa/main/get.h b/mesalib/src/mesa/main/get.h
index 4daa1aec1..6b0158f37 100644
--- a/mesalib/src/mesa/main/get.h
+++ b/mesalib/src/mesa/main/get.h
@@ -60,7 +60,7 @@ extern void GLAPIENTRY
 _mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params );
 
 extern void GLAPIENTRY
-_mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params );
+_mesa_GetInteger64i_v( GLenum pname, GLuint index, GLint64 *params );
 
 extern void GLAPIENTRY
 _mesa_GetPointerv( GLenum pname, GLvoid **params );
diff --git a/mesalib/src/mesa/main/get_hash_generator.py b/mesalib/src/mesa/main/get_hash_generator.py
index 4b3f5f490..04bf9ffe6 100644
--- a/mesalib/src/mesa/main/get_hash_generator.py
+++ b/mesalib/src/mesa/main/get_hash_generator.py
@@ -44,7 +44,7 @@ prime_factor = 89
 prime_step = 281
 hash_table_size = 1024
 
-gl_apis=set(["GL", "GL_CORE", "GLES", "GLES2"])
+gl_apis=set(["GL", "GL_CORE", "GLES", "GLES2", "GLES3"])
 
 def print_header():
    print "typedef const unsigned short table_t[%d];\n" % (hash_table_size)
@@ -67,6 +67,7 @@ api_enum = [
    'GLES',
    'GLES2',
    'GL_CORE',
+   'GLES3', # Not in gl_api enum in mtypes.h
 ]
 
 def api_index(api):
@@ -166,6 +167,9 @@ def generate_hash_tables(enum_list, enabled_apis, param_descriptors):
 
          for api in valid_apis:
             add_to_hash_table(tables[api], hash_val, len(params))
+            # Also add GLES2 items to the GLES3 hash table
+            if api == "GLES2":
+               add_to_hash_table(tables["GLES3"], hash_val, len(params))
 
          params.append(["GL_" + enum_name, param[1]])
 
@@ -183,6 +187,8 @@ def opt_to_apis(feature):
    apis = set([_map[feature]])
    if "GL" in apis:
       apis.add("GL_CORE")
+   if "GLES2" in apis:
+      apis.add("GLES3")
 
    return apis
 
diff --git a/mesalib/src/mesa/main/get_hash_params.py b/mesalib/src/mesa/main/get_hash_params.py
index ac9c79cea..3db820a77 100644
--- a/mesalib/src/mesa/main/get_hash_params.py
+++ b/mesalib/src/mesa/main/get_hash_params.py
@@ -204,12 +204,6 @@ descriptor=[
   [ "TEXTURE_COORD_ARRAY_TYPE", "LOC_CUSTOM, TYPE_ENUM, offsetof(struct gl_client_array, Type), NO_EXTRA" ],
   [ "TEXTURE_COORD_ARRAY_STRIDE", "LOC_CUSTOM, TYPE_INT, offsetof(struct gl_client_array, Stride), NO_EXTRA" ],
 
-# GL_ARB_ES2_compatibility
-  [ "SHADER_COMPILER", "CONST(1), extra_ARB_ES2_compatibility" ],
-  [ "MAX_VARYING_VECTORS", "CONTEXT_INT(Const.MaxVarying), extra_ARB_ES2_compatibility" ],
-  [ "MAX_VERTEX_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_ES2_compatibility" ],
-  [ "MAX_FRAGMENT_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_ES2_compatibility" ],
-
 # GL_ARB_multitexture
   [ "MAX_TEXTURE_UNITS", "CONTEXT_INT(Const.MaxTextureUnits), NO_EXTRA" ],
   [ "CLIENT_ACTIVE_TEXTURE", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
@@ -232,15 +226,8 @@ descriptor=[
 # GL_OES_point_sprite
   [ "POINT_SPRITE_NV", "CONTEXT_BOOL(Point.PointSprite), extra_NV_point_sprite_ARB_point_sprite" ],
 
-# GL_ARB_fragment_shader
-  [ "MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB", "CONTEXT_INT(Const.FragmentProgram.MaxUniformComponents), extra_ARB_fragment_shader" ],
-
 # GL_ARB_vertex_shader
-  [ "MAX_VERTEX_UNIFORM_COMPONENTS_ARB", "CONTEXT_INT(Const.VertexProgram.MaxUniformComponents), extra_ARB_vertex_shader" ],
   [ "MAX_VARYING_FLOATS_ARB", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_vertex_shader" ],
-
-# GL_EXT_texture_lod_bias
-  [ "MAX_TEXTURE_LOD_BIAS_EXT", "CONTEXT_FLOAT(Const.MaxTextureLodBias), NO_EXTRA" ],
 ]},
 
 
@@ -317,6 +304,73 @@ descriptor=[
 
 # GL_NV_read_buffer
   [ "READ_BUFFER", "LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, extra_NV_read_buffer_api_gl" ],
+
+# GL_ARB_ES2_compatibility
+  [ "SHADER_COMPILER", "CONST(1), extra_ARB_ES2_compatibility_api_es2" ],
+  [ "MAX_VARYING_VECTORS", "CONTEXT_INT(Const.MaxVarying), extra_ARB_ES2_compatibility_api_es2" ],
+  [ "MAX_VERTEX_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_ES2_compatibility_api_es2" ],
+  [ "MAX_FRAGMENT_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_ES2_compatibility_api_es2" ],
+]},
+
+# GLES3 is not a typo.
+{ "apis": ["GL", "GLES", "GLES3", "GL_CORE"], "params": [
+# GL_EXT_texture_lod_bias
+  [ "MAX_TEXTURE_LOD_BIAS_EXT", "CONTEXT_FLOAT(Const.MaxTextureLodBias), NO_EXTRA" ],
+]},
+
+
+# Enums in  OpenGL and ES 3.0
+{ "apis": ["GL", "GL_CORE", "GLES3"], "params": [
+# GL 3.0 / GLES3
+  [ "NUM_EXTENSIONS", "LOC_CUSTOM, TYPE_INT, 0, extra_gl30_es3" ],
+  [ "MAJOR_VERSION", "LOC_CUSTOM, TYPE_INT, 0, extra_gl30_es3" ],
+  [ "MINOR_VERSION", "LOC_CUSTOM, TYPE_INT, 0, extra_gl30_es3" ],
+
+# GL_ARB_ES3_compatibility
+  [ "MAX_ELEMENT_INDEX", "CONTEXT_INT64(Const.MaxElementIndex), extra_ARB_ES3_compatibility_api_es3"],
+
+# GL_ARB_fragment_shader
+  [ "MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB", "CONTEXT_INT(Const.FragmentProgram.MaxUniformComponents), extra_ARB_fragment_shader" ],
+
+# GL_ARB_framebuffer_object
+  [ "MAX_SAMPLES", "CONTEXT_INT(Const.MaxSamples), extra_ARB_framebuffer_object_EXT_framebuffer_multisample" ],
+
+# GL_ARB_sync
+  [ "MAX_SERVER_WAIT_TIMEOUT", "CONTEXT_INT64(Const.MaxServerWaitTimeout), extra_ARB_sync" ],
+
+# GL_ARB_transform_feedback2
+  [ "TRANSFORM_FEEDBACK_BUFFER_PAUSED", "LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_ARB_transform_feedback2_api_es3" ],
+  [ "TRANSFORM_FEEDBACK_BUFFER_ACTIVE", "LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_ARB_transform_feedback2_api_es3" ],
+  [ "TRANSFORM_FEEDBACK_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_transform_feedback2_api_es3" ],
+
+# GL_ARB_uniform_buffer_object
+  [ "MAX_VERTEX_UNIFORM_BLOCKS", "CONTEXT_INT(Const.VertexProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object" ],
+  [ "MAX_FRAGMENT_UNIFORM_BLOCKS", "CONTEXT_INT(Const.FragmentProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object" ],
+  [ "MAX_COMBINED_UNIFORM_BLOCKS", "CONTEXT_INT(Const.MaxCombinedUniformBlocks), extra_ARB_uniform_buffer_object" ],
+  [ "MAX_UNIFORM_BLOCK_SIZE", "CONTEXT_INT(Const.MaxUniformBlockSize), extra_ARB_uniform_buffer_object" ],
+  [ "MAX_UNIFORM_BUFFER_BINDINGS", "CONTEXT_INT(Const.MaxUniformBufferBindings), extra_ARB_uniform_buffer_object" ],
+  [ "MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.VertexProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object" ],
+  [ "MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.FragmentProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object" ],
+  [ "UNIFORM_BUFFER_OFFSET_ALIGNMENT", "CONTEXT_INT(Const.UniformBufferOffsetAlignment), extra_ARB_uniform_buffer_object" ],
+  [ "UNIFORM_BUFFER_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_uniform_buffer_object" ],
+
+# GL_ARB_vertex_shader
+  [ "MAX_VERTEX_UNIFORM_COMPONENTS_ARB", "CONTEXT_INT(Const.VertexProgram.MaxUniformComponents), extra_ARB_vertex_shader" ],
+
+# GL_EXT_framebuffer_blit
+# NOTE: GL_DRAW_FRAMEBUFFER_BINDING_EXT == GL_FRAMEBUFFER_BINDING_EXT
+  [ "READ_FRAMEBUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_framebuffer_blit" ],
+
+# GL_EXT_pixel_buffer_object
+  [ "PIXEL_PACK_BUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_pixel_buffer_object" ],
+  [ "PIXEL_UNPACK_BUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_pixel_buffer_object" ],
+
+# GL_EXT_transform_feedback
+  [ "TRANSFORM_FEEDBACK_BUFFER_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_transform_feedback" ],
+  [ "RASTERIZER_DISCARD", "CONTEXT_BOOL(RasterDiscard), extra_EXT_transform_feedback" ],
+  [ "MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", "CONTEXT_INT(Const.MaxTransformFeedbackInterleavedComponents), extra_EXT_transform_feedback" ],
+  [ "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", "CONTEXT_INT(Const.MaxTransformFeedbackBuffers), extra_EXT_transform_feedback" ],
+  [ "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS", "CONTEXT_INT(Const.MaxTransformFeedbackSeparateComponents), extra_EXT_transform_feedback" ],
 ]},
 
 { "apis": ["GLES", "GLES2"], "params": [
@@ -327,10 +381,6 @@ descriptor=[
 
 # Enums unique to OpenGL ES 2.0
 { "apis": ["GLES2"], "params": [
-  [ "MAX_FRAGMENT_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
-  [ "MAX_VARYING_VECTORS", "CONTEXT_INT(Const.MaxVarying), NO_EXTRA" ],
-  [ "MAX_VERTEX_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
-  [ "SHADER_COMPILER", "CONST(1), NO_EXTRA" ],
 # OES_get_program_binary
   [ "NUM_SHADER_BINARY_FORMATS", "CONST(0), NO_EXTRA" ],
   [ "SHADER_BINARY_FORMATS", "CONST(0), NO_EXTRA" ],
@@ -536,10 +586,6 @@ descriptor=[
   [ "SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB", "LOC_CUSTOM, TYPE_INT, offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_COLOR1].BufferObj), NO_EXTRA" ],
   [ "FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB", "LOC_CUSTOM, TYPE_INT, offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_FOG].BufferObj), NO_EXTRA" ],
 
-# GL_EXT_pixel_buffer_object
-  [ "PIXEL_PACK_BUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_pixel_buffer_object" ],
-  [ "PIXEL_UNPACK_BUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_pixel_buffer_object" ],
-
 # GL_ARB_vertex_program
 # == GL_VERTEX_PROGRAM_NV
   [ "VERTEX_PROGRAM_ARB", "CONTEXT_BOOL(VertexProgram.Enabled), extra_ARB_vertex_program" ],
@@ -580,38 +626,16 @@ descriptor=[
   [ "NUM_LOOPBACK_COMPONENTS_ATI", "CONST(3), extra_ATI_fragment_shader" ],
   [ "NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI", "CONST(3), extra_ATI_fragment_shader" ],
 
-# GL_EXT_framebuffer_blit
-# NOTE: GL_DRAW_FRAMEBUFFER_BINDING_EXT == GL_FRAMEBUFFER_BINDING_EXT
-  [ "READ_FRAMEBUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_framebuffer_blit" ],
-
 # GL_EXT_provoking_vertex
   [ "PROVOKING_VERTEX_EXT", "CONTEXT_ENUM(Light.ProvokingVertex), extra_EXT_provoking_vertex" ],
   [ "QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT", "CONTEXT_BOOL(Const.QuadsFollowProvokingVertexConvention), extra_EXT_provoking_vertex" ],
 
-# GL_ARB_framebuffer_object
-  [ "MAX_SAMPLES", "CONTEXT_INT(Const.MaxSamples), extra_ARB_framebuffer_object_EXT_framebuffer_multisample" ],
-
 # GL_ARB_seamless_cube_map
   [ "TEXTURE_CUBE_MAP_SEAMLESS", "CONTEXT_BOOL(Texture.CubeMapSeamless), extra_ARB_seamless_cube_map" ],
 
-# GL_ARB_sync
-  [ "MAX_SERVER_WAIT_TIMEOUT", "CONTEXT_INT64(Const.MaxServerWaitTimeout), extra_ARB_sync" ],
-
 # GL_EXT_texture_integer
   [ "RGBA_INTEGER_MODE_EXT", "BUFFER_BOOL(_IntegerColor), extra_EXT_texture_integer" ],
 
-# GL_EXT_transform_feedback
-  [ "TRANSFORM_FEEDBACK_BUFFER_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_transform_feedback" ],
-  [ "RASTERIZER_DISCARD", "CONTEXT_BOOL(RasterDiscard), extra_EXT_transform_feedback" ],
-  [ "MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", "CONTEXT_INT(Const.MaxTransformFeedbackInterleavedComponents), extra_EXT_transform_feedback" ],
-  [ "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", "CONTEXT_INT(Const.MaxTransformFeedbackBuffers), extra_EXT_transform_feedback" ],
-  [ "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS", "CONTEXT_INT(Const.MaxTransformFeedbackSeparateComponents), extra_EXT_transform_feedback" ],
-
-# GL_ARB_transform_feedback2
-  [ "TRANSFORM_FEEDBACK_BUFFER_PAUSED", "LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_ARB_transform_feedback2" ],
-  [ "TRANSFORM_FEEDBACK_BUFFER_ACTIVE", "LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_ARB_transform_feedback2" ],
-  [ "TRANSFORM_FEEDBACK_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_transform_feedback2" ],
-
 # GL_ARB_transform_feedback3
   [ "MAX_TRANSFORM_FEEDBACK_BUFFERS", "CONTEXT_INT(Const.MaxTransformFeedbackBuffers), extra_ARB_transform_feedback3" ],
   [ "MAX_VERTEX_STREAMS", "CONTEXT_INT(Const.MaxVertexStreams), extra_ARB_transform_feedback3" ],
@@ -642,9 +666,6 @@ descriptor=[
   [ "SAMPLER_BINDING", "LOC_CUSTOM, TYPE_INT, GL_SAMPLER_BINDING, NO_EXTRA" ],
 
 # GL 3.0
-  [ "NUM_EXTENSIONS", "LOC_CUSTOM, TYPE_INT, 0, extra_version_30" ],
-  [ "MAJOR_VERSION", "LOC_CUSTOM, TYPE_INT, 0, extra_version_30" ],
-  [ "MINOR_VERSION", "LOC_CUSTOM, TYPE_INT, 0, extra_version_30" ],
   [ "CONTEXT_FLAGS", "CONTEXT_INT(Const.ContextFlags), extra_version_30" ],
 
 # GL3.0 / GL_EXT_framebuffer_sRGB
@@ -671,17 +692,8 @@ descriptor=[
   [ "MAX_DUAL_SOURCE_DRAW_BUFFERS", "CONTEXT_INT(Const.MaxDualSourceDrawBuffers), extra_ARB_blend_func_extended" ],
 
 # GL_ARB_uniform_buffer_object
-  [ "MAX_VERTEX_UNIFORM_BLOCKS", "CONTEXT_INT(Const.VertexProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object" ],
-  [ "MAX_FRAGMENT_UNIFORM_BLOCKS", "CONTEXT_INT(Const.FragmentProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object" ],
   [ "MAX_GEOMETRY_UNIFORM_BLOCKS", "CONTEXT_INT(Const.GeometryProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object_and_geometry_shader" ],
-  [ "MAX_COMBINED_UNIFORM_BLOCKS", "CONTEXT_INT(Const.MaxCombinedUniformBlocks), extra_ARB_uniform_buffer_object" ],
-  [ "MAX_UNIFORM_BLOCK_SIZE", "CONTEXT_INT(Const.MaxUniformBlockSize), extra_ARB_uniform_buffer_object" ],
-  [ "MAX_UNIFORM_BUFFER_BINDINGS", "CONTEXT_INT(Const.MaxUniformBufferBindings), extra_ARB_uniform_buffer_object" ],
-  [ "MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.VertexProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object" ],
-  [ "MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.FragmentProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object" ],
   [ "MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.GeometryProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object_and_geometry_shader" ],
-  [ "UNIFORM_BUFFER_OFFSET_ALIGNMENT", "CONTEXT_INT(Const.UniformBufferOffsetAlignment), extra_ARB_uniform_buffer_object" ],
-  [ "UNIFORM_BUFFER_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_uniform_buffer_object" ],
 
 # GL_ARB_timer_query
   [ "TIMESTAMP", "LOC_CUSTOM, TYPE_INT64, 0, extra_ARB_timer_query" ],
diff --git a/mesalib/src/mesa/main/macros.h b/mesalib/src/mesa/main/macros.h
index 14a5d5fe1..d1e81fe08 100644
--- a/mesalib/src/mesa/main/macros.h
+++ b/mesalib/src/mesa/main/macros.h
@@ -656,6 +656,19 @@ INTERP_4F(GLfloat t, GLfloat dst[4], const GLfloat out[4], const GLfloat in[4])
 #define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
 #define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
 
+/**
+ * Align a value up to an alignment value
+ *
+ * If \c value is not already aligned to the requested alignment value, it
+ * will be rounded up.
+ *
+ * \param value  Value to be rounded
+ * \param alignment  Alignment value to be used.  This must be a power of two.
+ *
+ * \sa ROUND_DOWN_TO()
+ */
+#define ALIGN(value, alignment)  (((value) + alignment - 1) & ~(alignment - 1))
+
 
 
 /** Cross product of two 3-element vectors */
diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h
index 7c513a1c5..318dcb548 100644
--- a/mesalib/src/mesa/main/mtypes.h
+++ b/mesalib/src/mesa/main/mtypes.h
@@ -2962,6 +2962,17 @@ struct gl_constants
     * Drivers that support transform feedback must set this value to GL_FALSE.
     */
    GLboolean DisableVaryingPacking;
+
+   /*
+    * Maximum value supported for an index in DrawElements and friends.
+    *
+    * This must be at least (1ull<<24)-1.  The default value is
+    * (1ull<<32)-1.
+    *
+    * \since ES 3.0 or GL_ARB_ES3_compatibility
+    * \sa _mesa_init_constants
+    */
+   GLuint64 MaxElementIndex;
 };
 
 
@@ -3358,6 +3369,7 @@ typedef enum
    API_OPENGLES,
    API_OPENGLES2,
    API_OPENGL_CORE,
+   API_OPENGL_LAST = API_OPENGL_CORE,
 } gl_api;
 
 /**
diff --git a/mesalib/src/mesa/program/.gitignore b/mesalib/src/mesa/program/.gitignore
index bc48ef673..4c20872e1 100644
--- a/mesalib/src/mesa/program/.gitignore
+++ b/mesalib/src/mesa/program/.gitignore
@@ -1,4 +1,3 @@
-/Makefile
 program_parse.output
 lex.yy.c
 program_parse.tab.c
diff --git a/mesalib/src/mesa/program/Makefile.am b/mesalib/src/mesa/program/Makefile.am
index ea412f56f..1b8204658 100644
--- a/mesalib/src/mesa/program/Makefile.am
+++ b/mesalib/src/mesa/program/Makefile.am
@@ -35,7 +35,7 @@ DRICORE_LIB = libdricore_program.la
 endif
 
 noinst_LTLIBRARIES = $(DRICORE_LIB)
-if HAVE_GALLIUM
+if NEED_LIBPROGRAM
 noinst_LTLIBRARIES += libprogram.la
 else
 check_LTLIBRARIES = libprogram.la
diff --git a/mesalib/src/mesa/state_tracker/Makefile b/mesalib/src/mesa/state_tracker/Makefile
deleted file mode 100644
index 0ab1dc6e6..000000000
--- a/mesalib/src/mesa/state_tracker/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-default:
-	cd ../.. ; make
\ No newline at end of file
diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c
index 02fc675ae..7f07b741e 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_texture.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c
@@ -759,7 +759,7 @@ fallback_copy_texsubimage(struct gl_context *ctx,
    struct st_context *st = st_context(ctx);
    struct pipe_context *pipe = st->pipe;
    struct pipe_transfer *src_trans;
-   GLvoid *texDest;
+   GLubyte *texDest;
    enum pipe_transfer_usage transfer_usage;
    void *map;
    unsigned dst_width = width;
@@ -884,7 +884,7 @@ fallback_copy_texsubimage(struct gl_context *ctx,
                         texImage->_BaseFormat, 
                         texImage->TexFormat, 
                         dstRowStride,
-                        (GLubyte **) &texDest,
+                        &texDest,
                         width, height, 1,
                         GL_RGBA, GL_FLOAT, tempSrc, /* src */
                         &unpack);
diff --git a/mesalib/src/mesa/x86/.gitignore b/mesalib/src/mesa/x86/.gitignore
index ba7486c0b..ca3130d9f 100644
--- a/mesalib/src/mesa/x86/.gitignore
+++ b/mesalib/src/mesa/x86/.gitignore
@@ -1,3 +1,2 @@
-Makefile
 gen_matypes
 matypes.h
diff --git a/mkfontscale/mkfontscale.c b/mkfontscale/mkfontscale.c
index 53c53031b..b27bb6a5d 100644
--- a/mkfontscale/mkfontscale.c
+++ b/mkfontscale/mkfontscale.c
@@ -25,6 +25,7 @@
 #include <string.h>
 
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <dirent.h>
 #include <unistd.h>
 #include <errno.h>
@@ -826,6 +827,9 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
     while((entry = readdir(dirp)) != NULL) {
         int have_face = 0;
         char *xlfd_name = NULL;
+	struct stat f_stat;
+	int tprio = 1;
+
         xlfd = NULL;
 
 	if (xl) {
@@ -836,6 +840,19 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
 
         filename = dsprintf("%s%s", dirname, entry->d_name);
 
+#define PRIO(x) ((x << 1) + tprio)
+#ifdef DT_LNK
+	if (entry->d_type != DT_UNKNOWN) {
+	    if (entry->d_type == DT_LNK)
+		tprio = 0;
+	} else
+#endif
+	{
+	    if (lstat(filename, &f_stat))
+		goto done;
+	    if (S_ISLNK(f_stat.st_mode))
+		tprio = 0;
+	}
         if(doBitmaps)
             rc = bitmapIdentify(filename, &xlfd_name);
         else
@@ -896,7 +913,7 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
                 xlfd = listCons(s, xlfd);
             } else {
                 /* Not a reencodable font -- skip all the rest of the loop body */
-                putHash(entries, xlfd_name, entry->d_name, filePrio(entry->d_name));
+                putHash(entries, xlfd_name, entry->d_name, PRIO(filePrio(entry->d_name)));
                 goto done;
             }
         }
@@ -930,7 +947,7 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
                     found = 1;
                     snprintf(buf, MAXFONTNAMELEN, "%s-%s",
                             lp->value, encoding->value);
-                    putHash(entries, buf, entry->d_name, filePrio(entry->d_name));
+                    putHash(entries, buf, entry->d_name, PRIO(filePrio(entry->d_name)));
                 }
             }
             for(encoding = extra_encodings; encoding;
@@ -939,7 +956,7 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
                     /* Do not set found! */
                     snprintf(buf, MAXFONTNAMELEN, "%s-%s",
                             lp->value, encoding->value);
-                    putHash(entries, buf, entry->d_name, filePrio(entry->d_name));
+                    putHash(entries, buf, entry->d_name, PRIO(filePrio(entry->d_name)));
                 }
             }
         }
@@ -949,6 +966,7 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
         deepDestroyList(xlfd);
         xlfd = NULL;
         free(filename);
+#undef PRIO
     }
 
     closedir(dirp);
diff --git a/xorg-server/hw/xfree86/modes/xf86Crtc.c b/xorg-server/hw/xfree86/modes/xf86Crtc.c
index 13251cff4..b3ded5a33 100644
--- a/xorg-server/hw/xfree86/modes/xf86Crtc.c
+++ b/xorg-server/hw/xfree86/modes/xf86Crtc.c
@@ -2605,6 +2605,7 @@ xf86SetDesiredModes(ScrnInfoPtr scrn)
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
     xf86CrtcPtr crtc = config->crtc[0];
     int c;
+    int enabled = 0;
 
     /* A driver with this hook will take care of this */
     if (!crtc->funcs->set_mode_major) {
@@ -2655,14 +2656,20 @@ xf86SetDesiredModes(ScrnInfoPtr scrn)
             transform = &crtc->desiredTransform;
         else
             transform = NULL;
-        if (!xf86CrtcSetModeTransform
+        if (xf86CrtcSetModeTransform
             (crtc, &crtc->desiredMode, crtc->desiredRotation, transform,
-             crtc->desiredX, crtc->desiredY))
-            return FALSE;
+             crtc->desiredX, crtc->desiredY)) {
+            ++enabled;
+        } else {
+            for (o = 0; o < config->num_output; o++)
+                if (config->output[o]->crtc == crtc)
+                    config->output[o]->crtc = NULL;
+            crtc->enabled = FALSE;
+	}
     }
 
     xf86DisableUnusedFunctions(scrn);
-    return TRUE;
+    return enabled != 0;
 }
 
 /**
diff --git a/xorg-server/include/dixstruct.h b/xorg-server/include/dixstruct.h
index c1236f5c9..678481920 100644
--- a/xorg-server/include/dixstruct.h
+++ b/xorg-server/include/dixstruct.h
@@ -90,12 +90,12 @@ typedef struct _Client {
     Mask clientAsMask;
     short index;
     unsigned char majorOp, minorOp;
-    int swapped:1;
-    int local:1;
-    int big_requests:1;          /* supports large requests */
-    int clientGone:1;
-    int closeDownMode:2;
-    int clientState:2;
+    unsigned int swapped:1;
+    unsigned int local:1;
+    unsigned int big_requests:1; /* supports large requests */
+    unsigned int clientGone:1;
+    unsigned int closeDownMode:2;
+    unsigned int clientState:2;
     char smart_priority;
     short noClientException;      /* this client died or needs to be killed */
     int priority;
-- 
cgit v1.2.3