# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# 
# Filename: package/.../mesa/mesa.conf
# Copyright (C) 2006 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# 
# More information can be found in the files COPYING and README.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

# don't run make install
makeinstopt=''

# define the default driver location
var_append makeopt ' ' "DRI_DRIVER_INSTALL_DIR=\"$libdir/xorg/modules/dri\""

# use gccmakedep
[ "$SDECFG_DEFAULT_CC" == "gcc" ] && var_append makeopt ' ' "MKDEP=gccmakedep"

# X11 support
if pkginstalled libx11; then
	pkgprefix -t libx11
	var_append makeopt ' ' "X11_INCLUDES=-I$root$( pkgprefix includedir libx11)"
	var_append makeopt ' ' "EXTRA_LIB_PATH=-L$root$( pkgprefix libdir libx11)"
fi

# arch dependent optimization (compare configs/linux-dri-*)
case "$arch" in
	x86) target=linux-dri-x86
	;;
	x86-64) target=linux-dri-x86-64
	;;
	powerpc*) target=linux-dri-ppc
	;;
	*) target=linux-dri
	;;
esac

var_append makeopt ' ' "$target"

mesa_install()
{
	mkdir -p $root$includedir/GL #{GL,GLES}
	install -v include/GL/*.h   $root$includedir/GL/

	cp -av lib*/lib* $root$libdir/

	mkdir -p $root$libdir/xorg/modules/dri/
	install -v lib*/*dri.so $root$libdir/xorg/modules/dri/

	(
	cd $root/usr/${libdir##*/}
	# some compat symlinks (needed e.g. for (free)glut)
	ln -sdfv ../X11/include/GL $root/usr/include/GL
	ln -sfv ../X11/${libdir##*/}/libGL.* .
	ln -sfv ../X11/${libdir##*/}/libGLU.* .
	)
}

hook_add postmake 5 "mesa_install"