From 8a2a48137125ff160a62758d45172dc6e455ca7e Mon Sep 17 00:00:00 2001
From: Eivind Uggedal <eivind@uggedal.com>
Date: Thu, 13 Aug 2015 07:46:00 +0000
Subject: [PATCH] New package: phantomjs-2.0.0

---
 .../phantomjs/patches/qt-musl-execinfo.patch  | 20 ++++++++
 .../phantomjs/patches/qt-musl-socklen.patch   | 14 ++++++
 srcpkgs/phantomjs/template                    | 49 +++++++++++++++++++
 3 files changed, 83 insertions(+)
 create mode 100644 srcpkgs/phantomjs/patches/qt-musl-execinfo.patch
 create mode 100644 srcpkgs/phantomjs/patches/qt-musl-socklen.patch
 create mode 100644 srcpkgs/phantomjs/template

diff --git a/srcpkgs/phantomjs/patches/qt-musl-execinfo.patch b/srcpkgs/phantomjs/patches/qt-musl-execinfo.patch
new file mode 100644
index 0000000000..20ffa29e62
--- /dev/null
+++ b/srcpkgs/phantomjs/patches/qt-musl-execinfo.patch
@@ -0,0 +1,20 @@
+--- src/qt/qtwebkit/Source/WTF/wtf/Assertions.cpp
++++ src/qt/qtwebkit/Source/WTF/wtf/Assertions.cpp
+@@ -61,7 +61,7 @@
+ #include <windows.h>
+ #endif
+ 
+-#if (OS(DARWIN) || (OS(LINUX) && !defined(__UCLIBC__))) && !OS(ANDROID)
++#if (OS(DARWIN) || (OS(LINUX) && defined(__GLIBC__) && !defined(__UCLIBC__))) && !OS(ANDROID)
+ #include <cxxabi.h>
+ #include <dlfcn.h>
+ #include <execinfo.h>
+@@ -245,7 +245,7 @@ void WTFReportArgumentAssertionFailure(const char* file, int line, const char* f
+ 
+ void WTFGetBacktrace(void** stack, int* size)
+ {
+-#if (OS(DARWIN) || (OS(LINUX) && !defined(__UCLIBC__))) && !OS(ANDROID)
++#if (OS(DARWIN) || (OS(LINUX) && defined(__GLIBC__) && !defined(__UCLIBC__))) && !OS(ANDROID)
+     *size = backtrace(stack, *size);
+ #elif OS(WINDOWS) && !OS(WINCE)
+     // The CaptureStackBackTrace function is available in XP, but it is not defined
diff --git a/srcpkgs/phantomjs/patches/qt-musl-socklen.patch b/srcpkgs/phantomjs/patches/qt-musl-socklen.patch
new file mode 100644
index 0000000000..9f001dd003
--- /dev/null
+++ b/srcpkgs/phantomjs/patches/qt-musl-socklen.patch
@@ -0,0 +1,14 @@
+--- src/qt/qtbase/mkspecs/linux-g++/qplatformdefs.h.orig
++++ src/qt/qtbase/mkspecs/linux-g++/qplatformdefs.h
+@@ -86,11 +86,7 @@
+ 
+ #undef QT_SOCKLEN_T
+ 
+-#if defined(__GLIBC__) && (__GLIBC__ >= 2)
+ #define QT_SOCKLEN_T            socklen_t
+-#else
+-#define QT_SOCKLEN_T            int
+-#endif
+ 
+ #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)
+ #define QT_SNPRINTF		::snprintf
diff --git a/srcpkgs/phantomjs/template b/srcpkgs/phantomjs/template
new file mode 100644
index 0000000000..19273fae2e
--- /dev/null
+++ b/srcpkgs/phantomjs/template
@@ -0,0 +1,49 @@
+# Template file for 'phantomjs'
+pkgname=phantomjs
+version=2.0.0
+revision=1
+hostmakedepends="unzip flex ruby gperf python perl pkg-config"
+makedepends="
+ fontconfig-devel icu55-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
+
+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
+}