# 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/9.1.1/MesaLib-9.1.1.tar.bz2"
CHECKSUM_SHA256="3ae5741918a26ce6457b4427663b9e0ed31a3cae1b10b9009e55769a52e9adeb"
REVISION="1"
ARCHITECTURES="x86 x86_64"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
	# x86_gcc2 is fine as primary target architecture as long as we're building
	# for a different secondary architecture.
	ARCHITECTURES="$ARCHITECTURES x86_gcc2"
fi
SECONDARY_ARCHITECTURES="x86"

PATCHES="mesa-9.1.1.patch"

PROVIDES="
	mesa$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix >= $haikuVersion
	"
BUILD_REQUIRES="
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel >= $haikuVersion
	libxml2_python
	cmd:bison
	cmd:find
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:scons
	cmd:sed
	"
# TODO: Add LLVM, so llvmpipe can be built!

SOURCE_DIR="Mesa-$portVersion"

BUILD()
{
	if [ -n "$secondaryArchSuffix" ]; then
		export HAIKU_SECONDARY_ARCH="$effectiveTargetArchitecture"
	fi
	scons $jobArgs build=release
}

INSTALL()
{
	mesaBuildDir=build/haiku-$effectiveTargetArchitecture

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

	mkdir -p $developLibDir
	cp $(find $mesaBuildDir -name '*\.a') $developLibDir
	strip --strip-debug $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:libgalahad$secondaryArchSuffix = $portVersion
	devel:libgallium$secondaryArchSuffix = $portVersion
	devel:libglapi$secondaryArchSuffix = $portVersion
	devel:libglsl$secondaryArchSuffix = $portVersion
	devel:libi915$secondaryArchSuffix = $portVersion
	devel:libi915sw$secondaryArchSuffix = $portVersion
	devel:libidentity$secondaryArchSuffix = $portVersion
	devel:libmesa$secondaryArchSuffix = $portVersion
	devel:librbug$secondaryArchSuffix = $portVersion
	devel:libsoftpipe$secondaryArchSuffix = $portVersion
	devel:libst_vega$secondaryArchSuffix = $portVersion
	devel:libsvga$secondaryArchSuffix = $portVersion
	devel:libtrace$secondaryArchSuffix = $portVersion
	devel:libws_null$secondaryArchSuffix = $portVersion
	devel:libws_wrapper$secondaryArchSuffix = $portVersion
	"

REQUIRES_devel="
	mesa$secondaryArchSuffix == $portVersion base
	"
