SUMMARY="Multi-platform GL implementation"
DESCRIPTION="
Mesa is an open-source implementation of the OpenGL specification. The OpenGL \
specification documents a system for rendering interactive 3D graphics.
Mesa fills the role of the Haiku OpenGL kit providing 3D rendering to Haiku \
applications.
"
HOMEPAGE="http://www.mesa3d.org/"
COPYRIGHT="1999-2013 Brian Paul All Rights Reserved."
LICENSE="MIT"

SOURCE_URI="https://github.com/haiku/mesa_legacy/archive/7.9.2-9.tar.gz"
SOURCE_DIR="mesa_legacy-7.9.2-9"
SOURCE_FILENAME="mesa_legacy-7.9.2-9.tar.gz"
CHECKSUM_SHA256="445c4081c761851343ae732b5f233f269f6751ff422aa0299aae009fe049c273"
PATCHES="mesa-7.9.2.patchset"

REVISION="10"
ARCHITECTURES="x86_gcc2"
if [ $effectiveTargetArchitecture != x86 ]; then
	# x86_gcc2 is fine as primary target architecture as long as we're building
	# for a different secondary architecture.
	ARCHITECTURES="$ARCHITECTURES x86"
fi
SECONDARY_ARCHITECTURES="?x86_gcc2"

PROVIDES="
	mesa$secondaryArchSuffix = $portVersion compat >= 7.9
	lib:libGL$secondaryArchSuffix
	"

REQUIRES="
	haiku$secondaryArchSuffix
	"
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
	
BUILD_PREREQUIRES="
	libxml2_python
	cmd:bison
	cmd:find
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:python
	cmd:make
	cmd:sed
	"

BUILD()
{
	if [ -n "$secondaryArchSuffix" ]; then
		export HAIKU_SECONDARY_ARCH="$effectiveTargetArchitecture"
	fi
	#make DEBUG=1 haiku $jobArgs
	make haiku $jobArgs
}

INSTALL()
{
	# libGL.so makes up the core of our OpenGL kit
	mkdir -p $libDir
	cp $(find ./lib/ -name 'libGL.so') $libDir
	mkdir -p $developLibDir
	symlinkRelative -s $libDir/libGL.so $developLibDir

	# Our rendering add-on
	mkdir -p $addOnsDir/opengl
	cp $(find ./lib/ -name 'libswrast.so') \
		"$addOnsDir/opengl/Legacy Software Rasterizer"

	# OpenGL Kit
	mkdir -p $includeDir/os/opengl
	cp ./include/HGL/OpenGLKit.h $includeDir/os/
	cp ./include/HGL/GLView.h $includeDir/os/opengl/
	cp ./include/HGL/GLRenderer.h $includeDir/os/opengl/

	# Standard GL headers
	mkdir -p $includeDir/GL
	cp ./include/GL/gl.h $includeDir/GL/
	cp ./include/GL/gl_mangle.h $includeDir/GL/
	cp ./include/GL/glext.h $includeDir/GL/

	# Create GL symlink in opengl kit
	symlinkRelative -s $includeDir/GL $includeDir/os/opengl/GL

	# Create a pkcconfig for libGL
	mkdir -p $libDir/pkgconfig
	sed -e "s,@INSTALL_DIR@,$prefix," \
	    -e "s,@INSTALL_LIB_DIR@,$libDir," \
	    -e "s,@INSTALL_INC_DIR@,$includeDir," \
	    -e "s,@VERSION@,$portVersion," \
	    -e "s,@GL_LIB@,GL," \
	    -e "s,@GL_PC_LIB_PRIV@,," \
	    -e "s,@GL_PC_REQ_PRIV@,," \
	    -e "s,@GL_PC_CFLAGS@,," src/mesa/gl.pc.in > $libDir/pkgconfig/gl.pc
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir

	# swrast renderer package
	packageEntries swrast \
		"$addOnsDir/opengl/Legacy Software Rasterizer"
}

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

PROVIDES_devel="
	mesa${secondaryArchSuffix}_devel = $portVersion
	devel:libGL${secondaryArchSuffix} = $portVersion
	"

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

# ===== Mesa OpenGL Add-ons ==================================================
# ----- swrast package -------------------------------------------------------

SUMMARY_swrast="Mesa legacy software rasterization renderer"
DESCRIPTION_swrast="This 3D BGLRenderer add-on provides Mesa software
	rasterization on Haiku systems. Software rasterization performs all
	3D rendering on the systems CPU and doesn't require any specialized
	hardware. Software rasterization is generally considered a fallback
	3D rendering method as performance is limited.
	"
PROVIDES_swrast="
	mesa${secondaryArchSuffix}_swrast = $portVersion
	"
REQUIRED_swrast="
	mesa$secondaryArchSuffix == $portVersion base
	"
