pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

start a Mesa 13 package



Module Name:	pkgsrc-wip
Committed By:	Tobias Nygren <tnn%NetBSD.org@localhost>
Pushed By:	tnn
Date:		Mon Nov 21 05:14:50 2016 +0100
Changeset:	52f6bf3d4284afed5dd9a278983b9b41d71ced5d

Added Files:
	MesaLib/DESCR
	MesaLib/Makefile
	MesaLib/PLIST
	MesaLib/TODO
	MesaLib/buildlink3.mk
	MesaLib/builtin.mk
	MesaLib/distinfo
	MesaLib/dri.mk
	MesaLib/files/patch-manual_fdo90311
	MesaLib/options.mk
	MesaLib/patches-todo/patch-configure
	MesaLib/patches-todo/patch-src_loader_Makefile.in
	MesaLib/patches-todo/patch-src_loader_loader.c
	MesaLib/patches-todo/patch-src_mapi_entry__x86-64__tls.h
	MesaLib/patches-todo/patch-src_mapi_entry__x86__tls.h
	MesaLib/patches/patch-configure
	MesaLib/patches/patch-include_GL_glxext.h
	MesaLib/patches/patch-src_compiler_glsl_glsl__parser__extras.cpp
	MesaLib/patches/patch-src_egl_drivers_dri2_platform__drm.c
	MesaLib/patches/patch-src_egl_drivers_dri2_platform__x11.c
	MesaLib/patches/patch-src_egl_main_eglglobals.c
	MesaLib/patches/patch-src_gallium_auxiliary_util_u__format__tests.c
	MesaLib/patches/patch-src_gallium_auxiliary_util_u__math.h
	MesaLib/patches/patch-src_gallium_auxiliary_util_u__network.c
	MesaLib/patches/patch-src_gallium_auxiliary_util_u__network.h
	MesaLib/patches/patch-src_gallium_drivers_nouveau_codegen_nv50__ir__peephole.cpp
	MesaLib/patches/patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c
	MesaLib/patches/patch-src_gallium_drivers_nouveau_nv50_nv84__video.c
	MesaLib/patches/patch-src_gallium_targets_dri_Makefile.in
	MesaLib/patches/patch-src_gallium_winsys_radeon_drm_radeon__drm__winsys.c
	MesaLib/patches/patch-src_gallium_winsys_svga_drm_vmw__screen__ioctl.c
	MesaLib/patches/patch-src_glsl_ralloc.c
	MesaLib/patches/patch-src_glx_apple_apple__glapi.c
	MesaLib/patches/patch-src_glx_glxclient.h
	MesaLib/patches/patch-src_glx_glxcurrent.c
	MesaLib/patches/patch-src_mapi_glapi_gen_gl__gentable.py
	MesaLib/patches/patch-src_mapi_u__current.c
	MesaLib/patches/patch-src_mapi_u__current.h
	MesaLib/patches/patch-src_mesa_drivers_dri_Makefile.in
	MesaLib/patches/patch-src_mesa_drivers_dri_common_Makefile.in
	MesaLib/patches/patch-src_mesa_drivers_dri_common_xmlconfig.c
	MesaLib/patches/patch-src_mesa_drivers_dri_i915_intel__screen.c
	MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__screen.c
	MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__tiled__memcpy.c
	MesaLib/patches/patch-src_mesa_drivers_dri_swrast_swrast.c
	MesaLib/patches/patch-src_mesa_main_context.c
	MesaLib/patches/patch-src_mesa_main_extensions.c
	MesaLib/patches/patch-src_mesa_main_macros.h
	MesaLib/patches/patch-src_mesa_main_shader__query.cpp
	MesaLib/patches/patch-src_mesa_tnl_t__pipeline.c
	MesaLib/patches/patch-src_mesa_x86_common__x86.c
	MesaLib/patches/patch-src_util_strndup.c
	MesaLib/patches/patch-src_util_strndup.h
	MesaLib/patches/patch-src_util_u__atomic.h

Log Message:
start a Mesa 13 package

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=52f6bf3d4284afed5dd9a278983b9b41d71ced5d

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 MesaLib/DESCR                                      |   5 +
 MesaLib/Makefile                                   | 108 +++++++++++
 MesaLib/PLIST                                      |  64 +++++++
 MesaLib/TODO                                       |   6 +
 MesaLib/buildlink3.mk                              |  52 ++++++
 MesaLib/builtin.mk                                 |  87 +++++++++
 MesaLib/distinfo                                   |  45 +++++
 MesaLib/dri.mk                                     |  44 +++++
 MesaLib/files/patch-manual_fdo90311                | 111 ++++++++++++
 MesaLib/options.mk                                 | 200 +++++++++++++++++++++
 MesaLib/patches-todo/patch-configure               | 161 +++++++++++++++++
 MesaLib/patches-todo/patch-src_loader_Makefile.in  |  24 +++
 MesaLib/patches-todo/patch-src_loader_loader.c     |  82 +++++++++
 .../patch-src_mapi_entry__x86-64__tls.h            |  40 +++++
 .../patches-todo/patch-src_mapi_entry__x86__tls.h  |  48 +++++
 MesaLib/patches/patch-configure                    |  35 ++++
 MesaLib/patches/patch-include_GL_glxext.h          |  17 ++
 ...atch-src_compiler_glsl_glsl__parser__extras.cpp |  15 ++
 .../patch-src_egl_drivers_dri2_platform__drm.c     |  16 ++
 .../patch-src_egl_drivers_dri2_platform__x11.c     |  30 ++++
 MesaLib/patches/patch-src_egl_main_eglglobals.c    |  40 +++++
 ...h-src_gallium_auxiliary_util_u__format__tests.c |  17 ++
 .../patch-src_gallium_auxiliary_util_u__math.h     |  31 ++++
 .../patch-src_gallium_auxiliary_util_u__network.c  |  33 ++++
 .../patch-src_gallium_auxiliary_util_u__network.h  |  15 ++
 ..._drivers_nouveau_codegen_nv50__ir__peephole.cpp |  25 +++
 ...c_gallium_drivers_nouveau_nouveau__vp3__video.c |  18 ++
 ...-src_gallium_drivers_nouveau_nv50_nv84__video.c |  18 ++
 .../patch-src_gallium_targets_dri_Makefile.in      |  15 ++
 ...gallium_winsys_radeon_drm_radeon__drm__winsys.c |  18 ++
 ...rc_gallium_winsys_svga_drm_vmw__screen__ioctl.c |  32 ++++
 MesaLib/patches/patch-src_glsl_ralloc.c            |  39 ++++
 MesaLib/patches/patch-src_glx_apple_apple__glapi.c |  24 +++
 MesaLib/patches/patch-src_glx_glxclient.h          |  19 ++
 MesaLib/patches/patch-src_glx_glxcurrent.c         |  40 +++++
 .../patch-src_mapi_glapi_gen_gl__gentable.py       |  15 ++
 MesaLib/patches/patch-src_mapi_u__current.c        |  31 ++++
 MesaLib/patches/patch-src_mapi_u__current.h        |  16 ++
 .../patches/patch-src_mesa_drivers_dri_Makefile.in |  15 ++
 .../patch-src_mesa_drivers_dri_common_Makefile.in  |  16 ++
 .../patch-src_mesa_drivers_dri_common_xmlconfig.c  |  50 ++++++
 ...patch-src_mesa_drivers_dri_i915_intel__screen.c |  39 ++++
 ...patch-src_mesa_drivers_dri_i965_intel__screen.c |  39 ++++
 ...rc_mesa_drivers_dri_i965_intel__tiled__memcpy.c |  20 +++
 .../patch-src_mesa_drivers_dri_swrast_swrast.c     |  19 ++
 MesaLib/patches/patch-src_mesa_main_context.c      |  41 +++++
 MesaLib/patches/patch-src_mesa_main_extensions.c   |  24 +++
 MesaLib/patches/patch-src_mesa_main_macros.h       |  16 ++
 .../patches/patch-src_mesa_main_shader__query.cpp  |  48 +++++
 MesaLib/patches/patch-src_mesa_tnl_t__pipeline.c   |  20 +++
 MesaLib/patches/patch-src_mesa_x86_common__x86.c   |  24 +++
 MesaLib/patches/patch-src_util_strndup.c           |  30 ++++
 MesaLib/patches/patch-src_util_strndup.h           |  15 ++
 MesaLib/patches/patch-src_util_u__atomic.h         |  30 ++++
 54 files changed, 2082 insertions(+)

