--- src/uxa/intel_batchbuffer.h	Wed Nov 12 13:45:44 2014
+++ src/uxa/intel_batchbuffer.h	Wed Nov 12 13:46:57 2014
@@ -30,7 +30,8 @@
 #ifndef _INTEL_BATCHBUFFER_H
 #define _INTEL_BATCHBUFFER_H
 
-#define BATCH_RESERVED		16
+#define BATCH_RESERVED4K	4096
+#define BATCH_RESERVED16	16
 
 
 void intel_batch_init(ScrnInfoPtr scrn);
@@ -40,7 +41,10 @@
 
 static inline int intel_batch_space(intel_screen_private *intel)
 {
-	return (intel->batch_bo->size - BATCH_RESERVED) - (4*intel->batch_used);
+       if (IS_I865G(intel))
+           return (intel->batch_bo->size - BATCH_RESERVED16) - (4*intel->batch_used);
+       else
+           return (intel->batch_bo->size - BATCH_RESERVED4K) - (4*intel->batch_used);
 }
 
 static inline int intel_vertex_space(intel_screen_private *intel)
--- configure.ac	Wed Nov 12 13:47:32 2014
+++ configure.ac	Wed Nov 12 13:47:51 2014
@@ -791,7 +791,11 @@
 AC_SEARCH_LIBS(clock_gettime, rt, [CLOCK_GETTIME_LIBS=$LIBS])
 AC_SUBST(CLOCK_GETTIME_LIBS)
 
-sdkdir=`$PKG_CONFIG --variable=sdkdir xorg-server`
+AC_ARG_WITH(xorg-sdk-dir,
+       AC_HELP_STRING([--with-xorg-sdk-dir=DIR],
+       [Default xorg sdk include directory [[default is taken from pkgconfig]]]),
+       [sdkdir="$withval"],
+       [sdkdir=$(pkg-config --variable=sdkdir xorg-server)])
 
 AM_CONDITIONAL(DEBUG, test "x$DEBUG" != "xno")
 AM_CONDITIONAL(FULL_DEBUG, test "x$DEBUG" = "xfull")
--- src/legacy/Makefile.am	Wed Nov 12 14:12:28 2014
+++ src/legacy/Makefile.am	Wed Nov 12 14:13:04 2014
@@ -1,10 +1,20 @@
 SUBDIRS =
 noinst_LTLIBRARIES = liblegacy.la
 
-NULL:=#
+#NULL:=#
 
 liblegacy_la_SOURCES = legacy.h
 liblegacy_la_LIBADD =
+liblegacy_la_SOURCES = legacy.h \
+                      i810/i810_accel.c \
+                      i810/i810_cursor.c \
+                      i810/i810_dga.c \
+                      i810/i810_dri.c \
+                      i810/i810_driver.c \
+                      i810/i810_hwmc.c \
+                      i810/i810_memory.c \
+                      i810/i810_video.c \
+                      i810/i810_wmark.c
 
 if UMS
 SUBDIRS += i810
--- src/legacy/i810/i810.h	Wed Nov 12 14:33:23 2014
+++ src/legacy/i810/i810.h	Wed Nov 12 14:33:38 2014
@@ -53,7 +53,7 @@
 #include "xorg-server.h"
 #include <pciaccess.h>
 
-#include "compat-api.h"
+#include "../../compat-api.h"
 #ifdef HAVE_DRI1
 #include "xf86drm.h"
 #include "sarea.h"
@@ -65,7 +65,7 @@
 #include "i810_common.h"
 #include "i810_ring.h"
 
-#include "intel_driver.h"
+#include "../../intel_driver.h"
 
 /* HWMC Surfaces */
 #define I810_MAX_SURFACES 7
--- src/legacy/i810/Makefile.am	Wed Nov 12 14:41:37 2014
+++ src/legacy/i810/Makefile.am	Wed Nov 12 14:42:00 2014
@@ -5,6 +5,7 @@
 AM_CFLAGS = $(CWARNFLAGS) $(XORG_CFLAGS) $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) \
 	    -I$(top_srcdir)/src \
 	    -I$(top_srcdir)/src/legacy \
+	    -I/usr/include/xorg \
 	    $(NULL)
 
 liblegacy_i810_la_SOURCES = \
--- src/backlight.c	Fri Nov 14 11:36:24 2014
+++ src/backlight.c	Fri Nov 14 11:36:41 2014
@@ -33,6 +33,7 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <sys/sysmacros.h>
 
 #include <stdio.h>
 #include <stdlib.h>
--- src/legacy/Makefile.am	Fri Nov 14 11:40:51 2014
+++ src/legacy/Makefile.am	Fri Nov 14 11:41:09 2014
@@ -16,6 +16,9 @@
                       i810/i810_video.c \
                       i810/i810_wmark.c
 
+AM_CFLAGS = @XORG_CFLAGS@ @DRM_CFLAGS@ -I$(top_srcdir)/src
+liblegacy_la_LIBADD = @DRM_LIBS@ @XVMCLIB_LIBS@
+
 if UMS
 SUBDIRS += i810
 liblegacy_la_SOURCES +=
--- src/uxa/Makefile.am Fri Nov 14 09:47:49 2014
+++ src/uxa/Makefile.am Fri Nov 14 09:50:01 2014
@@ -24,6 +24,9 @@

 noinst_LTLIBRARIES = libuxa.la
 libuxa_la_LIBADD = $(UDEV_LIBS) $(DRMINTEL_LIBS) $(DRM_LIBS)
+
+libuxa_la_LIBADD += $(XORG_EXTERNS_FLAG) -lfb -lshadowfb -lm \
+                       -lvbe -lvgahw -ldrm $(XORG_LIBS)
 libuxa_la_SOURCES = \
        brw_defines.h \
        brw_structs.h \
--- src/Makefile.am	Fri Nov 14 12:02:25 2014
+++ src/Makefile.am	Fri Nov 14 12:03:02 2014
@@ -42,6 +42,9 @@
 intel_drv_la_LDFLAGS = -module -avoid-version
 intel_drv_ladir = $(moduledir)/drivers
 intel_drv_la_LIBADD = legacy/liblegacy.la $(PCIACCESS_LIBS) $(XORG_LIBS)
+intel_drv_la_LDFLAGS += -R $(moduledir)
+intel_drv_la_LIBADD += $(XORG_EXTERNS_FLAG) -lfb -lshadowfb -lm \
+       -lvbe -lvgahw -lexa $(XORG_LIBS)
 
 if SNA
 SUBDIRS += sna
@@ -53,7 +56,7 @@
 intel_drv_la_LIBADD += uxa/libuxa.la
 endif
 
-NULL:=#
+#NULL:=#
 
 intel_drv_la_SOURCES = \
 	backlight.c \
--- src/compat-api.h	Tue Apr 26 16:19:10 2016
+++ src/compat-api.h	Tue Apr 26 16:20:11 2016
@@ -175,6 +175,10 @@
 }
 #endif
 
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,17,99,0,0)
+#define PixmapSyncDirtyHelper(d, dd) PixmapSyncDirtyHelper(d)
+#endif
+
 #if !HAS_DIXREGISTERPRIVATEKEY
 #define dixPrivateKeyRegistered(key__) (*(key__) != 0)
 #endif
