SUMMARY="Google's open source JavaScript engine."
DESCRIPTION="
V8 is Google's open source JavaScript engine. V8 is written in C++ and is used \
in Google Chrome, the open source browser from Google. V8 implements \
ECMAScript as specified in ECMA-262, 5th edition, and runs on Windows (XP or \
newer), Mac OS X (10.5 or newer), and Linux systems that use IA-32, x64, or \
ARM processors. V8 can run standalone, or can be embedded into any C++ \
application.
"
LICENSE="BSD (3-clause)"
COPYRIGHT="2006-2012 The V8 Project Authors"
HOMEPAGE="https://code.google.com/p/v8/" 
SRC_URI="git+https://github.com/hamishm/v8.git#5698a30"
SRC_URI_2="svn+http://gyp.googlecode.com/svn/trunk#1773"
REVISION="1"
ARCHITECTURES="?x86"
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"
else
	ARCHITECTURES="$ARCHITECTURES !x86_gcc2"
fi
SECONDARY_ARCHITECTURES="?x86"

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
    commandSuffix=
    commandBinDir=$prefix/bin
fi

PROVIDES="
	v8$secondaryArchSuffix = $portVersion
	cmd:d8$commandSuffix = $portVersion
	lib:libv8$secondaryArchSuffix = $portVersion
	"

REQUIRES="
	haiku$secondaryArchSuffix >= $haikuVersion
	"

BUILD_REQUIRES=""

BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel >= $haikuVersion
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:python
	cmd:which
	cmd:ar$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	"

PROVIDES_devel="
	v8${secondaryArchSuffix}_devel = $portVersion
	devel:libv8$secondaryArchSuffix
	"

REQUIRES_devel="
	v8$secondaryArchSuffix == $portVersion
	"

PATCHES="v8-3.16.1.patch"

PATCH()
{
	cd $sourceDir2
	patch -p0 -i $(haikuporter -t)/dev-lang/v8/patches/gyp-r1773.patch
}

SOURCE_DIR="v8"

SOURCE_DIR_2="gyp"

BUILD()
{
	ln -sfn $sourceDir2 build/gyp

	GYP_GENERATORS=make \
	build/gyp/gyp --generator-output="out" build/all.gyp \
		-Ibuild/standalone.gypi --depth=. \
		-Dv8_target_arch=ia32 \
		-S.ia32 \
		-Dcomponent=shared_library \
		-Dv8_enable_backtrace=1 \
		-Dv8_can_use_vfp2_instructions=true \
		-Dv8_can_use_vfp3_instructions=true

		# enable these in the future?
		#-Duse_system_icu=1 \
		#-Dconsole=readline


	make library=shared ia32.release $jobArgs
}

INSTALL()
{
	mkdir $commandBinDir
	cp -af out/ia32.release/d8 ${commandBinDir}
	mkdir -p ${includeDir}/v8
	cp -af include/*  ${includeDir}/v8
	mkdir -p ${libDir}
	cp -af out/ia32.release/lib.target/libv8.so ${libDir}
	
	prepareInstalledDevelLibs libv8
	packageEntries devel $developDir
}