diffs:
diff --git a/MesaLib/DESCR b/MesaLib/DESCR
new file mode 100644
index 0000000..8a8cccf
--- /dev/null
+++ b/MesaLib/DESCR
@@ -0,0 +1,5 @@
+MesaLib is a 3-D graphics library with an API which is very similar to
+that of OpenGL*.  To the extent that Mesa utilizes the OpenGL command syntax
+or state machine, it is being used with authorization from Silicon Graphics,
+Inc.  However, the author makes no claim that Mesa is in any way a
+compatible replacement for OpenGL or associated with Silicon Graphics, Inc.
diff --git a/MesaLib/Makefile b/MesaLib/Makefile
new file mode 100644
index 0000000..6ff3770
--- /dev/null
+++ b/MesaLib/Makefile
@@ -0,0 +1,108 @@
+# $NetBSD: Makefile,v 1.129 2016/10/20 12:06:06 wiz Exp $
+
+DISTNAME=	mesa-13.0.1
+PKGNAME=	${DISTNAME:S/mesa/MesaLib/}
+CATEGORIES=	graphics x11
+MASTER_SITES=	ftp://ftp.freedesktop.org/pub/mesa/${PKGVERSION_NOREV}/
+EXTRACT_SUFX=	.tar.xz
+
+MAINTAINER=	pkgsrc-users%NetBSD.org@localhost
+HOMEPAGE=	http://www.mesa3d.org/
+COMMENT=	The Mesa 3D Graphics Library
+LICENSE=	mit
+
+GNU_CONFIGURE=	yes
+USE_TOOLS+=	bison pkg-config gmake flex
+USE_LANGUAGES=	c99 c++
+USE_LIBTOOL=	yes
+
+GCC_REQD+=	4.2
+
+PKGCONFIG_OVERRIDE+=	src/egl/main/egl.pc.in
+PKGCONFIG_OVERRIDE+=	src/egl/wayland/wayland-egl/wayland-egl.pc.in
+PKGCONFIG_OVERRIDE+=	src/gallium/targets/d3dadapter9/d3d.pc.in
+PKGCONFIG_OVERRIDE+=	src/gallium/targets/osmesa/osmesa.pc.in
+PKGCONFIG_OVERRIDE+=	src/gallium/targets/xa/xatracker.pc.in
+PKGCONFIG_OVERRIDE+=	src/gbm/main/gbm.pc.in
+PKGCONFIG_OVERRIDE+=	src/mapi/es1api/glesv1_cm.pc.in
+PKGCONFIG_OVERRIDE+=	src/mapi/es2api/glesv2.pc.in
+PKGCONFIG_OVERRIDE+=	src/mesa/drivers/dri/dri.pc.in
+PKGCONFIG_OVERRIDE+=	src/mesa/drivers/osmesa/osmesa.pc.in
+PKGCONFIG_OVERRIDE+=	src/mesa/gl.pc.in
+
+CONFIGURE_ARGS+=		--enable-shared-glapi
+
+# Work around a buildlink and/or libtool bug:
+# In the libtool install/relink stage, if we want to link with two static
+# archives named libglapi.la but in different directories, bad things happen.
+SUBST_CLASSES+=			wrapper-bug
+SUBST_STAGE.wrapper-bug=	pre-configure
+SUBST_MESSAGE.wrapper-bug=	Renaming glapi-shared/libglapi in Makefiles
+SUBST_FILES.wrapper-bug=	src/gbm/Makefile.in
+SUBST_FILES.wrapper-bug+=	src/glx/Makefile.in
+SUBST_FILES.wrapper-bug+=	src/mapi/Makefile.in
+SUBST_FILES.wrapper-bug+=	src/mesa/drivers/x11/Makefile.in
+SUBST_SED.wrapper-bug=		-e 's,shared-glapi/libglapi.la,shared-glapi/libglapi_tmp_rename.la,g'
+SUBST_SED.wrapper-bug+=		-e 's,libglapi.la,libglapi_impl.la,g'
+SUBST_SED.wrapper-bug+=		-e 's,libglapi_tmp_rename.la,libglapi.la,g'
+
+# Replace /etc/drirc with ${PREFIX}/etc/drirc
+SUBST_CLASSES+=			drirc
+SUBST_STAGE.drirc=		pre-configure
+SUBST_MESSAGE.drirc=		Fixing hardcoded /etc/drirc references
+SUBST_FILES.drirc+=		src/mesa/drivers/dri/common/xmlconfig.c
+SUBST_SED.drirc+=		 -e 's|/etc/|${PREFIX}/etc/|g'
+
+.include "../../mk/bsd.prefs.mk"
+.include "../../mk/compiler.mk"
+.include "options.mk"
+
+.if !empty(PKGSRC_COMPILER:Mclang)
+SUBST_CLASSES+=		tr1
+SUBST_STAGE.tr1=	pre-configure
+SUBST_MESSAGE.tr1=	Fixing TR1 C++ namespace
+SUBST_FILES.tr1=	src/gallium/drivers/nouveau/codegen/*.h
+SUBST_FILES.tr1+=	src/gallium/drivers/nouveau/codegen/*.cpp
+SUBST_SED.tr1=		-e 's,std::tr1::,std::,g'
+SUBST_SED.tr1+=		-e 's,include <tr1/,include <,g'
+.endif
+
+PYTHON_FOR_BUILD_ONLY=	yes
+PYTHON_VERSIONS_INCOMPATIBLE=	34 35 # as of 11.2.2
+BUILD_DEPENDS+=		${PYPKGPREFIX}-mako-[0-9]*:../../devel/py-mako
+CONFIGURE_ENV+=		ac_cv_prog_PYTHON2=${PYTHONBIN}
+.include "../../lang/python/tool.mk"
+
+# On NetBSD < 6 we need to compile with GCC from pkgsrc.
+# But GCC from pkgsrc does not add implicit -lc like base GCC does,
+# which breaks the build with -Wl,--no-undefined.
+# So we piggy back on -lpthread and inject -lc after it.
+.if !empty(MACHINE_PLATFORM:MNetBSD-[1-5].*-*)
+BUILDLINK_TRANSFORM+=   l:pthread:pthread:c l:m:m:c
+.endif
+
+# Handle platforms without exp2
+.if !empty(MACHINE_PLATFORM:MNetBSD-[1-5].*-*)
+CPPFLAGS+=	-Dexp2\(x\)=exp\(\(x\)\*M_LN2\)
+CPPFLAGS+=	-Dexp2f\(x\)=expf\(\(x\)\*M_LN2\)
+.endif
+
+# Manual patch for FDO bug 90311. Don't apply if not on Darwin as there could
+# be side effects.
+.if ${OPSYS} == "Darwin"
+pre-configure: ${WRKDIR}/.manual_patch_done
+${WRKDIR}/.manual_patch_done:
+	cd ${WRKSRC} && ${TOOLS_PATCH} -z .manual -p0 < ${FILESDIR}/patch-manual_fdo90311
+	touch ${.TARGET}
+.endif
+
+INSTALLATION_DIRS+=	share/examples/MesaLib
+
+post-install:
+	${INSTALL_DATA} ${WRKSRC}/src/mesa/drivers/dri/common/drirc ${DESTDIR}${PREFIX}/share/examples/MesaLib
+
+.include "../../wip/libpthread-stubs/buildlink3.mk"
+.include "../../x11/libX11/buildlink3.mk"
+.include "../../x11/libXext/buildlink3.mk"
+.include "../../x11/libxcb/buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/MesaLib/PLIST b/MesaLib/PLIST
new file mode 100644
index 0000000..62ec282
--- /dev/null
+++ b/MesaLib/PLIST
@@ -0,0 +1,64 @@
+@comment $NetBSD: PLIST,v 1.33 2016/02/23 14:40:36 tnn Exp $
+${PLIST.dri}include/EGL/egl.h
+${PLIST.dri}include/EGL/eglext.h
+${PLIST.dri}include/EGL/eglextchromium.h
+${PLIST.dri}include/EGL/eglmesaext.h
+${PLIST.dri}include/EGL/eglplatform.h
+include/GL/gl.h
+include/GL/gl_mangle.h
+include/GL/glcorearb.h
+include/GL/glext.h
+include/GL/glx.h
+include/GL/glx_mangle.h
+include/GL/glxext.h
+${PLIST.dri}include/GL/internal/dri_interface.h
+${PLIST.dri}include/GLES/egl.h
+${PLIST.dri}include/GLES/gl.h
+${PLIST.dri}include/GLES/glext.h
+${PLIST.dri}include/GLES/glplatform.h
+${PLIST.dri}include/GLES2/gl2.h
+${PLIST.dri}include/GLES2/gl2ext.h
+${PLIST.dri}include/GLES2/gl2platform.h
+${PLIST.dri}include/GLES3/gl3.h
+${PLIST.dri}include/GLES3/gl31.h
+${PLIST.dri}include/GLES3/gl32.h
+${PLIST.dri}include/GLES3/gl3ext.h
+${PLIST.dri}include/GLES3/gl3platform.h
+${PLIST.dri}include/KHR/khrplatform.h
+${PLIST.gbm}include/gbm.h
+${PLIST.xatracker}include/xa_composite.h
+${PLIST.xatracker}include/xa_context.h
+${PLIST.xatracker}include/xa_tracker.h
+${PLIST.i915_dri}lib/dri/i915_dri.so
+${PLIST.i965_dri}lib/dri/i965_dri.so
+${PLIST.ilo}lib/dri/ilo_dri.so
+${PLIST.freedreno}lib/dri/kgsl_dri.so
+${PLIST.swrast}lib/dri/kms_swrast_dri.so
+${PLIST.freedreno}lib/dri/msm_dri.so
+${PLIST.nouveau}lib/dri/nouveau_dri.so
+${PLIST.nouveau_dri}lib/dri/nouveau_vieux_dri.so
+${PLIST.r200_dri}lib/dri/r200_dri.so
+${PLIST.r300}lib/dri/r300_dri.so
+${PLIST.r600}lib/dri/r600_dri.so
+${PLIST.radeon_dri}lib/dri/radeon_dri.so
+${PLIST.radeonsi}lib/dri/radeonsi_dri.so
+${PLIST.swrast_dri}lib/dri/swrast_dri.so
+${PLIST.vc4}lib/dri/vc4_dri.so
+${PLIST.svga}lib/dri/vmwgfx_dri.so
+${PLIST.dri}lib/libEGL.la
+lib/libGL.la
+${PLIST.dri}lib/libGLESv1_CM.la
+${PLIST.dri}lib/libGLESv2.la
+${PLIST.gbm}lib/libgbm.la
+lib/libglapi.la
+${PLIST.wayland}lib/libwayland-egl.la
+${PLIST.xatracker}lib/libxatracker.la
+${PLIST.dri}lib/pkgconfig/dri.pc
+${PLIST.dri}lib/pkgconfig/egl.pc
+${PLIST.gbm}lib/pkgconfig/gbm.pc
+lib/pkgconfig/gl.pc
+${PLIST.dri}lib/pkgconfig/glesv1_cm.pc
+${PLIST.dri}lib/pkgconfig/glesv2.pc
+${PLIST.wayland}lib/pkgconfig/wayland-egl.pc
+${PLIST.xatracker}lib/pkgconfig/xatracker.pc
+share/examples/MesaLib/drirc
diff --git a/MesaLib/TODO b/MesaLib/TODO
new file mode 100644
index 0000000..8dbc118
--- /dev/null
+++ b/MesaLib/TODO
@@ -0,0 +1,6 @@
+investigate applicability of FreeBSD DEVQ patch
+fix bitrot that broke GLX TLS on NetBSD
+test OSX quartz, check if bug 90311 patch needs regen
+test Solaris
+test Linux
+test NetBSD 7
diff --git a/MesaLib/buildlink3.mk b/MesaLib/buildlink3.mk
new file mode 100644
index 0000000..3fff25b
--- /dev/null
+++ b/MesaLib/buildlink3.mk
@@ -0,0 +1,52 @@
+# $NetBSD: buildlink3.mk,v 1.54 2015/09/27 21:58:03 tnn Exp $
+
+BUILDLINK_TREE+=	MesaLib
+
+.if !defined(MESALIB_BUILDLINK3_MK)
+MESALIB_BUILDLINK3_MK:=
+
+BUILDLINK_API_DEPENDS.MesaLib+=	MesaLib>=3.4.2
+BUILDLINK_ABI_DEPENDS.MesaLib+=	MesaLib>=7.11.2
+BUILDLINK_PKGSRCDIR.MesaLib?=	../../graphics/MesaLib
+
+.include "../../mk/bsd.fast.prefs.mk"
+
+.if ${X11_TYPE} == "modular"
+BUILDLINK_ABI_DEPENDS.MesaLib+=	MesaLib>=13
+# This is needed to avoid linking conflicting libstdc++ versions
+.if defined(USE_LANGUAGES) && !empty(USE_LANGUAGES:Mc++)
+GCC_REQD+=	4.2
+.endif
+.endif
+
+# See <http://developer.apple.com/qa/qa2007/qa1567.html>.
+.if ${X11_TYPE} == "native" && !empty(MACHINE_PLATFORM:MDarwin-[9].*-*)
+BUILDLINK_LDFLAGS.MesaLib+=	-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib
+.endif
+
+pkgbase:= MesaLib
+.include "../../mk/pkg-build-options.mk"
+
+.if ${X11_TYPE} == "native" && ${OPSYS} != "Cygwin" && exists(${X11BASE}/lib/pkgconfig/dri.pc)
+PKG_BUILD_OPTIONS.MesaLib+=	dri
+.endif
+
+.if !empty(PKG_BUILD_OPTIONS.MesaLib:Mdri)
+.  include "../../graphics/MesaLib/dri.mk"
+.endif
+
+.if	${X11_TYPE} == "modular" && !empty(PKG_BUILD_OPTIONS.MesaLib:Mdri) ||	\
+	${X11_TYPE} == "native"  && exists(${X11BASE}/include/EGL/egl.h)
+MESALIB_SUPPORTS_EGL=	yes
+.else
+MESALIB_SUPPORTS_EGL=	no
+.endif
+
+.include "../../x11/libXext/buildlink3.mk"
+.if ${X11_TYPE} == "modular"
+.include "../../wip/libpthread-stubs/buildlink3.mk"
+.endif
+
+.endif # MESALIB_BUILDLINK3_MK
+
+BUILDLINK_TREE+=	-MesaLib
diff --git a/MesaLib/builtin.mk b/MesaLib/builtin.mk
new file mode 100644
index 0000000..1e7d558
--- /dev/null
+++ b/MesaLib/builtin.mk
@@ -0,0 +1,87 @@
+# $NetBSD: builtin.mk,v 1.20 2014/03/22 08:19:24 jperkin Exp $
+
+BUILTIN_PKG:=	MesaLib
+
+BUILTIN_FIND_FILES_VAR:=	H_MESALIB PC_GL
+BUILTIN_FIND_FILES.H_MESALIB=	${X11BASE}/include/GL/glx.h
+BUILTIN_FIND_FILES.PC_GL=	${X11BASE}/lib/pkgconfig/gl.pc
+BUILTIN_FIND_FILES.PC_GL+=	${X11BASE}/lib${LIBABISUFFIX}/pkgconfig/gl.pc
+
+.include "../../mk/buildlink3/bsd.builtin.mk"
+
+###
+### Determine if there is a built-in implementation of the package and
+### set IS_BUILTIN.<pkg> appropriately ("yes" or "no").
+###
+.if !defined(IS_BUILTIN.MesaLib)
+.  if empty(PC_GL:M__nonexistent__)
+IS_BUILTIN.MesaLib=	yes
+.  elif empty(H_MESALIB:M__nonexistent__)
+IS_BUILTIN.MesaLib=	yes
+.  else
+IS_BUILTIN.MesaLib=	no
+.  endif
+.endif
+MAKEVARS+=	IS_BUILTIN.MesaLib
+
+###
+### If there is a built-in implementation, then set BUILTIN_PKG.<pkg> to
+### a package name to represent the built-in package.
+###
+.if !defined(BUILTIN_PKG.MesaLib) && \
+    !empty(IS_BUILTIN.MesaLib:M[yY][eE][sS])
+.  if empty(PC_GL:M__nonexistent__)
+BUILTIN_VERSION.Mesa!= ${SED} -n -e 's/Version: //p' ${PC_GL}
+.  elif empty(H_MESALIB:M__nonexistent__)
+.    include "../../graphics/Mesa/version.mk"
+.  else # ?
+BUILTIN_VERSION.Mesa:= 0.something-weird-happened
+.  endif
+BUILTIN_PKG.MesaLib=	MesaLib-${BUILTIN_VERSION.Mesa}
+MAKEVARS+=	BUILTIN_VERSION.Mesa
+.endif
+MAKEVARS+=	BUILTIN_PKG.MesaLib
+
+###
+### Determine whether we should use the built-in implementation if it
+### exists, and set USE_BUILTIN.<pkg> appropriate ("yes" or "no").
+###
+.if !defined(USE_BUILTIN.MesaLib)
+.  if ${PREFER.MesaLib} == "pkgsrc"
+USE_BUILTIN.MesaLib=	no
+.  else
+USE_BUILTIN.MesaLib=	${IS_BUILTIN.MesaLib}
+.    if defined(BUILTIN_PKG.MesaLib) && \
+        !empty(IS_BUILTIN.MesaLib:M[yY][eE][sS])
+USE_BUILTIN.MesaLib=	yes
+.      for dep in ${BUILDLINK_API_DEPENDS.MesaLib}
+.        if !empty(USE_BUILTIN.MesaLib:M[yY][eE][sS])
+USE_BUILTIN.MesaLib!=							\
+	if ${PKG_ADMIN} pmatch ${dep:Q} ${BUILTIN_PKG.MesaLib:Q}; then \
+		${ECHO} yes;						\
+	else								\
+		${ECHO} no;						\
+	fi
+.        endif
+.      endfor
+.    endif
+.  endif  # PREFER.MesaLib
+.endif
+MAKEVARS+=	USE_BUILTIN.MesaLib
+
+###
+### The section below only applies if we are not including this file
+### solely to determine whether a built-in implementation exists.
+###
+CHECK_BUILTIN.MesaLib?=	no
+.if !empty(CHECK_BUILTIN.MesaLib:M[nN][oO])
+
+.  if !empty(USE_BUILTIN.MesaLib:M[nN][oO])
+.    include "../../mk/pthread.buildlink3.mk"
+.    include "../../mk/pthread.builtin.mk"
+BUILTIN_PKG:=	MesaLib
+.  endif
+
+.  include "../../mk/x11.builtin.mk"
+
+.endif	# CHECK_BUILTIN.MesaLib
diff --git a/MesaLib/distinfo b/MesaLib/distinfo
new file mode 100644
index 0000000..ef639ee
--- /dev/null
+++ b/MesaLib/distinfo
@@ -0,0 +1,45 @@
+$NetBSD: distinfo,v 1.117 2016/05/18 12:55:28 wiz Exp $
+
+SHA1 (mesa-13.0.1.tar.xz) = 13a6f25b8f66ec788293cbbebb2d2bd7e9cc6195
+RMD160 (mesa-13.0.1.tar.xz) = 884012a4a2c68bf982f4b546b03a8f46ac8932fe
+SHA512 (mesa-13.0.1.tar.xz) = 00ae0eaef742a3954c1461b50cdcc8b9f933e829c89784d66bfcc0890e7e2793350efcad1a06f28bd3c115f04702a43a6f1ac6ce86270ca7799a90f1a5cf5127
+Size (mesa-13.0.1.tar.xz) = 9154288 bytes
+SHA1 (patch-configure) = 619e7b3e70f8f20f5ac61fafe6bb0b87e16a1693
+SHA1 (patch-include_GL_glxext.h) = 830902f2d38a8395cda682c059fc5223e1b0e89e
+SHA1 (patch-src_compiler_glsl_glsl__parser__extras.cpp) = c5046ce848d0b1ea428e29611b6822d4f4ab970d
+SHA1 (patch-src_egl_drivers_dri2_platform__drm.c) = 75144a5c2cbcda3f7ccd708ff2ac03c823c045d7
+SHA1 (patch-src_egl_drivers_dri2_platform__x11.c) = 04b6ef8e755f226fbe3e6f2bea6c9e2a56a783ca
+SHA1 (patch-src_egl_main_eglglobals.c) = 194954826564d1053544a88c771019faf4d07df2
+SHA1 (patch-src_gallium_auxiliary_util_u__format__tests.c) = 4d5e4677c2825778c43440ab131b8807f6840975
+SHA1 (patch-src_gallium_auxiliary_util_u__math.h) = 812e4a5291aea47e06505f09891e0434c4d9c34d
+SHA1 (patch-src_gallium_auxiliary_util_u__network.c) = 283f505af780071dc9fd7914f8065e3fb7d8a4fd
+SHA1 (patch-src_gallium_auxiliary_util_u__network.h) = c6106d67b4fa9db0d790474182d6e0ce0c5da677
+SHA1 (patch-src_gallium_drivers_nouveau_codegen_nv50__ir__peephole.cpp) = 5fc2ef7eafac3006896af96bac8176c79b17cfdc
+SHA1 (patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c) = ae1b6eb4df3e4db0f37e44118cdf69b16f3c471e
+SHA1 (patch-src_gallium_drivers_nouveau_nv50_nv84__video.c) = 1b4239fe053523835ecac006894bdb0cde0ee626
+SHA1 (patch-src_gallium_targets_dri_Makefile.in) = a9a8265d97297040a3e3260b362ca920ec852280
+SHA1 (patch-src_gallium_winsys_radeon_drm_radeon__drm__winsys.c) = 94e05c38ab2a8d2bcc25dd477cbd1fd5d681182a
+SHA1 (patch-src_gallium_winsys_svga_drm_vmw__screen__ioctl.c) = e4b891e8b4ebe5b8e8c7b8c2c1dbed11b9c417df
+SHA1 (patch-src_glsl_ralloc.c) = 63c8e40b9f74404033c20c5c9a00c5f6d8df6433
+SHA1 (patch-src_glx_apple_apple__glapi.c) = df70afc24759978f954ac3a774a14e6518dde97a
+SHA1 (patch-src_glx_glxclient.h) = e15256851559dafb7a86e1eb7e9d6afc86de581b
+SHA1 (patch-src_glx_glxcurrent.c) = 713f75bcafb186c7123d19a6aae3deaed9d5fa69
+SHA1 (patch-src_mapi_glapi_gen_gl__gentable.py) = 53026e520a510e54494760a3fa05af6f15dfb9d8
+SHA1 (patch-src_mapi_u__current.c) = 1731375d82119be326b35d141d7879e083d6d620
+SHA1 (patch-src_mapi_u__current.h) = 214dd29cb0c4fe127eb1157b04b12ddfc455b4b0
+SHA1 (patch-src_mesa_drivers_dri_Makefile.in) = 2fb1471045ae88eaa4fca162bf86330b833167fd
+SHA1 (patch-src_mesa_drivers_dri_common_Makefile.in) = 5e160f7d92c2e9f3fa36e52a082a496af67e634e
+SHA1 (patch-src_mesa_drivers_dri_common_xmlconfig.c) = b87644c5ef5fb5d71c3260026d3afdfbaee749a8
+SHA1 (patch-src_mesa_drivers_dri_i915_intel__screen.c) = fd8436e4e3a69250256c2cddf8138effb16bd7b3
+SHA1 (patch-src_mesa_drivers_dri_i965_intel__screen.c) = 7c1a1e5c549f64d4c390e0c87984c44a88d4abfe
+SHA1 (patch-src_mesa_drivers_dri_i965_intel__tiled__memcpy.c) = c0d465fb65939ead71c9d02b6f6793824dbf441d
+SHA1 (patch-src_mesa_drivers_dri_swrast_swrast.c) = b8a6cca517e1cccbdb2c59cf67a6d2481cdfebd4
+SHA1 (patch-src_mesa_main_context.c) = 695b0e04cbd08dfed46b4dae5f9602b35e21f5b3
+SHA1 (patch-src_mesa_main_extensions.c) = d650d7ddfe22ddbcd8a4c24b64feb27126521ae0
+SHA1 (patch-src_mesa_main_macros.h) = e0e98dff37bbf96fea2f3adf0dc9ef9911b711d9
+SHA1 (patch-src_mesa_main_shader__query.cpp) = 6273c74161f045363c58f38adeb672287f6a0898
+SHA1 (patch-src_mesa_tnl_t__pipeline.c) = afc7d5f27aeadacc7c6a762e5aa892e01a0c1317
+SHA1 (patch-src_mesa_x86_common__x86.c) = bdac91384d67ad0238ecd4cdcf5cfc787952a3d9
+SHA1 (patch-src_util_strndup.c) = b8dfae71f1b219e44f884b8fc6f89a86201353c3
+SHA1 (patch-src_util_strndup.h) = a48a0ebefbc79a770db4baa590d3f858bb52cacf
+SHA1 (patch-src_util_u__atomic.h) = 4a567b6fe5bf67fb7f386fa5f37bedb66d593085
diff --git a/MesaLib/dri.mk b/MesaLib/dri.mk
new file mode 100644
index 0000000..68eb95d
--- /dev/null
+++ b/MesaLib/dri.mk
@@ -0,0 +1,44 @@
+# $NetBSD: dri.mk,v 1.16 2016/03/10 05:29:56 tnn Exp $
+#
+# Currently, this is for convenience only.
+#
+.if !defined(DRI_MK)
+DRI_MK=		# defined
+
+.  if !defined(USE_BUILTIN.MesaLib)
+CHECK_BUILTIN.MesaLib:=	yes
+.    include "../../graphics/MesaLib/builtin.mk"
+CHECK_BUILTIN.MesaLib:=	no
+.  endif
+
+.  if !empty(USE_BUILTIN.MesaLib:M[Nn][Oo])
+BUILDLINK_API_DEPENDS.dri2proto+=	dri2proto>=2.1
+BUILDLINK_API_DEPENDS.glproto+=		glproto>=1.4.11
+.    if ${OPSYS} != "Darwin"
+BUILDLINK_API_DEPENDS.libdrm+=		libdrm>=2.4.60
+.    endif
+.    if ${OPSYS} == "Linux"
+BUILDLINK_API_DEPENDS.libxcb+=	libxcb>=1.9.3
+.    endif
+.  endif
+.  include "../../textproc/expat/buildlink3.mk"
+.  include "../../x11/dri2proto/buildlink3.mk"
+# XXX these do not have builtin.mk
+.  if ${X11_TYPE} == "modular"
+.    include "../../x11/dri3proto/buildlink3.mk"
+.    include "../../x11/libxshmfence/buildlink3.mk"
+.    include "../../x11/presentproto/buildlink3.mk"
+.  endif
+.  include "../../x11/glproto/buildlink3.mk"
+.  include "../../x11/libXdamage/buildlink3.mk"
+.  include "../../x11/libXfixes/buildlink3.mk"
+.  include "../../x11/libXxf86vm/buildlink3.mk"
+.  if ${OPSYS} != "Darwin"
+.    include "../../x11/libdrm/buildlink3.mk"
+.  endif
+.  include "../../x11/xf86driproto/buildlink3.mk"
+.  include "../../x11/xf86vidmodeproto/buildlink3.mk"
+.  if ${OPSYS} == "FreeBSD" || ${OPSYS} == "DragonFly"
+.    include "../../devel/libdevq/buildlink3.mk"
+.  endif
+.endif
diff --git a/MesaLib/files/patch-manual_fdo90311 b/MesaLib/files/patch-manual_fdo90311
new file mode 100644
index 0000000..845ab87
--- /dev/null
+++ b/MesaLib/files/patch-manual_fdo90311
@@ -0,0 +1,111 @@
+$NetBSD: patch-manual_fdo90311,v 1.2 2016/01/18 17:59:01 jperkin Exp $
+
+https://bugs.freedesktop.org/show_bug.cgi?id=90311
+
+Regenerated with autoconf to link with C++ linker using this addition:
+
+libglx_la_LIBADD += $(builddir)/apple/libappleglx.la + $(top_builddir)/src/mesa/libmesa.la
+nodist_EXTRA_lib@GL_LIB@_la_SOURCES = dummy.cpp
+
+and then dummy.cpp manuallly edited out.
+
+--- src/glx/Makefile.in.orig	2015-12-15 14:52:32.000000000 +0000
++++ src/glx/Makefile.in
+@@ -143,7 +143,7 @@ target_triplet = @target@
+ @HAVE_APPLEDRI_TRUE@	applegl_glx.c
+ 
+ @HAVE_APPLEDRI_TRUE@am__append_7 = apple
+-@HAVE_APPLEDRI_TRUE@am__append_8 = $(builddir)/apple/libappleglx.la
++@HAVE_APPLEDRI_TRUE@am__append_8 = $(builddir)/apple/libappleglx.la $(top_builddir)/src/mesa/libmesa.la
+ subdir = src/glx
+ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_gnu_make.m4 \
+@@ -202,10 +202,10 @@ AM_V_lt = $(am__v_lt_@AM_V@)
+ am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+ am__v_lt_0 = --silent
+ am__v_lt_1 = 
+-lib@GL_LIB@_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+-	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+-	$(AM_CFLAGS) $(CFLAGS) $(lib@GL_LIB@_la_LDFLAGS) $(LDFLAGS) -o \
+-	$@
++lib@GL_LIB@_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
++	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
++	$(AM_CXXFLAGS) $(CXXFLAGS) $(lib@GL_LIB@_la_LDFLAGS) \
++	$(LDFLAGS) -o $@
+ libglx_la_DEPENDENCIES = $(top_builddir)/src/loader/libloader.la \
+ 	$(am__append_5) $(am__append_8)
+ am__libglx_la_SOURCES_DIST = clientattrib.c clientinfo.c compsize.c \
+@@ -276,6 +276,24 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+ am__v_CCLD_0 = @echo "  CCLD    " $@;
+ am__v_CCLD_1 = 
++CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
++	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
++LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
++	$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
++	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
++	$(AM_CXXFLAGS) $(CXXFLAGS)
++AM_V_CXX = $(am__v_CXX_@AM_V@)
++am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
++am__v_CXX_0 = @echo "  CXX     " $@;
++am__v_CXX_1 = 
++CXXLD = $(CXX)
++CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
++	$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
++	$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
++AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
++am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
++am__v_CXXLD_0 = @echo "  CXXLD   " $@;
++am__v_CXXLD_1 = 
+ SOURCES = $(lib@GL_LIB@_la_SOURCES) $(libglx_la_SOURCES)
+ DIST_SOURCES = $(lib@GL_LIB@_la_SOURCES) $(am__libglx_la_SOURCES_DIST)
+ RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
+@@ -696,7 +714,7 @@ lib@GL_LIB@_la_LDFLAGS = $(GL_LDFLAGS)
+ all: all-recursive
+ 
+ .SUFFIXES:
+-.SUFFIXES: .c .lo .o .obj
++.SUFFIXES: .c .cpp .lo .o .obj
+ $(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(top_srcdir)/install-lib-links.mk $(am__configure_deps)
+ 	@for dep in $?; do \
+ 	  case '$(am__configure_deps)' in \
+@@ -775,7 +793,7 @@ clean-noinstLTLIBRARIES:
+ 	}
+ 
+ lib@GL_LIB@.la: $(lib@GL_LIB@_la_OBJECTS) $(lib@GL_LIB@_la_DEPENDENCIES) $(EXTRA_lib@GL_LIB@_la_DEPENDENCIES) 
+-	$(AM_V_CCLD)$(lib@GL_LIB@_la_LINK) -rpath $(libdir) $(lib@GL_LIB@_la_OBJECTS) $(lib@GL_LIB@_la_LIBADD) $(LIBS)
++	$(AM_V_CXXLD)$(lib@GL_LIB@_la_LINK) -rpath $(libdir) $(lib@GL_LIB@_la_OBJECTS) $(lib@GL_LIB@_la_LIBADD) $(LIBS)
+ 
+ libglx.la: $(libglx_la_OBJECTS) $(libglx_la_DEPENDENCIES) $(EXTRA_libglx_la_DEPENDENCIES) 
+ 	$(AM_V_CCLD)$(LINK)  $(libglx_la_OBJECTS) $(libglx_la_LIBADD) $(LIBS)
+@@ -852,6 +870,30 @@ distclean-compile:
+ @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+ 
++.cpp.o:
++@am__fastdepCXX_TRUE@	$(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
++@am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
++@am__fastdepCXX_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Po
++@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
++@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
++@am__fastdepCXX_FALSE@	$(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
++
++.cpp.obj:
++@am__fastdepCXX_TRUE@	$(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
++@am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
++@am__fastdepCXX_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Po
++@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
++@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
++@am__fastdepCXX_FALSE@	$(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
++
++.cpp.lo:
++@am__fastdepCXX_TRUE@	$(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
++@am__fastdepCXX_TRUE@	$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
++@am__fastdepCXX_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Plo
++@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
++@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
++@am__fastdepCXX_FALSE@	$(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
++
+ mostlyclean-libtool:
+ 	-rm -f *.lo
+ 
diff --git a/MesaLib/options.mk b/MesaLib/options.mk
new file mode 100644
index 0000000..3b17174
--- /dev/null
+++ b/MesaLib/options.mk
@@ -0,0 +1,200 @@
+# $NetBSD: options.mk,v 1.49 2016/02/25 13:37:46 jperkin Exp $
+
+PKG_OPTIONS_VAR=		PKG_OPTIONS.MesaLib
+PKG_SUPPORTED_OPTIONS=		llvm dri
+PKG_SUGGESTED_OPTIONS=
+
+# The LLVM option enables JIT accelerated software rendering and
+# is also required to support the latest RADEON GPUs, so enable it
+# by default on platforms where such GPUs might be encountered.
+.if \
+	!empty(MACHINE_PLATFORM:MNetBSD-[789].*-i386) ||	\
+	!empty(MACHINE_PLATFORM:MNetBSD-[789].*-x86_64) ||	\
+	!empty(MACHINE_PLATFORM:MNetBSD-[789].*-sparc64) ||	\
+	!empty(MACHINE_PLATFORM:MNetBSD-[789].*-*arm*)
+PKG_SUGGESTED_OPTIONS+=		llvm
+.endif
+
+.if	(!empty(MACHINE_PLATFORM:MLinux-*-i386) ||	\
+	 !empty(MACHINE_PLATFORM:MLinux-*-x86_64)) &&	\
+	(!empty(CC_VERSION:Mgcc-4.[89].*) ||		\
+	 !empty(CC_VERSION:Mgcc-[56].*))
+PKG_SUGGESTED_OPTIONS+=		llvm
+.endif
+
+.if ${OPSYS} == "FreeBSD" || ${OPSYS} == "OpenBSD" ||		\
+	${OPSYS} == "DragonFly" || ${OPSYS} == "Linux" ||	\
+	${OPSYS} == "SunOS" || ${OPSYS} == "NetBSD" ||		\
+	${OPSYS} == "Darwin"
+PKG_SUGGESTED_OPTIONS+=		dri
+.endif
+
+.include "../../mk/bsd.options.mk"
+
+# gallium
+PLIST_VARS+=	freedreno ilo i915 i965 nouveau r300 r600 radeonsi	\
+		swrast svga vc4 virgl
+# classic DRI
+PLIST_VARS+=	dri swrast_dri i915_dri nouveau_dri i965_dri radeon_dri r200_dri
+# other features
+PLIST_VARS+=	gbm wayland xatracker
+
+.if !empty(PKG_OPTIONS:Mdri)
+
+CONFIGURE_ARGS+=	--enable-dri
+CONFIGURE_ARGS+=	--enable-egl
+.if ${OPSYS} != "Darwin"
+CFLAGS+=		-DHAVE_DRI3
+CONFIGURE_ARGS+=	--enable-dri3
+CONFIGURE_ARGS+=	--enable-gbm
+PLIST.gbm=		yes
+.endif
+CONFIGURE_ARGS+=	--enable-gles1
+CONFIGURE_ARGS+=	--enable-gles2
+
+# Use Thread Local Storage in GLX where it is supported by Mesa and works.
+# XXX Fixme
+#	!empty(MACHINE_PLATFORM:MNetBSD-[789].*-i386) ||
+#	!empty(MACHINE_PLATFORM:MNetBSD-[789].*-x86_64) ||
+.if \
+	!empty(MACHINE_PLATFORM:MLinux-*-i386) ||		\
+	!empty(MACHINE_PLATFORM:MLinux-*-x86_64) ||		\
+	!empty(MACHINE_PLATFORM:MFreeBSD-1[0-9].*-x86_64) ||	\
+	!empty(MACHINE_PLATFORM:MDragonFly-*-x86_64)
+CONFIGURE_ARGS+=	--enable-glx-tls
+.else
+CONFIGURE_ARGS+=	--disable-glx-tls
+.endif
+
+# DRI on Linux needs either sysfs or udev
+CONFIGURE_ARGS.Linux+=	--enable-sysfs
+
+PLIST.dri=	yes
+
+.if ${OPSYS} != "Darwin"
+BUILDLINK_DEPMETHOD.libpciaccess=	full
+.include "../../sysutils/libpciaccess/buildlink3.mk"
+.endif
+.include "../../graphics/MesaLib/dri.mk"
+
+DRI_DRIVERS=		#
+GALLIUM_DRIVERS=	#
+
+# Software rasterizer
+PLIST.swrast_dri=	yes
+DRI_DRIVERS+=		swrast
+.if ${OPSYS} != "Darwin"
+PLIST.swrast=		yes
+GALLIUM_DRIVERS+=	swrast
+.endif
+
+# x86 only drivers
+.if (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64") && ${OPSYS} != "Darwin"
+# svga / VMWare driver
+PLIST.svga=		yes
+GALLIUM_DRIVERS+=	svga
+
+# Intel chipsets, x86 only
+PLIST.i915=		yes
+GALLIUM_DRIVERS+=	i915
+PLIST.i915_dri=		yes
+DRI_DRIVERS+=		i915
+
+# Experimental Intel driver
+PLIST.ilo=		yes
+GALLIUM_DRIVERS+=	ilo
+
+PLIST.i965_dri=		yes
+DRI_DRIVERS+=		i965
+.endif
+
+# ARM drivers
+.if !empty(MACHINE_PLATFORM:MNetBSD-*-*arm*)
+# Qualcomm SnapDragon, libdrm_freedreno.pc
+GALLIUM_DRIVERS+=	freedreno
+PLIST.freedreno=	yes
+
+# Broadcom VideoCore 4
+GALLIUM_DRIVERS+=	vc4
+PLIST.vc4=		yes
+.endif
+
+# qemu Linux guest driver
+.if !empty(MACHINE_PLATFORM:MLinux-*-x86_64)
+# XXX test this
+#GALLIUM_DRIVERS+=	virgl
+#PLIST.virgl=		yes
+.endif
+
+# theoretically cross platform PCI drivers, but don't build on ARM
+.if ${OPSYS} != "Darwin" && empty(MACHINE_PLATFORM:MNetBSD-*-*arm*)
+
+# AMD Radeon r600
+PLIST.r600=		yes
+GALLIUM_DRIVERS+=	r600
+
+# nVidia
+PLIST.nouveau=		yes
+GALLIUM_DRIVERS+=	nouveau
+
+# classic DRI radeon
+PLIST.radeon_dri=	yes
+DRI_DRIVERS+=		radeon
+
+# classic DRI r200
+PLIST.r200_dri=		yes
+DRI_DRIVERS+=		r200
+
+# classic DRI nouveau
+PLIST.nouveau_dri=	yes
+DRI_DRIVERS+=		nouveau
+.endif
+
+.if ${OPSYS} == "Darwin"
+CONFIGURE_ARGS+=	--with-egl-platforms=x11
+#.elif ${OPSYS} == "Linux"
+#.include "../../wip/wayland/buildlink3.mk"
+#CONFIGURE_ARGS+=	--with-egl-platforms=x11,drm,wayland
+#PLIST.wayland=		yes
+.else
+CONFIGURE_ARGS+=	--with-egl-platforms=x11,drm
+.endif
+
+CONFIGURE_ARGS+=	--with-gallium-drivers=${GALLIUM_DRIVERS:ts,}
+CONFIGURE_ARGS+=	--with-dri-drivers=${DRI_DRIVERS:ts,}
+
+.if !empty(PKG_OPTIONS:Mllvm)
+# XA is useful for accelerating xf86-video-vmware
+CONFIGURE_ARGS+=	--enable-xa
+PLIST.xatracker=	yes
+# AMD Radeon r300
+PLIST.r300=		yes
+GALLIUM_DRIVERS+=	r300
+# AMD Canary Islands GPUs
+PLIST.radeonsi=		yes
+GALLIUM_DRIVERS+=	radeonsi
+CONFIGURE_ARGS+=	--enable-gallium-llvm
+CONFIGURE_ARGS+=	--enable-r600-llvm-compiler
+.include "../../devel/libelf/buildlink3.mk"
+CPPFLAGS+=		-I${BUILDLINK_PREFIX.libelf}/include/libelf
+.include "../../lang/libLLVM/buildlink3.mk"
+CONFIGURE_ENV+=		ac_cv_path_ac_pt_LLVM_CONFIG=${LLVM_CONFIG_PATH}
+.else # !llvm
+CONFIGURE_ARGS+=	--disable-xa
+CONFIGURE_ARGS+=	--disable-gallium-llvm
+CONFIGURE_ARGS+=	--disable-r600-llvm-compiler
+.endif # llvm
+.else # !dri
+CONFIGURE_ARGS+=	--with-gallium-drivers=
+CONFIGURE_ARGS+=	--with-dri-drivers=
+CONFIGURE_ARGS+=	--disable-dri
+CONFIGURE_ARGS+=	--disable-dri3
+CONFIGURE_ARGS+=	--disable-egl
+CONFIGURE_ARGS+=	--disable-gbm
+CONFIGURE_ARGS+=	--disable-gles1
+CONFIGURE_ARGS+=	--disable-gles2
+CONFIGURE_ARGS+=	--enable-xlib-glx
+.if !empty(PKG_OPTIONS:Mllvm)
+PKG_FAIL_REASON+=	"The llvm PKG_OPTION must also be disabled when dri is disabled"
+.endif
+.endif
diff --git a/MesaLib/patches-todo/patch-configure b/MesaLib/patches-todo/patch-configure
new file mode 100644
index 0000000..beb84c4
--- /dev/null
+++ b/MesaLib/patches-todo/patch-configure
@@ -0,0 +1,161 @@
+$NetBSD: patch-configure,v 1.5 2016/02/12 11:49:53 tnn Exp $
+
+Add libdevq support from FreeBSD ports.
+
+--- configure.orig	2016-01-13 10:48:25.000000000 +0000
++++ configure
+@@ -860,6 +860,8 @@ GLPROTO_LIBS
+ GLPROTO_CFLAGS
+ XLIBGL_LIBS
+ XLIBGL_CFLAGS
++LIBDEVQ_LIBS
++LIBDEVQ_CFLAGS
+ LIBUDEV_LIBS
+ LIBUDEV_CFLAGS
+ ENABLE_SHADER_CACHE_FALSE
+@@ -1174,6 +1176,8 @@ OPENSSL_CFLAGS
+ OPENSSL_LIBS
+ LIBUDEV_CFLAGS
+ LIBUDEV_LIBS
++LIBDEVQ_CFLAGS
++LIBDEVQ_LIBS
+ XLIBGL_CFLAGS
+ XLIBGL_LIBS
+ GLPROTO_CFLAGS
+@@ -5287,6 +5291,7 @@ DRI2PROTO_REQUIRED=2.6
+ DRI3PROTO_REQUIRED=1.0
+ PRESENTPROTO_REQUIRED=1.0
+ LIBUDEV_REQUIRED=151
++LIBDEVQ_REQUIRED=0.0.2
+ GLPROTO_REQUIRED=1.4.14
+ LIBOMXIL_BELLAGIO_REQUIRED=0.0
+ LIBVA_REQUIRED=0.38.0
+@@ -20727,7 +20732,7 @@ _ACEOF
+ $as_echo_n "checking if more special flags are required for pthreads... " >&6; }
+         flag=no
+         case ${host_os} in
+-            aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";;
++            aix* | freebsd* | dragonfly* | darwin*) flag="-D_THREAD_SAFE";;
+             osf* | hpux*) flag="-D_REENTRANT";;
+             solaris*)
+             if test "$GCC" = "yes"; then
+@@ -22087,6 +22092,89 @@ else
+ fi
+ 
+ 
++
++# Check for libdevq
++
++pkg_failed=no
++{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBDEVQ" >&5
++$as_echo_n "checking for LIBDEVQ... " >&6; }
++if test -n "$LIBDEVQ_CFLAGS"; then
++    pkg_cv_LIBDEVQ_CFLAGS="$LIBDEVQ_CFLAGS"
++ elif test -n "$PKG_CONFIG"; then
++    if test -n "$PKG_CONFIG" && \
++    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists
++ --print-errors \"libdevq-1.0 >= \$LIBDEVQ_REQUIRED\""; } >&5
++  ($PKG_CONFIG --exists --print-errors "libdevq-1.0 >= $LIBDEVQ_REQUIRED") 2>&5
++  ac_status=$?
++  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
++  test $ac_status = 0; }; then
++  pkg_cv_LIBDEVQ_CFLAGS=`$PKG_CONFIG --cflags "libdevq-1.0 >=
++ $LIBDEVQ_REQUIRED" 2>/dev/null`
++              test "x$?" != "x0" && pkg_failed=yes
++else
++  pkg_failed=yes
++fi
++ else
++    pkg_failed=untried
++fi
++if test -n "$LIBDEVQ_LIBS"; then
++    pkg_cv_LIBDEVQ_LIBS="$LIBDEVQ_LIBS"
++ elif test -n "$PKG_CONFIG"; then
++    if test -n "$PKG_CONFIG" && \
++    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists
++ --print-errors \"libdevq-1.0 >= \$LIBDEVQ_REQUIRED\""; } >&5
++  ($PKG_CONFIG --exists --print-errors "libdevq-1.0 >= $LIBDEVQ_REQUIRED") 2>&5
++  ac_status=$?
++  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
++  test $ac_status = 0; }; then
++  pkg_cv_LIBDEVQ_LIBS=`$PKG_CONFIG --libs "libdevq-1.0 >=
++ $LIBDEVQ_REQUIRED" 2>/dev/null`
++              test "x$?" != "x0" && pkg_failed=yes
++else
++  pkg_failed=yes
++fi
++ else
++    pkg_failed=untried
++fi
++
++
++
++if test $pkg_failed = yes; then
++       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
++$as_echo "no" >&6; }
++
++if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
++        _pkg_short_errors_supported=yes
++else
++        _pkg_short_errors_supported=no
++fi
++        if test $_pkg_short_errors_supported = yes; then
++            LIBDEVQ_PKG_ERRORS=`$PKG_CONFIG --short-errors
++ --print-errors --cflags --libs "libdevq-1.0 >= $LIBDEVQ_REQUIRED"
++ 2>&1`
++        else
++            LIBDEVQ_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags
++ --libs "libdevq-1.0 >= $LIBDEVQ_REQUIRED" 2>&1`
++        fi
++    # Put the nasty error message in config.log where it belongs
++    echo "$LIBDEVQ_PKG_ERRORS" >&5
++
++    have_libdevq=no
++elif test $pkg_failed = untried; then
++         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
++$as_echo "no" >&6; }
++    have_libdevq=no
++else
++    LIBDEVQ_CFLAGS=$pkg_cv_LIBDEVQ_CFLAGS
++    LIBDEVQ_LIBS=$pkg_cv_LIBDEVQ_LIBS
++        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
++$as_echo "yes" >&6; }
++    have_libdevq=yes
++fi
++
++
++
++
+ if test "x$enable_dri" = xyes; then
+     if test "$enable_static" = yes; then
+         as_fn_error $? "Cannot use static libraries for DRI drivers" "$LINENO" 5
+@@ -22889,6 +22977,10 @@ if test "$have_sysfs" = yes; then
+     DEFINES="$DEFINES -DHAVE_SYSFS"
+     have_pci_id=yes
+ fi
++if test "$have_libdevq" = yes; then
++    DEFINES="$DEFINES -DHAVE_LIBDEVQ"
++    have_pci_id=yes
++fi
+ 
+ # This is outside the case (above) so that it is invoked even for non-GLX
+ # builds.
+@@ -23821,6 +23913,8 @@ fi
+ 
+ if test "x$need_pci_id$have_libudev" = xyesyes; then
+     GBM_PC_REQ_PRIV="libudev >= $LIBUDEV_REQUIRED"
++elif test "x$need_libdevq" = xyes; then
++    GBM_PC_REQ_PRIV="libdevq-1.0 >= $LIBDEVQ_REQUIRED"
+ else
+     GBM_PC_REQ_PRIV=""
+ fi
+@@ -25468,9 +25562,6 @@ fi
+                 CLANG_LIBDIR=${LLVM_LIBDIR}
+             fi
+             CLANG_RESOURCE_DIR=$CLANG_LIBDIR/clang/${LLVM_VERSION}
+-            if test ! -f "$CLANG_RESOURCE_DIR/include/stddef.h"; then :
+-  as_fn_error $? "Could not find clang internal header stddef.h in $CLANG_RESOURCE_DIR Use --with-clang-libdir to specify the correct path to the clang libraries." "$LINENO" 5
+-fi
+         fi
+     else
+         MESA_LLVM=0
diff --git a/MesaLib/patches-todo/patch-src_loader_Makefile.in b/MesaLib/patches-todo/patch-src_loader_Makefile.in
new file mode 100644
index 0000000..7a9011d
--- /dev/null
+++ b/MesaLib/patches-todo/patch-src_loader_Makefile.in
@@ -0,0 +1,24 @@
+$NetBSD: patch-src_loader_Makefile.in,v 1.4 2016/01/27 07:39:54 wiz Exp $
+
+FreeBSD & DragonFly support for libdevq.
+
+--- src/loader/Makefile.in.orig	2016-01-13 10:48:30.000000000 +0000
++++ src/loader/Makefile.in
+@@ -320,6 +320,8 @@ LEXLIB = @LEXLIB@
+ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
+ LIBCLC_INCLUDEDIR = @LIBCLC_INCLUDEDIR@
+ LIBCLC_LIBEXECDIR = @LIBCLC_LIBEXECDIR@
++LIBDEVQ_CFLAGS = @LIBDEVQ_CFLAGS@
++LIBDEVQ_LIBS = @LIBDEVQ_LIBS@
+ LIBDRM_CFLAGS = @LIBDRM_CFLAGS@
+ LIBDRM_LIBS = @LIBDRM_LIBS@
+ LIBELF_CFLAGS = @LIBELF_CFLAGS@
+@@ -532,7 +534,7 @@ AM_CPPFLAGS = \
+ 	$(LIBDRM_CFLAGS) \
+ 	$(LIBUDEV_CFLAGS)
+ 
+-libloader_la_CPPFLAGS = $(AM_CPPFLAGS) $(am__append_1)
++libloader_la_CPPFLAGS = $(AM_CPPFLAGS) $(am__append_1) $(LIBDEVQ_CFLAGS)
+ libloader_la_SOURCES = $(LOADER_C_FILES)
+ libloader_la_LIBADD = $(am__append_2) $(am__append_3)
+ @HAVE_DRI3_TRUE@libloader_dri3_helper_la_SOURCES = \
diff --git a/MesaLib/patches-todo/patch-src_loader_loader.c b/MesaLib/patches-todo/patch-src_loader_loader.c
new file mode 100644
index 0000000..f596f0a
--- /dev/null
+++ b/MesaLib/patches-todo/patch-src_loader_loader.c
@@ -0,0 +1,82 @@
+$NetBSD: patch-src_loader_loader.c,v 1.2 2015/09/26 08:45:02 tnn Exp $
+
+FreeBSD & DragonFly support for libdevq. From FreeBSD ports(?)
+
+--- src/loader/loader.c.orig	2015-09-10 18:07:21.000000000 +0000
++++ src/loader/loader.c
+@@ -70,7 +70,7 @@
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <string.h>
+-#ifdef HAVE_LIBUDEV
++#if defined(HAVE_LIBUDEV) || defined(HAVE_LIBDEVQ)
+ #include <assert.h>
+ #include <dlfcn.h>
+ #include <unistd.h>
+@@ -505,6 +505,53 @@ sysfs_get_pci_id_for_fd(int fd, int *ven
+ }
+ #endif
+ 
++#if defined(HAVE_LIBDEVQ)
++#include <libdevq.h>
++
++static void *devq_handle = NULL;
++
++static void *
++devq_dlopen_handle(void)
++{
++   if (!devq_handle) {
++      devq_handle = dlopen("libdevq.so.0", RTLD_LOCAL | RTLD_LAZY);
++   }
++
++   return devq_handle;
++}
++
++static void *
++asserted_dlsym(void *dlopen_handle, const char *name)
++{
++   void *result = dlsym(dlopen_handle, name);
++   assert(result);
++   return result;
++}
++
++#define DEVQ_SYMBOL(ret, name, args) \
++   ret (*name) args = asserted_dlsym(devq_dlopen_handle(), #name);
++
++static int
++devq_get_pci_id_from_fd(int fd, int *vendor_id, int *chip_id)
++{
++   int ret;
++   DEVQ_SYMBOL(int, devq_device_get_pciid_from_fd,
++               (int fd, int *vendor_id, int *chip_id));
++
++   *chip_id = -1;
++
++   ret = devq_device_get_pciid_from_fd(fd, vendor_id, chip_id);
++   if (ret < 0) {
++      log_(_LOADER_WARNING, "MESA-LOADER: could not get PCI ID\n");
++      goto out;
++   }
++
++out:
++   return (*chip_id >= 0);
++}
++
++#endif
++
+ #if defined(HAVE_LIBDRM)
+ /* for i915 */
+ #include <i915_drm.h>
+@@ -588,6 +635,12 @@ loader_get_pci_id_for_fd(int fd, int *ve
+    if (sysfs_get_pci_id_for_fd(fd, vendor_id, chip_id))
+       return 1;
+ #endif
++
++#if HAVE_LIBDEVQ
++   if (devq_get_pci_id_from_fd(fd, vendor_id, chip_id))
++      return 1;
++#endif
++
+ #if HAVE_LIBDRM
+    if (drm_get_pci_id_for_fd(fd, vendor_id, chip_id))
+       return 1;
diff --git a/MesaLib/patches-todo/patch-src_mapi_entry__x86-64__tls.h b/MesaLib/patches-todo/patch-src_mapi_entry__x86-64__tls.h
new file mode 100644
index 0000000..c4363aa
--- /dev/null
+++ b/MesaLib/patches-todo/patch-src_mapi_entry__x86-64__tls.h
@@ -0,0 +1,40 @@
+$NetBSD: patch-src_mapi_entry__x86-64__tls.h,v 1.2 2015/09/26 08:45:02 tnn Exp $
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+Fix --enable-glx-tls with clang. From FreeBSD.
+
+--- src/mapi/entry_x86-64_tls.h.orig	2015-09-11 17:41:47.000000000 +0000
++++ src/mapi/entry_x86-64_tls.h
+@@ -36,10 +36,19 @@ __asm__(".text\n"
+    ".balign 32\n"                                        \
+    func ":"
+ 
++#ifdef __NetBSD__
+ #define STUB_ASM_CODE(slot)                              \
+    "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t"  \
+    "movq %fs:(%rax), %r11\n\t"                           \
++   "testq %r11, %r11\n\t"                                \
++   "cmoveq table_noop_array@GOTPCREL(%rip), %r11\n\t"    \
+    "jmp *(8 * " slot ")(%r11)"
++#else
++#define STUB_ASM_CODE(slot)                              \
++   "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t"  \
++   "movq %fs:(%rax), %r11\n\t"                           \
++   "jmp *(8 * " slot ")(%r11)"
++#endif
+ 
+ #define MAPI_TMP_STUB_ASM_GCC
+ #include "mapi_tmp.h"
+@@ -61,8 +70,8 @@ entry_patch_public(void)
+ {
+ }
+ 
+-static char
+-x86_64_entry_start[];
++extern char
++x86_64_entry_start[] __attribute__((visibility("hidden")));
+ 
+ mapi_func
+ entry_get_public(int slot)
diff --git a/MesaLib/patches-todo/patch-src_mapi_entry__x86__tls.h b/MesaLib/patches-todo/patch-src_mapi_entry__x86__tls.h
new file mode 100644
index 0000000..267190b
--- /dev/null
+++ b/MesaLib/patches-todo/patch-src_mapi_entry__x86__tls.h
@@ -0,0 +1,48 @@
+$NetBSD: patch-src_mapi_entry__x86__tls.h,v 1.2 2015/09/26 08:45:02 tnn Exp $
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+Fix --enable-glx-tls with clang. From FreeBSD.
+
+--- src/mapi/entry_x86_tls.h.orig	2015-09-02 17:06:23.000000000 +0000
++++ src/mapi/entry_x86_tls.h
+@@ -50,10 +50,27 @@ __asm__(".balign 16\n"
+    ".balign 16\n"                \
+    func ":"
+ 
++#ifdef __NetBSD__
++extern const mapi_func table_noop_array[];
+ #define STUB_ASM_CODE(slot)      \
+    "call x86_current_tls\n\t"    \
+    "movl %gs:(%eax), %eax\n\t"   \
++   "testl %eax, %eax\n\t"        \
++   "je 1f\n\t"                   \
++   "jmp *(4 * " slot ")(%eax)\n\t" \
++   "1:\n\t"                      \
++   "call 2f\n"                   \
++   "2:\n\t"                      \
++   "popl %eax\n\t"               \
++   "addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax\n\t" \
++   "movl table_noop_array@GOT(%eax), %eax\n\t" \
+    "jmp *(4 * " slot ")(%eax)"
++#else
++#define STUB_ASM_CODE(slot)      \
++   "call x86_current_tls\n\t"    \
++   "movl %gs:(%eax), %eax\n\t"   \
++   "jmp *(4 * " slot ")(%eax)"
++#endif
+ 
+ #define MAPI_TMP_STUB_ASM_GCC
+ #include "mapi_tmp.h"
+@@ -71,8 +88,8 @@ __asm__(".text");
+ extern unsigned long
+ x86_current_tls();
+ 
+-static char x86_entry_start[];
+-static char x86_entry_end[];
++extern char x86_entry_start[] __attribute__((visibility("hidden")));
++extern char x86_entry_end[] __attribute__((visibility("hidden")));
+ 
+ void
+ entry_patch_public(void)
diff --git a/MesaLib/patches/patch-configure b/MesaLib/patches/patch-configure
new file mode 100644
index 0000000..0c911bf
--- /dev/null
+++ b/MesaLib/patches/patch-configure
@@ -0,0 +1,35 @@
+$NetBSD$
+
+--- configure.orig	2016-11-14 11:29:26.000000000 +0000
++++ configure
+@@ -24711,7 +24711,7 @@ if test -n "$with_vulkan_drivers"; then
+             if test "x$HAVE_I965_DRI" != xyes; then
+                 as_fn_error $? "Intel Vulkan driver requires the i965 dri driver" "$LINENO" 5
+             fi
+-            if test "x$with_sha1" == "x"; then
++            if test "x$with_sha1" = "x"; then
+                 as_fn_error $? "Intel Vulkan driver requires SHA1" "$LINENO" 5
+             fi
+             HAVE_INTEL_VULKAN=yes;
+@@ -24810,7 +24810,7 @@ $as_echo "yes" >&6; }
+ 
+ fi
+             HAVE_RADEON_VULKAN=yes;
+-            if test "x$with_sha1" == "x"; then
++            if test "x$with_sha1" = "x"; then
+                 as_fn_error $? "radv vulkan driver requires SHA1" "$LINENO" 5
+             fi
+ 	    ;;
+@@ -26375,9 +26375,9 @@ fi
+ strip_unwanted_llvm_flags() {
+     # Use \> (marks the end of the word)
+     echo `$1` | sed \
+-	-e 's/-march=\S*//g' \
+-	-e 's/-mtune=\S*//g' \
+-	-e 's/-mcpu=\S*//g' \
++	-e 's/-march=[-a-zA-Z0-9]*//g' \
++	-e 's/-mtune=[-a-zA-Z0-9]*//g' \
++	-e 's/-mcpu=[-a-zA-Z0-9]*//g' \
+ 	-e 's/-DNDEBUG\>//g' \
+ 	-e 's/-D_GNU_SOURCE\>//g' \
+ 	-e 's/-pedantic\>//g' \
diff --git a/MesaLib/patches/patch-include_GL_glxext.h b/MesaLib/patches/patch-include_GL_glxext.h
new file mode 100644
index 0000000..876b16d
--- /dev/null
+++ b/MesaLib/patches/patch-include_GL_glxext.h
@@ -0,0 +1,17 @@
+$NetBSD: patch-include_GL_glxext.h,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+Make sure the GLsizeiptr and GLintptr types are defined
+
+--- include/GL/glxext.h.orig	2014-10-03 03:59:50.000000000 +0000
++++ include/GL/glxext.h
+@@ -477,6 +477,10 @@ Bool glXSet3DfxModeMESA (int mode);
+ 
+ #ifndef GLX_NV_copy_buffer
+ #define GLX_NV_copy_buffer 1
++#ifndef GL_VERSION_1_5
++typedef ptrdiff_t GLsizeiptr;
++typedef ptrdiff_t GLintptr;
++#endif
+ typedef void ( *PFNGLXCOPYBUFFERSUBDATANVPROC) (Display *dpy, GLXContext readCtx, GLXContext writeCtx, GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+ typedef void ( *PFNGLXNAMEDCOPYBUFFERSUBDATANVPROC) (Display *dpy, GLXContext readCtx, GLXContext writeCtx, GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+ #ifdef GLX_GLXEXT_PROTOTYPES
diff --git a/MesaLib/patches/patch-src_compiler_glsl_glsl__parser__extras.cpp b/MesaLib/patches/patch-src_compiler_glsl_glsl__parser__extras.cpp
new file mode 100644
index 0000000..d912e19
--- /dev/null
+++ b/MesaLib/patches/patch-src_compiler_glsl_glsl__parser__extras.cpp
@@ -0,0 +1,15 @@
+$NetBSD: patch-src_compiler_glsl_glsl__parser__extras.cpp,v 1.1 2016/04/17 00:03:00 wiz Exp $
+
+atexit() is not a good idea in a library; use destructor attribute.
+
+--- src/compiler/glsl/glsl_parser_extras.cpp.orig	2016-04-04 10:24:28.000000000 +0000
++++ src/compiler/glsl/glsl_parser_extras.cpp
+@@ -1938,7 +1938,7 @@ extern "C" {
+  * programs would be invalid.  So this should happen at approximately
+  * program exit.
+  */
+-void
++void __attribute__((__destructor__))
+ _mesa_destroy_shader_compiler(void)
+ {
+    _mesa_destroy_shader_compiler_caches();
diff --git a/MesaLib/patches/patch-src_egl_drivers_dri2_platform__drm.c b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__drm.c
new file mode 100644
index 0000000..c5ccec6
--- /dev/null
+++ b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__drm.c
@@ -0,0 +1,16 @@
+$NetBSD$
+
+netbsd-5 build fix
+
+--- src/egl/drivers/dri2/platform_drm.c.orig	2016-11-10 22:06:40.000000000 +0000
++++ src/egl/drivers/dri2/platform_drm.c
+@@ -683,7 +683,9 @@ dri2_initialize_drm(_EGLDriver *drv, _EG
+          goto cleanup;
+       }
+    } else {
++#ifdef F_DUPFD_CLOEXEC
+       fd = fcntl(gbm_device_get_fd(gbm), F_DUPFD_CLOEXEC, 3);
++#endif
+       if (fd < 0) {
+          err = "DRI2: failed to fcntl() existing gbm device";
+          goto cleanup;
diff --git a/MesaLib/patches/patch-src_egl_drivers_dri2_platform__x11.c b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__x11.c
new file mode 100644
index 0000000..bc38731
--- /dev/null
+++ b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__x11.c
@@ -0,0 +1,30 @@
+$NetBSD: patch-src_egl_drivers_dri2_platform__x11.c,v 1.2 2016/05/18 12:55:28 wiz Exp $
+
+Provide compat strndup for older Darwin.
+
+--- src/egl/drivers/dri2/platform_x11.c.orig	2016-05-05 12:59:22.000000000 +0000
++++ src/egl/drivers/dri2/platform_x11.c
+@@ -591,6 +591,23 @@ dri2_x11_local_authenticate(struct dri2_
+    return EGL_TRUE;
+ }
+ 
++#if (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1070)
++static char *
++strndup(const char *s, int length)
++{
++   char *d;
++
++   d = malloc(length + 1);
++   if (d == NULL)
++      return NULL;
++
++   memcpy(d, s, length);
++   d[length] = '\0';
++
++   return d;
++}
++#endif
++
+ static EGLBoolean
+ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
+ {
diff --git a/MesaLib/patches/patch-src_egl_main_eglglobals.c b/MesaLib/patches/patch-src_egl_main_eglglobals.c
new file mode 100644
index 0000000..9286f9a
--- /dev/null
+++ b/MesaLib/patches/patch-src_egl_main_eglglobals.c
@@ -0,0 +1,40 @@
+$NetBSD$
+
+atexit() is not a good idea in shared libraries.
+
+--- src/egl/main/eglglobals.c.orig	2016-11-10 22:05:17.000000000 +0000
++++ src/egl/main/eglglobals.c
+@@ -72,11 +72,16 @@ struct _egl_global _eglGlobal =
+    _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR, /* debugTypesEnabled */
+ };
+ 
++static EGLBoolean registered = EGL_FALSE;
+ 
+-static void
++static void __attribute__((__destructor__))
+ _eglAtExit(void)
+ {
+    EGLint i;
++
++   if (!registered)
++     return;
++
+    for (i = _eglGlobal.NumAtExitCalls - 1; i >= 0; i--)
+       _eglGlobal.AtExitCalls[i]();
+ }
+@@ -86,14 +91,9 @@ void
+ _eglAddAtExitCall(void (*func)(void))
+ {
+    if (func) {
+-      static EGLBoolean registered = EGL_FALSE;
+-
+       mtx_lock(_eglGlobal.Mutex);
+ 
+-      if (!registered) {
+-         atexit(_eglAtExit);
+-         registered = EGL_TRUE;
+-      }
++      registered = EGL_TRUE;
+ 
+       assert(_eglGlobal.NumAtExitCalls < ARRAY_SIZE(_eglGlobal.AtExitCalls));
+       _eglGlobal.AtExitCalls[_eglGlobal.NumAtExitCalls++] = func;
diff --git a/MesaLib/patches/patch-src_gallium_auxiliary_util_u__format__tests.c b/MesaLib/patches/patch-src_gallium_auxiliary_util_u__format__tests.c
new file mode 100644
index 0000000..0458cbd
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_auxiliary_util_u__format__tests.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-src_gallium_auxiliary_util_u__format__tests.c,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+On old NetBSD, NAN in math.h is __nanf.__val. Which is not constant.
+
+--- src/gallium/auxiliary/util/u_format_tests.c.orig	2014-09-12 21:30:32.000000000 +0000
++++ src/gallium/auxiliary/util/u_format_tests.c
+@@ -28,6 +28,10 @@
+ 
+ #include <math.h>
+ #include <float.h>
++#if defined(__NetBSD__) && __NetBSD_Version__ < 600000000
++#undef NAN
++#define NAN __builtin_nanf("")
++#endif
+ 
+ #include "pipe/p_config.h"
+ #include "u_memory.h"
diff --git a/MesaLib/patches/patch-src_gallium_auxiliary_util_u__math.h b/MesaLib/patches/patch-src_gallium_auxiliary_util_u__math.h
new file mode 100644
index 0000000..0c8b6f7
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_auxiliary_util_u__math.h
@@ -0,0 +1,31 @@
+$NetBSD: patch-src_gallium_auxiliary_util_u__math.h,v 1.4 2015/09/26 08:45:02 tnn Exp $
+
+The C99 "restrict" keyword is not valid in C++, but most compilers will
+understand __restrict.
+
+--- src/gallium/auxiliary/util/u_math.h.orig	2015-09-11 17:41:47.000000000 +0000
++++ src/gallium/auxiliary/util/u_math.h
+@@ -709,6 +712,11 @@ util_bswap16(uint16_t n)
+           (n << 8);
+ }
+ 
++#if defined(__cplusplus) && !defined(restrict)
++#define undef_restrict
++#define restrict __restrict
++#endif
++
+ static inline void*
+ util_memcpy_cpu_to_le32(void * restrict dest, const void * restrict src, size_t n)
+ {
+@@ -727,6 +735,11 @@ util_memcpy_cpu_to_le32(void * restrict 
+ #endif
+ }
+ 
++#if defined(undef_restrict)
++#undef undef_restrict
++#undef restrict
++#endif
++
+ /**
+  * Clamp X to [MIN, MAX].
+  * This is a macro to allow float, int, uint, etc. types.
diff --git a/MesaLib/patches/patch-src_gallium_auxiliary_util_u__network.c b/MesaLib/patches/patch-src_gallium_auxiliary_util_u__network.c
new file mode 100644
index 0000000..de17091
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_auxiliary_util_u__network.c
@@ -0,0 +1,33 @@
+$NetBSD: patch-src_gallium_auxiliary_util_u__network.c,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+BSD has sockets, silence warning about missing implementation.
+
+--- src/gallium/auxiliary/util/u_network.c.orig	2014-09-12 21:30:32.000000000 +0000
++++ src/gallium/auxiliary/util/u_network.c
+@@ -7,7 +7,7 @@
+ #  include <winsock2.h>
+ #  include <windows.h>
+ #elif defined(PIPE_OS_LINUX) || defined(PIPE_OS_HAIKU) || \
+-   defined(PIPE_OS_APPLE) || defined(PIPE_OS_CYGWIN) || defined(PIPE_OS_SOLARIS)
++   defined(PIPE_OS_APPLE) || defined(PIPE_OS_CYGWIN) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_BSD)
+ #  include <sys/socket.h>
+ #  include <netinet/in.h>
+ #  include <unistd.h>
+@@ -56,7 +56,7 @@ u_socket_close(int s)
+       return;
+ 
+ #if defined(PIPE_OS_LINUX) || defined(PIPE_OS_HAIKU) \
+-    || defined(PIPE_OS_APPLE) || defined(PIPE_OS_SOLARIS)
++    || defined(PIPE_OS_APPLE) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_BSD)
+    shutdown(s, SHUT_RDWR);
+    close(s);
+ #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+@@ -172,7 +172,7 @@ void
+ u_socket_block(int s, boolean block)
+ {
+ #if defined(PIPE_OS_LINUX) || defined(PIPE_OS_HAIKU) \
+-    || defined(PIPE_OS_APPLE) || defined(PIPE_OS_SOLARIS)
++    || defined(PIPE_OS_APPLE) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_BSD)
+    int old = fcntl(s, F_GETFL, 0);
+    if (old == -1)
+       return;
diff --git a/MesaLib/patches/patch-src_gallium_auxiliary_util_u__network.h b/MesaLib/patches/patch-src_gallium_auxiliary_util_u__network.h
new file mode 100644
index 0000000..095a244
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_auxiliary_util_u__network.h
@@ -0,0 +1,15 @@
+$NetBSD: patch-src_gallium_auxiliary_util_u__network.h,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+BSD has sockets, silence warning about missing implementation.
+
+--- src/gallium/auxiliary/util/u_network.h.orig	2014-09-12 21:30:32.000000000 +0000
++++ src/gallium/auxiliary/util/u_network.h
+@@ -7,7 +7,7 @@
+ #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+ #  define PIPE_HAVE_SOCKETS
+ #elif defined(PIPE_OS_LINUX) || defined(PIPE_OS_HAIKU) || \
+-    defined(PIPE_OS_APPLE) || defined(PIPE_OS_SOLARIS)
++    defined(PIPE_OS_APPLE) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_BSD)
+ #  define PIPE_HAVE_SOCKETS
+ #endif
+ 
diff --git a/MesaLib/patches/patch-src_gallium_drivers_nouveau_codegen_nv50__ir__peephole.cpp b/MesaLib/patches/patch-src_gallium_drivers_nouveau_codegen_nv50__ir__peephole.cpp
new file mode 100644
index 0000000..4a2b50d
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_drivers_nouveau_codegen_nv50__ir__peephole.cpp
@@ -0,0 +1,25 @@
+$NetBSD: patch-src_gallium_drivers_nouveau_codegen_nv50__ir__peephole.cpp,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+The C99 "restrict" keyword is not valid in C++, but most compilers will
+understand __restrict.
+
+--- src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp.orig	2015-03-28 18:20:39.000000000 +0000
++++ src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+@@ -1530,7 +1530,7 @@ private:
+ 
+    bool replaceLdFromLd(Instruction *ld, Record *ldRec);
+    bool replaceLdFromSt(Instruction *ld, Record *stRec);
+-   bool replaceStFromSt(Instruction *restrict st, Record *stRec);
++   bool replaceStFromSt(Instruction *__restrict st, Record *stRec);
+ 
+    void addRecord(Instruction *ldst);
+    void purgeRecords(Instruction *const st, DataFile);
+@@ -1817,7 +1817,7 @@ MemoryOpt::replaceLdFromLd(Instruction *
+ }
+ 
+ bool
+-MemoryOpt::replaceStFromSt(Instruction *restrict st, Record *rec)
++MemoryOpt::replaceStFromSt(Instruction *__restrict st, Record *rec)
+ {
+    const Instruction *const ri = rec->insn;
+    Value *extra[3];
diff --git a/MesaLib/patches/patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c b/MesaLib/patches/patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c
new file mode 100644
index 0000000..89b3d08
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+Fix build on platforms without close-on-exec.
+
+--- src/gallium/drivers/nouveau/nouveau_vp3_video.c.orig	2014-09-12 21:30:32.000000000 +0000
++++ src/gallium/drivers/nouveau/nouveau_vp3_video.c
+@@ -292,7 +292,11 @@ nouveau_vp3_load_firmware(struct nouveau
+    if (nouveau_bo_map(dec->fw_bo, NOUVEAU_BO_WR, dec->client))
+       return 1;
+ 
++#ifdef O_CLOEXEC
+    fd = open(path, O_RDONLY | O_CLOEXEC);
++#else
++   fd = open(path, O_RDONLY);
++#endif
+    if (fd < 0) {
+       fprintf(stderr, "opening firmware file %s failed: %m\n", path);
+       return 1;
diff --git a/MesaLib/patches/patch-src_gallium_drivers_nouveau_nv50_nv84__video.c b/MesaLib/patches/patch-src_gallium_drivers_nouveau_nv50_nv84__video.c
new file mode 100644
index 0000000..4aab565
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_drivers_nouveau_nv50_nv84__video.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-src_gallium_drivers_nouveau_nv50_nv84__video.c,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+Fix build on platforms without close-on-exec.
+
+--- src/gallium/drivers/nouveau/nv50/nv84_video.c.orig	2015-03-21 00:51:18.000000000 +0000
++++ src/gallium/drivers/nouveau/nv50/nv84_video.c
+@@ -34,7 +34,11 @@
+ static int
+ nv84_copy_firmware(const char *path, void *dest, ssize_t len)
+ {
++#ifdef O_CLOEXEC
+    int fd = open(path, O_RDONLY | O_CLOEXEC);
++#else
++   int fd = open(path, O_RDONLY);
++#endif
+    ssize_t r;
+    if (fd < 0) {
+       fprintf(stderr, "opening firmware file %s failed: %m\n", path);
diff --git a/MesaLib/patches/patch-src_gallium_targets_dri_Makefile.in b/MesaLib/patches/patch-src_gallium_targets_dri_Makefile.in
new file mode 100644
index 0000000..e54ff8c
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_targets_dri_Makefile.in
@@ -0,0 +1,15 @@
+$NetBSD: patch-src_gallium_targets_dri_Makefile.in,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+DRI drivers need explicit linkage to glapi. FDO bug 57702. We only need to do
+this for the "mega" drivers since that's where final linking takes place.
+
+--- src/gallium/targets/dri/Makefile.in.orig	2015-03-28 18:43:38.000000000 +0000
++++ src/gallium/targets/dri/Makefile.in
+@@ -735,6 +735,7 @@ GALLIUM_TARGET_CFLAGS = \
+ 	$(VISIBILITY_CFLAGS)
+ 
+ GALLIUM_COMMON_LIB_DEPS = \
++	$(top_srcdir)/src/mapi/shared-glapi/libglapi.la \
+ 	-lm \
+ 	$(CLOCK_LIB) \
+ 	$(PTHREAD_LIBS) \
diff --git a/MesaLib/patches/patch-src_gallium_winsys_radeon_drm_radeon__drm__winsys.c b/MesaLib/patches/patch-src_gallium_winsys_radeon_drm_radeon__drm__winsys.c
new file mode 100644
index 0000000..e14f4dd
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_winsys_radeon_drm_radeon__drm__winsys.c
@@ -0,0 +1,18 @@
+$NetBSD$
+
+Don't create pipe thread on NetBSD. It triggers some kernel bug.
+kern/49838.
+
+--- src/gallium/winsys/radeon/drm/radeon_drm_winsys.c.orig	2016-11-10 22:05:17.000000000 +0000
++++ src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+@@ -819,8 +819,10 @@ radeon_drm_winsys_create(int fd, radeon_
+     /* TTM aligns the BO size to the CPU page size */
+     ws->info.gart_page_size = sysconf(_SC_PAGESIZE);
+ 
++#if !defined(__NetBSD__)
+     if (ws->num_cpus > 1 && debug_get_option_thread())
+         util_queue_init(&ws->cs_queue, "radeon_cs", 8, 1);
++#endif
+ 
+     /* Create the screen at the end. The winsys must be initialized
+      * completely.
diff --git a/MesaLib/patches/patch-src_gallium_winsys_svga_drm_vmw__screen__ioctl.c b/MesaLib/patches/patch-src_gallium_winsys_svga_drm_vmw__screen__ioctl.c
new file mode 100644
index 0000000..93b1be2
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_winsys_svga_drm_vmw__screen__ioctl.c
@@ -0,0 +1,32 @@
+$NetBSD: patch-src_gallium_winsys_svga_drm_vmw__screen__ioctl.c,v 1.3 2015/05/15 14:27:42 nros Exp $
+
+Make sure ERESTART gets defined.
+
+--- src/gallium/winsys/svga/drm/vmw_screen_ioctl.c.orig	2015-04-24 21:09:35.000000000 +0000
++++ src/gallium/winsys/svga/drm/vmw_screen_ioctl.c
+@@ -48,6 +48,25 @@
+ 
+ #include "os/os_mman.h"
+ 
++#if defined(__NetBSD__)
++#define _KMEMUSER
++#include <errno.h>
++#if !defined(ERESTART)
++#define ERESTART -3
++#endif
++#endif
++
++#if defined(__FreeBSD__)
++#include <errno.h>
++#if !defined(ERESTART)
++#define ERESTART -1
++#endif
++#endif
++
++#if defined(__DragonFly__)
++#define _KERNEL_STRUCTURES 1
++#endif
++
+ #include <errno.h>
+ #include <unistd.h>
+ 
diff --git a/MesaLib/patches/patch-src_glsl_ralloc.c b/MesaLib/patches/patch-src_glsl_ralloc.c
new file mode 100644
index 0000000..f0e3ba6
--- /dev/null
+++ b/MesaLib/patches/patch-src_glsl_ralloc.c
@@ -0,0 +1,39 @@
+$NetBSD: patch-src_glsl_ralloc.c,v 1.4 2016/02/23 11:16:55 jperkin Exp $
+
+* Fix exit time segfault of qt5 application with modular xorg
+* Provide compat strnlen for older Darwin.
+
+--- src/util/ralloc.c.orig	2016-01-29 12:21:30.000000000 +0000
++++ src/util/ralloc.c
+@@ -312,7 +312,7 @@ ralloc_parent(const void *ptr)
+ 
+ static void *autofree_context = NULL;
+ 
+-static void
++static void __attribute__((__destructor__))
+ autofree(void)
+ {
+    ralloc_free(autofree_context);
+@@ -323,7 +323,6 @@ ralloc_autofree_context(void)
+ {
+    if (unlikely(autofree_context == NULL)) {
+       autofree_context = ralloc_context(NULL);
+-      atexit(autofree);
+    }
+    return autofree_context;
+ }
+@@ -360,7 +359,14 @@ ralloc_strndup(const void *ctx, const ch
+    if (unlikely(str == NULL))
+       return NULL;
+ 
++#if (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1070)
++   for (n = 0; n < max; n++, str++) {
++     if (!*str)
++       break;
++   }
++#else
+    n = strnlen(str, max);
++#endif
+    ptr = ralloc_array(ctx, char, n + 1);
+    memcpy(ptr, str, n);
+    ptr[n] = '\0';
diff --git a/MesaLib/patches/patch-src_glx_apple_apple__glapi.c b/MesaLib/patches/patch-src_glx_apple_apple__glapi.c
new file mode 100644
index 0000000..6e538e6
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_apple_apple__glapi.c
@@ -0,0 +1,24 @@
+$NetBSD: patch-src_glx_apple_apple__glapi.c,v 1.1 2015/09/27 21:58:03 tnn Exp $
+
+https://bugs.freedesktop.org/show_bug.cgi?id=90311
+See also hacks.mk.
+
+--- src/glx/apple/apple_glapi.c.orig	2015-08-07 17:36:03.000000000 +0000
++++ src/glx/apple/apple_glapi.c
+@@ -39,6 +39,7 @@
+ #include <GL/gl.h>
+ 
+ #include "main/glheader.h"
++#include "main/remap.h"
+ #include "glapi.h"
+ #include "glapitable.h"
+ #include "main/dispatch.h"
+@@ -54,6 +55,8 @@ static void _apple_glapi_create_table(vo
+     if (__applegl_api)
+         return;
+ 
++    _mesa_init_remap_table(); 
++
+     __ogl_framework_api = _glapi_create_table_from_handle(apple_cgl_get_dl_handle(), "gl");
+     assert(__ogl_framework_api);
+ 
diff --git a/MesaLib/patches/patch-src_glx_glxclient.h b/MesaLib/patches/patch-src_glx_glxclient.h
new file mode 100644
index 0000000..60ecfcf
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_glxclient.h
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_glx_glxclient.h,v 1.1 2015/09/11 16:27:30 tnn Exp $
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+--- src/glx/glxclient.h.orig	2015-09-02 17:06:23.000000000 +0000
++++ src/glx/glxclient.h
+@@ -635,7 +635,11 @@ extern void __glXSetCurrentContext(struc
+ extern __thread void *__glX_tls_Context
+    __attribute__ ((tls_model("initial-exec")));
+ 
++#if defined(__NetBSD__)
++#  define __glXGetCurrentContext() (likely(__glX_tls_Context) ? __glX_tls_Context : (void*)&dummyContext)
++#else
+ #  define __glXGetCurrentContext() __glX_tls_Context
++#endif
+ 
+ # else
+ 
diff --git a/MesaLib/patches/patch-src_glx_glxcurrent.c b/MesaLib/patches/patch-src_glx_glxcurrent.c
new file mode 100644
index 0000000..86406e4
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_glxcurrent.c
@@ -0,0 +1,40 @@
+$NetBSD: patch-src_glx_glxcurrent.c,v 1.2 2015/09/26 08:45:02 tnn Exp $
+
+Interim fix for toolchain/50277.
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+--- src/glx/glxcurrent.c.orig	2015-09-02 17:06:23.000000000 +0000
++++ src/glx/glxcurrent.c
+@@ -40,6 +40,18 @@
+ #include "glapi.h"
+ 
+ /*
++ * MASSIVE KLUDGE!
++ * We need these to not be extern in libGL.so because of
++ * PR toolchain/50277
++ */
++#if defined(GLX_USE_TLS) && defined(__NetBSD__)
++_X_EXPORT __thread struct _glapi_table * _glapi_tls_Dispatch
++    __attribute__((tls_model("initial-exec"))) = NULL;
++_X_EXPORT __thread void * _glapi_tls_Context
++    __attribute__((tls_model("initial-exec")));
++#endif
++
++/*
+ ** We setup some dummy structures here so that the API can be used
+ ** even if no context is current.
+ */
+@@ -77,7 +89,11 @@ _X_HIDDEN pthread_mutex_t __glXmutex = P
+  * \c __glXGetCurrentContext can be implemented as trivial macro.
+  */
+ __thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec")))
++#if defined(__NetBSD__)
++   = NULL; /* non-zero initializers not supported with dlopen */
++#else
+    = &dummyContext;
++#endif
+ 
+ _X_HIDDEN void
+ __glXSetCurrentContext(struct glx_context * c)
diff --git a/MesaLib/patches/patch-src_mapi_glapi_gen_gl__gentable.py b/MesaLib/patches/patch-src_mapi_glapi_gen_gl__gentable.py
new file mode 100644
index 0000000..4c9561c
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_glapi_gen_gl__gentable.py
@@ -0,0 +1,15 @@
+$NetBSD: patch-src_mapi_glapi_gen_gl__gentable.py,v 1.1 2015/09/11 00:03:36 tnn Exp $
+
+FreeBSD support.
+
+--- src/mapi/glapi/gen/gl_gentable.py.orig	2015-07-29 21:28:50.156039000 +0000
++++ src/mapi/glapi/gen/gl_gentable.py
+@@ -42,7 +42,7 @@ header = """/* GLXEXT is the define used
+ #endif
+ 
+ #if (defined(GLXEXT) && defined(HAVE_BACKTRACE)) \\
+-	|| (!defined(GLXEXT) && defined(DEBUG) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__))
++	|| (!defined(GLXEXT) && defined(DEBUG) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__DragonFly__))
+ #define USE_BACKTRACE
+ #endif
+ 
diff --git a/MesaLib/patches/patch-src_mapi_u__current.c b/MesaLib/patches/patch-src_mapi_u__current.c
new file mode 100644
index 0000000..1091eb4
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_u__current.c
@@ -0,0 +1,31 @@
+$NetBSD: patch-src_mapi_u__current.c,v 1.1 2015/09/11 16:27:30 tnn Exp $
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+--- src/mapi/u_current.c.orig	2015-09-02 17:06:23.000000000 +0000
++++ src/mapi/u_current.c
+@@ -101,7 +101,11 @@ extern void (*__glapi_noop_table[])(void
+ 
+ __thread struct mapi_table *u_current_table
+     __attribute__((tls_model("initial-exec")))
++#if defined(__NetBSD__)
++    = NULL; /* non-zero initializers not supported with dlopen */
++#else
+     = (struct mapi_table *) table_noop_array;
++#endif
+ 
+ __thread void *u_current_context
+     __attribute__((tls_model("initial-exec")));
+@@ -283,7 +287,11 @@ struct mapi_table *
+ u_current_get_table_internal(void)
+ {
+ #if defined(GLX_USE_TLS)
++#  if defined(__NetBSD__)
++   return (likely(u_current_table) ? u_current_table : (struct mapi_table *) table_noop_array);
++#  else
+    return u_current_table;
++#  endif
+ #else
+    if (ThreadSafe)
+       return (struct mapi_table *) tss_get(u_current_table_tsd);
diff --git a/MesaLib/patches/patch-src_mapi_u__current.h b/MesaLib/patches/patch-src_mapi_u__current.h
new file mode 100644
index 0000000..c137f91
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_u__current.h
@@ -0,0 +1,16 @@
+$NetBSD: patch-src_mapi_u__current.h,v 1.1 2015/09/11 16:27:30 tnn Exp $
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+--- src/mapi/u_current.h.orig	2015-09-02 17:06:23.000000000 +0000
++++ src/mapi/u_current.h
+@@ -68,7 +68,7 @@ u_current_get_context_internal(void);
+ static inline const struct mapi_table *
+ u_current_get_table(void)
+ {
+-#ifdef GLX_USE_TLS
++#if defined(GLX_USE_TLS) && !defined(__NetBSD__)
+    return u_current_table;
+ #else
+    return (likely(u_current_table) ?
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_Makefile.in b/MesaLib/patches/patch-src_mesa_drivers_dri_Makefile.in
new file mode 100644
index 0000000..663a1d7
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_Makefile.in
@@ -0,0 +1,15 @@
+$NetBSD$
+
+DRI drivers need explicit linkage to glapi. FDO bug 57702. We only need to do
+this for the "mega" drivers since that's where final linking takes place.
+
+--- src/mesa/drivers/dri/Makefile.in.orig	2016-11-14 11:29:32.000000000 +0000
++++ src/mesa/drivers/dri/Makefile.in
+@@ -614,6 +614,7 @@ mesa_dri_drivers_la_LIBADD = \
+         $(SHARED_GLAPI_LIB) \
+         $(MEGADRIVERS_DEPS) \
+         $(DRI_LIB_DEPS) \
++        $(top_srcdir)/src/mapi/shared-glapi/libglapi.la \
+         $()
+ 
+ @NEED_MEGADRIVER_TRUE@dri_LTLIBRARIES = mesa_dri_drivers.la
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_common_Makefile.in b/MesaLib/patches/patch-src_mesa_drivers_dri_common_Makefile.in
new file mode 100644
index 0000000..20e3007
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_common_Makefile.in
@@ -0,0 +1,16 @@
+$NetBSD: patch-src_mesa_drivers_dri_common_Makefile.in,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+Don't install the sysconf directory for now.
+
+--- src/mesa/drivers/dri/common/Makefile.in.orig	2015-02-28 00:06:10.000000000 +0000
++++ src/mesa/drivers/dri/common/Makefile.in
+@@ -710,6 +710,9 @@ mostlyclean-libtool:
+ clean-libtool:
+ 	-rm -rf .libs _libs
+ install-sysconfDATA: $(sysconf_DATA)
++	true
++
++disabled-install-sysconfDATA:
+ 	@$(NORMAL_INSTALL)
+ 	@list='$(sysconf_DATA)'; test -n "$(sysconfdir)" || list=; \
+ 	if test -n "$$list"; then \
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_common_xmlconfig.c b/MesaLib/patches/patch-src_mesa_drivers_dri_common_xmlconfig.c
new file mode 100644
index 0000000..22dafc6
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_common_xmlconfig.c
@@ -0,0 +1,50 @@
+$NetBSD: patch-src_mesa_drivers_dri_common_xmlconfig.c,v 1.3 2016/02/23 11:16:55 jperkin Exp $
+
+PR pkg/50202.
+Provide compat strndup for older Darwin.
+
+--- src/mesa/drivers/dri/common/xmlconfig.c.orig	2016-01-29 12:21:30.000000000 +0000
++++ src/mesa/drivers/dri/common/xmlconfig.c
+@@ -50,12 +50,17 @@ extern char *program_invocation_name, *p
+ #    define GET_PROGRAM_NAME() program_invocation_short_name
+ #elif defined(__CYGWIN__)
+ #    define GET_PROGRAM_NAME() program_invocation_short_name
++/*
+ #elif defined(__FreeBSD__) && (__FreeBSD__ >= 2)
+ #    include <osreldate.h>
+ #    if (__FreeBSD_version >= 440000)
+ #        include <stdlib.h>
+ #        define GET_PROGRAM_NAME() getprogname()
+ #    endif
++*/
++#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++#    include <stdlib.h>
++#    define GET_PROGRAM_NAME() getprogname()
+ #elif defined(__NetBSD__) && defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106000100)
+ #    include <stdlib.h>
+ #    define GET_PROGRAM_NAME() getprogname()
+@@ -111,6 +116,24 @@ static const char *__getProgramName () {
+ #    endif
+ #endif
+ 
++#if (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1070)
++static char *
++strndup(const char *str, size_t n)
++{
++  size_t len;
++  char *copy;
++
++  for (len = 0; len < n && str[len]; len++)
++    continue;
++
++  if ((copy = (char *)malloc(len + 1)) == NULL)
++    return (NULL);
++  memcpy(copy, str, len);
++  copy[len] = '\0';
++  return (copy);
++}
++#endif
++
+ /** \brief Find an option in an option cache with the name as key */
+ static uint32_t findOption (const driOptionCache *cache, const char *name) {
+     uint32_t len = strlen (name);
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_i915_intel__screen.c b/MesaLib/patches/patch-src_mesa_drivers_dri_i915_intel__screen.c
new file mode 100644
index 0000000..3b8aa7d
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_i915_intel__screen.c
@@ -0,0 +1,39 @@
+$NetBSD: patch-src_mesa_drivers_dri_i915_intel__screen.c,v 1.2 2015/06/07 15:48:12 tnn Exp $
+
+Fix build on older NetBSD w/o _SC_PHYS_PAGES.
+
+--- src/mesa/drivers/dri/i915/intel_screen.c.orig	2015-06-07 10:06:53.000000000 +0000
++++ src/mesa/drivers/dri/i915/intel_screen.c
+@@ -41,6 +41,10 @@
+ #include "utils.h"
+ #include "xmlpool.h"
+ 
++#ifdef HAVE_SYS_SYSCTL_H
++# include <sys/sysctl.h>
++#endif
++
+ static const __DRIconfigOptionsExtension i915_config_options = {
+    .base = { __DRI_CONFIG_OPTIONS, 1 },
+    .xml =
+@@ -732,6 +736,13 @@ i915_query_renderer_integer(__DRIscreen 
+       const unsigned gpu_mappable_megabytes =
+          (aper_size / (1024 * 1024)) * 3 / 4;
+ 
++#if defined(HW_PHYSMEM64)
++      int mib[2] = { CTL_HW, HW_PHYSMEM64 };
++      uint64_t system_memory_bytes;
++      size_t len = sizeof(system_memory_bytes);
++      if (sysctl(mib, 2, &system_memory_bytes, &len, NULL, 0) != 0)
++         return -1;
++#else
+       const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
+       const long system_page_size = sysconf(_SC_PAGE_SIZE);
+ 
+@@ -740,6 +751,7 @@ i915_query_renderer_integer(__DRIscreen 
+ 
+       const uint64_t system_memory_bytes = (uint64_t) system_memory_pages
+          * (uint64_t) system_page_size;
++#endif
+ 
+       const unsigned system_memory_megabytes =
+          (unsigned) (system_memory_bytes / (1024 * 1024));
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__screen.c b/MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__screen.c
new file mode 100644
index 0000000..b301211
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__screen.c
@@ -0,0 +1,39 @@
+$NetBSD: patch-src_mesa_drivers_dri_i965_intel__screen.c,v 1.2 2015/06/07 15:48:12 tnn Exp $
+
+Fix build on older NetBSD w/o _SC_PHYS_PAGES.
+
+--- src/mesa/drivers/dri/i965/intel_screen.c.orig	2015-06-07 10:06:53.000000000 +0000
++++ src/mesa/drivers/dri/i965/intel_screen.c
+@@ -42,6 +42,10 @@
+ #include "utils.h"
+ #include "xmlpool.h"
+ 
++#ifdef HAVE_SYS_SYSCTL_H
++# include <sys/sysctl.h>
++#endif
++
+ static const __DRIconfigOptionsExtension brw_config_options = {
+    .base = { __DRI_CONFIG_OPTIONS, 1 },
+    .xml =
+@@ -829,6 +833,13 @@ brw_query_renderer_integer(__DRIscreen *
+       const unsigned gpu_mappable_megabytes =
+          (aper_size / (1024 * 1024)) * 3 / 4;
+ 
++#if defined(HW_PHYSMEM64)
++      int mib[2] = { CTL_HW, HW_PHYSMEM64 };
++      const uint64_t system_memory_bytes;
++      size_t len = sizeof(system_memory_bytes);
++      if (sysctl(mib, 2, &system_memory_bytes, &len, NULL, 0) != 0)
++         return -1;
++#else
+       const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
+       const long system_page_size = sysconf(_SC_PAGE_SIZE);
+ 
+@@ -837,6 +848,7 @@ brw_query_renderer_integer(__DRIscreen *
+ 
+       const uint64_t system_memory_bytes = (uint64_t) system_memory_pages
+          * (uint64_t) system_page_size;
++#endif
+ 
+       const unsigned system_memory_megabytes =
+          (unsigned) (system_memory_bytes / (1024 * 1024));
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__tiled__memcpy.c b/MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__tiled__memcpy.c
new file mode 100644
index 0000000..8c2201e
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__tiled__memcpy.c
@@ -0,0 +1,20 @@
+$NetBSD$
+
+--- src/mesa/drivers/dri/i965/intel_tiled_memcpy.c.orig	2016-11-10 22:05:17.000000000 +0000
++++ src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
+@@ -64,6 +64,7 @@ ror(uint32_t n, uint32_t d)
+    return (n >> d) | (n << (32 - d));
+ }
+ 
++#if !defined(__NetBSD__)
+ static inline uint32_t
+ bswap32(uint32_t n)
+ {
+@@ -76,6 +77,7 @@ bswap32(uint32_t n)
+           (n << 24);
+ #endif
+ }
++#endif /* NetBSD */
+ 
+ /**
+  * Copy RGBA to BGRA - swap R and B.
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_swrast_swrast.c b/MesaLib/patches/patch-src_mesa_drivers_dri_swrast_swrast.c
new file mode 100644
index 0000000..6d7a514
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_swrast_swrast.c
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_mesa_drivers_dri_swrast_swrast.c,v 1.2 2015/06/07 15:48:12 tnn Exp $
+
+Fix build on older NetBSD w/o _SC_PHYS_PAGES.
+
+--- src/mesa/drivers/dri/swrast/swrast.c.orig	2015-06-07 10:06:53.000000000 +0000
++++ src/mesa/drivers/dri/swrast/swrast.c
+@@ -150,6 +150,12 @@ swrast_query_renderer_integer(__DRIscree
+         size_t len = sizeof(system_memory_bytes);
+         if (sysctl(mib, 2, &system_memory_bytes, &len, NULL, 0) != 0)
+             return -1;
++#elif defined(HW_PHYSMEM64)
++        int mib[2] = { CTL_HW, HW_PHYSMEM64 };
++        uint64_t system_memory_bytes;
++        size_t len = sizeof(system_memory_bytes);
++        if (sysctl(mib, 2, &system_memory_bytes, &len, NULL, 0) != 0)
++            return -1;
+ #elif defined(_SC_PHYS_PAGES) && defined(_SC_PAGE_SIZE)
+       /* XXX: Do we want to return the full amount of system memory ? */
+       const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
diff --git a/MesaLib/patches/patch-src_mesa_main_context.c b/MesaLib/patches/patch-src_mesa_main_context.c
new file mode 100644
index 0000000..486ba22
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_main_context.c
@@ -0,0 +1,41 @@
+$NetBSD: patch-src_mesa_main_context.c,v 1.3 2015/09/26 08:45:02 tnn Exp $
+
+* Fix exit time segfault of qt5 application with modular xorg
+
+--- src/mesa/main/context.c.orig	2015-09-11 17:41:47.000000000 +0000
++++ src/mesa/main/context.c
+@@ -350,11 +350,14 @@ mtx_t OneTimeLock = _MTX_INITIALIZER_NP;
+  * Calls all the various one-time-fini functions in Mesa
+  */
+ 
+-static void
++static GLbitfield api_init_mask = 0x0;
++static void __attribute__((__destructor__))
+ one_time_fini(void)
+ {
+-   _mesa_destroy_shader_compiler();
+-   _mesa_locale_fini();
++   if (api_init_mask) {
++      _mesa_destroy_shader_compiler();
++      _mesa_locale_fini();
++   }
+ }
+ 
+ /**
+@@ -369,7 +372,6 @@ one_time_fini(void)
+ static void
+ one_time_init( struct gl_context *ctx )
+ {
+-   static GLbitfield api_init_mask = 0x0;
+ 
+    mtx_lock(&OneTimeLock);
+ 
+@@ -394,8 +396,6 @@ one_time_init( struct gl_context *ctx )
+          _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
+       }
+ 
+-      atexit(one_time_fini);
+-
+ #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
+       if (MESA_VERBOSE != 0) {
+ 	 _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
diff --git a/MesaLib/patches/patch-src_mesa_main_extensions.c b/MesaLib/patches/patch-src_mesa_main_extensions.c
new file mode 100644
index 0000000..395d96d
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_main_extensions.c
@@ -0,0 +1,24 @@
+$NetBSD: patch-src_mesa_main_extensions.c,v 1.1 2016/01/27 07:39:54 wiz Exp $
+
+atexit() is not a good idea in shared libraries.
+
+--- src/mesa/main/extensions.c.orig	2016-01-07 16:17:53.000000000 +0000
++++ src/mesa/main/extensions.c
+@@ -256,7 +256,7 @@ get_extension_override( struct gl_contex
+  * These strings are allocated early during the first context creation by
+  * _mesa_one_time_init_extension_overrides.
+  */
+-static void
++static void __attribute__((__destructor__))
+ free_unknown_extensions_strings(void)
+ {
+    free(extra_extensions);
+@@ -277,7 +277,7 @@ _mesa_one_time_init_extension_overrides(
+    int len;
+    size_t offset;
+ 
+-   atexit(free_unknown_extensions_strings);
++   /* atexit(free_unknown_extensions_strings); */
+ 
+    memset(&_mesa_extension_override_enables, 0, sizeof(struct gl_extensions));
+    memset(&_mesa_extension_override_disables, 0, sizeof(struct gl_extensions));
diff --git a/MesaLib/patches/patch-src_mesa_main_macros.h b/MesaLib/patches/patch-src_mesa_main_macros.h
new file mode 100644
index 0000000..8b26b14
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_main_macros.h
@@ -0,0 +1,16 @@
+$NetBSD: patch-src_mesa_main_macros.h,v 1.1 2016/01/05 13:02:57 tnn Exp $
+
+ALIGN is also defined in sys/param.h on NetBSD.
+
+--- src/mesa/main/macros.h.orig	2015-12-09 16:10:13.000000000 +0000
++++ src/mesa/main/macros.h
+@@ -690,6 +690,9 @@ minify(unsigned value, unsigned levels)
+  *
+  * \sa ROUND_DOWN_TO()
+  */
++#if defined(__NetBSD__)
++#undef ALIGN
++#endif
+ static inline uintptr_t
+ ALIGN(uintptr_t value, int32_t alignment)
+ {
diff --git a/MesaLib/patches/patch-src_mesa_main_shader__query.cpp b/MesaLib/patches/patch-src_mesa_main_shader__query.cpp
new file mode 100644
index 0000000..b87fcd5
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_main_shader__query.cpp
@@ -0,0 +1,48 @@
+$NetBSD: patch-src_mesa_main_shader__query.cpp,v 1.1 2015/05/16 16:39:52 tnn Exp $
+
+https://bugs.freedesktop.org/show_bug.cgi?id=66346
+
+From c4a1fec68d2508ff0c4fc2831465aca8c4ca783a Mon Sep 17 00:00:00 2001
+From: Julien Isorce <j.isorce%samsung.com@localhost>
+Date: Wed, 22 Apr 2015 23:04:42 +0100
+Subject: [PATCH 1/2] shader_query: convert GLhandleARB to uintptr_t before
+ troncating to GLuint
+
+Fixes compiler error on OSX as GLhandleARB is defined as void* if __APPLE__.
+
+https://bugs.freedesktop.org/show_bug.cgi?id=66346
+---
+ src/mesa/main/shader_query.cpp | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
+index bc6fec5..22d9e0f 100644
+--- src/mesa/main/shader_query.cpp
++++ src/mesa/main/shader_query.cpp
+@@ -68,7 +68,7 @@ _mesa_BindAttribLocation(GLhandleARB program, GLuint index,
+    GET_CURRENT_CONTEXT(ctx);
+ 
+    struct gl_shader_program *const shProg =
+-      _mesa_lookup_shader_program_err(ctx, program, "glBindAttribLocation");
++      _mesa_lookup_shader_program_err(ctx, (GLuint)(uintptr_t)program, "glBindAttribLocation");
+    if (!shProg)
+       return;
+ 
+@@ -136,7 +136,7 @@ _mesa_GetActiveAttrib(GLhandleARB program, GLuint desired_index,
+       return;
+    }
+ 
+-   shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveAttrib");
++   shProg = _mesa_lookup_shader_program_err(ctx, (GLuint)(uintptr_t)program, "glGetActiveAttrib");
+    if (!shProg)
+       return;
+ 
+@@ -250,7 +250,7 @@ _mesa_GetAttribLocation(GLhandleARB program, const GLcharARB * name)
+ {
+    GET_CURRENT_CONTEXT(ctx);
+    struct gl_shader_program *const shProg =
+-      _mesa_lookup_shader_program_err(ctx, program, "glGetAttribLocation");
++      _mesa_lookup_shader_program_err(ctx, (GLuint)(uintptr_t)program, "glGetAttribLocation");
+ 
+    if (!shProg) {
+       return -1;
diff --git a/MesaLib/patches/patch-src_mesa_tnl_t__pipeline.c b/MesaLib/patches/patch-src_mesa_tnl_t__pipeline.c
new file mode 100644
index 0000000..a089340
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_tnl_t__pipeline.c
@@ -0,0 +1,20 @@
+$NetBSD: patch-src_mesa_tnl_t__pipeline.c,v 1.1 2015/09/11 00:03:36 tnn Exp $
+
+i386 FPU control word defaults.
+
+--- src/mesa/tnl/t_pipeline.c.orig	2015-09-09 17:55:36.000000000 +0000
++++ src/mesa/tnl/t_pipeline.c
+@@ -132,7 +132,13 @@ static GLuint check_output_changes( stru
+ /* Hardware default: All exceptions masked, extended double precision,
+  * round to nearest (IEEE compliant):
+  */
++#if defined(__NetBSD__)
++#define DEFAULT_X86_FPU	0x127f  /* __NetBSD_NPXCW__ */
++#elif defined(__FreeBSD__)
++#define DEFAULT_X86_FPU	0x1272  /* __FreeBSD_NPXCW__ */
++#else
+ #define DEFAULT_X86_FPU		0x037f
++#endif
+ /* All exceptions masked, single precision, round to nearest:
+  */
+ #define FAST_X86_FPU		0x003f
diff --git a/MesaLib/patches/patch-src_mesa_x86_common__x86.c b/MesaLib/patches/patch-src_mesa_x86_common__x86.c
new file mode 100644
index 0000000..49217fd
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_x86_common__x86.c
@@ -0,0 +1,24 @@
+$NetBSD: patch-src_mesa_x86_common__x86.c,v 1.2 2015/09/11 00:03:36 tnn Exp $
+
+DragonFly support.
+
+--- src/mesa/x86/common_x86.c.orig	2015-07-14 18:10:47.000000000 +0000
++++ src/mesa/x86/common_x86.c
+@@ -38,7 +38,7 @@
+ #if defined(USE_SSE_ASM) && defined(__linux__)
+ #include <linux/version.h>
+ #endif
+-#if defined(USE_SSE_ASM) && defined(__FreeBSD__)
++#if defined(USE_SSE_ASM) && (defined(__FreeBSD__) || defined(__DragonFly__))
+ #include <sys/types.h>
+ #include <sys/sysctl.h>
+ #endif
+@@ -128,7 +128,7 @@ static LONG WINAPI ExceptionFilter(LPEXC
+  */
+ void _mesa_check_os_sse_support( void )
+ {
+-#if defined(__FreeBSD__)
++#if defined(__FreeBSD__) || defined(__DragonFly__)
+    {
+       int ret, enabled;
+       unsigned int len;
diff --git a/MesaLib/patches/patch-src_util_strndup.c b/MesaLib/patches/patch-src_util_strndup.c
new file mode 100644
index 0000000..3afd89b
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_strndup.c
@@ -0,0 +1,30 @@
+$NetBSD: patch-src_util_strndup.c,v 1.1 2016/02/23 11:16:55 jperkin Exp $
+
+Provide compat strndup for older Darwin.
+
+--- src/util/strndup.c.orig	2016-01-22 15:44:31.000000000 +0000
++++ src/util/strndup.c
+@@ -21,7 +21,7 @@
+  * IN THE SOFTWARE.
+  */
+ 
+-#if defined(_WIN32)
++#if defined(_WIN32) || (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1070)
+ #include <stdlib.h>
+ #include <string.h>
+ #include "strndup.h"
+@@ -35,7 +35,14 @@ strndup(const char *str, size_t max)
+    if (!str)
+       return NULL;
+ 
++#if defined(__APPLE__)
++   for (n = 0; n < max; n++, str++) {
++      if (!*str)
++          break;
++   }
++#else
+    n = strnlen(str, max);
++#endif
+    ptr = (char *) calloc(n + 1, sizeof(char));
+    if (!ptr)
+       return NULL;
diff --git a/MesaLib/patches/patch-src_util_strndup.h b/MesaLib/patches/patch-src_util_strndup.h
new file mode 100644
index 0000000..5de6a78
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_strndup.h
@@ -0,0 +1,15 @@
+$NetBSD: patch-src_util_strndup.h,v 1.1 2016/02/23 11:16:55 jperkin Exp $
+
+Provide compat strndup for older Darwin.
+
+--- src/util/strndup.h.orig	2016-01-22 15:44:31.000000000 +0000
++++ src/util/strndup.h
+@@ -25,7 +25,7 @@
+ 
+ #include <stdlib.h> // size_t
+ 
+-#if defined(_WIN32)
++#if defined(_WIN32) || (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1070)
+ 
+ #ifdef __cplusplus
+ extern "C" {
diff --git a/MesaLib/patches/patch-src_util_u__atomic.h b/MesaLib/patches/patch-src_util_u__atomic.h
new file mode 100644
index 0000000..2b71ffd
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_u__atomic.h
@@ -0,0 +1,30 @@
+$NetBSD: patch-src_util_u__atomic.h,v 1.1 2015/04/25 11:19:18 tnn Exp $
+
+Fix SunOS atomic macros.
+
+--- src/util/u_atomic.h.orig	2015-03-28 18:20:39.000000000 +0000
++++ src/util/u_atomic.h
+@@ -175,7 +175,7 @@ char _InterlockedCompareExchange8(char v
+    sizeof(*v) == sizeof(uint16_t) ? atomic_inc_16((uint16_t *)(v)) : \
+    sizeof(*v) == sizeof(uint32_t) ? atomic_inc_32((uint32_t *)(v)) : \
+    sizeof(*v) == sizeof(uint64_t) ? atomic_inc_64((uint64_t *)(v)) : \
+-                                    (assert(!"should not get here"), 0))
++                                    (assert(!"should not get here"), (void)0))
+ 
+ #define p_atomic_inc_return(v) ((__typeof(*v)) \
+    sizeof(*v) == sizeof(uint8_t)  ? atomic_inc_8_nv ((uint8_t  *)(v)) : \
+@@ -184,12 +184,12 @@ char _InterlockedCompareExchange8(char v
+    sizeof(*v) == sizeof(uint64_t) ? atomic_inc_64_nv((uint64_t *)(v)) : \
+                                     (assert(!"should not get here"), 0))
+ 
+-#define p_atomic_dec(v) ((void) \
++#define p_atomic_dec(v) (void) (\
+    sizeof(*v) == sizeof(uint8_t)  ? atomic_dec_8 ((uint8_t  *)(v)) : \
+    sizeof(*v) == sizeof(uint16_t) ? atomic_dec_16((uint16_t *)(v)) : \
+    sizeof(*v) == sizeof(uint32_t) ? atomic_dec_32((uint32_t *)(v)) : \
+    sizeof(*v) == sizeof(uint64_t) ? atomic_dec_64((uint64_t *)(v)) : \
+-                                    (assert(!"should not get here"), 0))
++                                    (assert(!"should not get here"), (void)0))
+ 
+ #define p_atomic_dec_return(v) ((__typeof(*v)) \
+    sizeof(*v) == sizeof(uint8_t)  ? atomic_dec_8_nv ((uint8_t  *)(v)) : \


Home | Main Index | Thread Index | Old Index