# NOTE: This recipe doesn't generate packages for general use:
# * mesa_devel: Is a service package for the Haiku build system. It contains the
#   Mesa libraries and headers, which are built into the Haiku system package.
# * mesa: Is an empty package which we keep as a dependency for the Haiku system
#   package, mainly to keep the copyright info.

SUMMARY="Multi-platform GL implementation"
DESCRIPTION="
Mesa is an open-source implementation of the OpenGL specification - a system \
for rendering interactive 3D graphics.
A variety of device drivers allows Mesa to be used in many different \
environments ranging from software emulation to complete hardware acceleration \
for modern GPUs.
Mesa ties into several other open-source projects: the Direct Rendering \
Infrastructure and X.org to provide OpenGL support to users of X on Linux, \
FreeBSD and other operating systems.
"
HOMEPAGE="http://www.mesa3d.org/" 
COPYRIGHT="1999-2012 Brian Paul All Rights Reserved."
LICENSE="MIT"
SRC_URI="ftp://freedesktop.org/pub/mesa/older-versions/7.x/7.8.2/MesaLib-7.8.2.tar.bz2"
CHECKSUM_SHA256="505bf418dceba05837f4ea1b1972b9620c35f8cb94bc4d1e6d573c15f562576d"
REVISION="3"
ARCHITECTURES="x86_gcc2"
if [ $effectiveTargetArchitecture = x86_gcc2 -a $targetArchitecture = x86 ]
then
	ARCHITECTURES="$ARCHITECTURES x86"
fi
SECONDARY_ARCHITECTURES="x86_gcc2"

PATCHES="mesa-7.8.2.patch"

PROVIDES="
	mesa$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix >= $haikuVersion
	"
BUILD_REQUIRES="
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel >= $haikuVersion
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:sed
	"

SOURCE_DIR="Mesa-$portVersion"

BUILD()
{
	DEBUG=0 make $jobArgs haiku
}

INSTALL()
{
	# "make install" seems to be broken, so we copy the headers and libraries
	# manually.

	mkdir -p $includeDir
	cp -r include/* $includeDir

	mkdir -p $developLibDir
	cp lib/libglu.a src/mesa/*.a src/glsl/*/*.a $developLibDir

	mesaPrivateHeaders=$includeDir/mesa_private
	for header in $(find src -name '*\.h' | sed "s,^src/,,"); do
		mkdir -p $mesaPrivateHeaders/$(dirname $header)
		cp src/$header $mesaPrivateHeaders/$header
	done

	# devel package
	packageEntries devel \
		$developDir
}

# ----- devel package -------------------------------------------------------

PROVIDES_devel="
	mesa${secondaryArchSuffix}_devel = $portVersion
	devel:libglapi$secondaryArchSuffix = $portVersion
	devel:libglslcl$secondaryArchSuffix = $portVersion
	devel:libglslpp$secondaryArchSuffix = $portVersion
	devel:libglu$secondaryArchSuffix = $portVersion
	devel:libmesa$secondaryArchSuffix = $portVersion
	devel:libmesagallium$secondaryArchSuffix = $portVersion
	"
REQUIRES_devel="
	mesa$secondaryArchSuffix == $portVersion base
	"
