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/"
COPYRIGHT="2003-2017 Oracle Corporation"
LICENSE="
	GNU GPL v2
	CDDL v1
	"
REVISION="3"
SOURCE_URI="http://download.virtualbox.org/virtualbox/$portVersion/VirtualBox-$portVersion.tar.bz2"
CHECKSUM_SHA256="b5715035e681a11ef1475f83f9503d34a00f0276b89c572eebec363dda80c8a9"
SOURCE_DIR="VirtualBox-$portVersion"
PATCHES="virtualbox_guest_additions-$portVersion.patchset"

ARCHITECTURES="?all !x86_gcc2"
SECONDARY_ARCHITECTURES="?x86"

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

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcurl$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libpng$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:kmk$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:mkisofs
	cmd:sed
	cmd:which
	cmd:xres
	cmd:yasm
	"

BUILD()
{
	export USER=user
	export KBUILD_PATH=`finddir B_SYSTEM_DATA_DIRECTORY`/kBuild
	./configure --only-additions
	source env.sh
	kmk VBOX_ONLY_ADDITIONS=1 VBOX_WITH_ADDITION_DRIVERS=1 BUILD_TYPE=strict all
}

INSTALL()
{
	source env.sh
	cd out/haiku.$BUILD_PLATFORM_ARCH/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


	# install VBoxTray replicant
#	mkdir -p $prefix/boot/post-install
#	cat <<'EOF' > $prefix/boot/post-install/install-VBoxTray-replicant.sh
#!/bin/sh
#/bin/VBoxTray
#EOF
#	chmod a+x $prefix/boot/post-install/install-VBoxTray-replicant.sh


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