# Template file for 'phantomjs'
pkgname=phantomjs
version=2.0.0
revision=8
hostmakedepends="unzip flex ruby gperf python perl pkg-config"
makedepends="
 fontconfig-devel icu-devel libressl-devel libpng-devel
 libjpeg-turbo-devel"
short_desc="Scriptable headless WebKit"
maintainer="Eivind Uggedal <eivind@uggedal.com>"
license="BSD, MIT, LGPL-2.1"
homepage="http://phantomjs.org/"
distfiles="https://bitbucket.org/ariya/${pkgname}/downloads/${pkgname}-${version}-source.zip"
checksum=cc81249eaa059cc138414390cade9cb6509b9d6fa0df16f4f43de70b174b3bfe

nopie=yes
nocross=yes

do_configure() {
	sed -e "s|-O2|${CXXFLAGS}|" \
		-i src/qt/qtbase/mkspecs/common/{g++,gcc}-base.conf
	sed -e "/^QMAKE_LFLAGS\s/s|+=|+= ${LDFLAGS}|g" \
		-i src/qt/qtbase/mkspecs/common/gcc-base.conf


	# Disable severely outdated bundled version of google breakpad on musl:
	case "$XBPS_TARGET_MACHINE" in
		*-musl)
			sed -e '/^#ifdef Q_OS_LINUX/,/^#endif/d' \
				-i src/crashdump.cpp
			sed -e '/^linux/,/^}/d' \
				-i src/phantomjs.pro
			;;
	esac
}

do_build() {
	export LD_LIBRARY_PATH="${wrksrc}/qtbase/lib:${wrksrc}/qttools/lib:${LD_LIBRARY_PATH}"
	export LD="$CXX"
	unset CPP AR AS RANLIB
	./build.sh \
		--confirm \
		--jobs $XBPS_MAKEJOBS
}

do_install() {
	vbin bin/phantomjs
	vlicense LICENSE.BSD LICENSE
	vlicense third-party.txt
}
