SUMMARY="VirtualBox kernel modules and user-space tools for Haiku guests"
DESCRIPTION="VirtualBox is a free x86 virtualization solution allowing a wide \
range of x86 operating systems such as Windows, DOS, BSD or Linux to run on a \
Linux system.

This package contains the VirtualBox kernel modules and user-space \
tools for Haiku guests."
HOMEPAGE="https://www.virtualbox.org/"
#TODO:check user manual for full list
COPYRIGHT="2003-2014 Oracle Corporation."
#TODO:check user manual for full list
LICENSE="GNU GPL v2
	CDDL v1"
REVISION="4"
SOURCE_URI="http://download.virtualbox.org/virtualbox/$portVersion/VirtualBox-$portVersion.tar.bz2"
SOURCE_DIR="VirtualBox-$portVersion"
CHECKSUM_SHA256="db84ddf47d1ecd316ec46417595f0252e3ec2f67e35e1e17320aba87b7c2934f"
PATCHES="virtualbox_guest_additions-$portVersion.patchset"

ARCHITECTURES="x86_gcc2"

PROVIDES="
	virtualbox_guest_additions$secondaryArchSuffix = $portVersion
	cmd:VBoxControl$secondaryArchSuffix = $portVersion
	cmd:VBoxService$secondaryArchSuffix = $portVersion
	cmd:VBoxTray$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	"

BUILD_REQUIRES="
	devel:libiconv$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libpng$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	# required for kmk_* which are compiled with gcc4
	haiku_x86
	haiku${secondaryArchSuffix}_devel
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:ld$secondaryArchSuffix
	cmd:mkisofs
	cmd:sed
	cmd:which
	cmd:xres
	cmd:yasm
	"

BUILD()
{
	# use the checked-out kBuild for now
	export PATH="$PATH:$PWD/kBuild/bin/haiku.x86"
	export USER=user
	./configure --build-headless --disable-python --disable-java --nofatal
	source env.sh
	kmk VBOX_ONLY_ADDITIONS=1 VBOX_WITH_ADDITION_DRIVERS=1 BUILD_TYPE=strict all
}

INSTALL()
{
	cd out/haiku.x86/strict/bin/additions
	mkdir -p $addOnsDir/kernel/{generic,drivers/bin,drivers/dev/misc}

	cp vboxguest $addOnsDir/kernel/generic
	cp vboxdev $addOnsDir/kernel/drivers/bin
	ln -fs ../../bin/vboxdev $addOnsDir/kernel/drivers/dev/misc

#	mkdir -p $addOnsDir/kernel/file_systems
#	cp vboxsf $addOnsDir/kernel/file_systems

#	mkdir -p $addOnsDir/{input_server/filters,input_server/devices}
#	cp VBoxMouseFilter $addOnsDir/input_server/filters
#	cp VBoxMouse $addOnsDir/input_server/devices

#	mkdir -p $addOnsDir/{accelerants,kernel/drivers/dev/graphics}
#	cp vboxvideo $addOnsDir/kernel/drivers/bin
#	ln -fs ../../bin/vboxvideo $addOnsDir/kernel/drivers/dev/graphics
#	cp vboxvideo.accelerant $addOnsDir/accelerants

	mkdir -p $binDir

	xres -o file.tmp VBoxControl ; strip -S VBoxControl ; xres -o VBoxControl file.tmp
	xres -o file.tmp VBoxService ; strip -S VBoxService ; xres -o VBoxService file.tmp
	xres -o file.tmp VBoxTray ; strip -S VBoxTray ; xres -o VBoxTray file.tmp

	cp VBoxControl VBoxService VBoxTray $binDir

	# Add a symlink to the Desktop applets directory in Deskbar
	desktopAppletsDir="$dataDir/deskbar/menu/Desktop applets"
	mkdir -p "$desktopAppletsDir"
	ln -s $binDir/VBoxTray "$desktopAppletsDir/VBoxTray"
}
