# Template file for 'v8'
pkgname=v8
_sonamever="3.20"
version=${_sonamever}.17.13
revision=3
hostmakedepends="which python"
makedepends="readline-devel>=6.3"
short_desc="V8 JavaScript Engine"
maintainer="davehome <davehome@redthumb.info.tm>"
homepage="http://code.google.com/p/v8/"
license="BSD"
distfiles="http://commondatastorage.googleapis.com/chromium-browser-official/v8-${version}.tar.bz2"
checksum=472dcceb944685243b405ec131e3205ef5754110b0031c2cb135a44db6fa8755

do_build() {
	case "${XBPS_TARGET_MACHINE}" in
		i686|x86_64) target="native";;
		arm*)
			sed -e "s/m32flag':.*/m32flag':'',/" -i build/toolchain.gypi
			target="arm.release hardfp=on snapshot=off"
			;;
		*) msg_error "$pkgver: unknown target architecture!\n" ;;
	esac

	LINK=${CXX} make ${makejobs} ${target} i18nsupport=off \
		werror=no library=shared soname_version=${_sonamever} \
		console=readline disassembler=on \
		CXX.host=${CXX} CXX.link=${CXX} LINK.target=${CXX} \
		BUILTYPE=Release
}

do_install() {
	if [ "$CROSS_BUILD" ]; then
		case "$XBPS_TARGET_MACHINE" in
		arm*)
			vinstall out/arm.release/d8 755 usr/bin
			vinstall out/arm.release/lib.target/libv8.so.${_sonamever} 755 usr/lib
			;;
		esac
	else
		# native build
		vinstall out/native/d8 755 usr/bin
		vinstall out/native/lib.target/libv8.so.${_sonamever} 755 usr/lib
	fi
	if [ -z "$CROSS_BUILD" ]; then
		# mksnapshot only built in native builds.
		if [ "$XBPS_TARGET_MACHINE" = "x86_64" ]; then
			vinstall out/native/mksnapshot.x64 755 usr/bin mksnapshot
		elif [ "$XBPS_TARGET_MACHINE" = "i686" ]; then
			vinstall out/native/mksnapshot.ia32 755 usr/bin mksnapshot
		fi
	fi

   	vinstall include/${pkgname}-debug.h 644 usr/include
	vinstall include/${pkgname}-preparser.h 644 usr/include
	vinstall include/${pkgname}-profiler.h 644 usr/include
	vinstall include/${pkgname}-testing.h 644 usr/include
	vinstall include/${pkgname}.h 644 usr/include
	vinstall include/${pkgname}stdint.h 644 usr/include

	ln -sfr ${DESTDIR}/usr/lib/libv8.so.${_sonamever} ${DESTDIR}/usr/lib/libv8.so
}

v8-devel_package() {
	depends="libv8-${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/libv8.so
	}
}

libv8_package() {
	short_desc+=" - runtime library"
	pkg_install() {
		vmove usr/lib/libv8.so.${_sonamever}
	}
}
