# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=webkitgtk
pkgver=2.4.11
pkgrel=3
pkgdesc="portable web rendering engine WebKit for GTK+"
url="http://webkitgtk.org/"
arch="all !ppc64le !s390x"
license="LGPL-2.0-or-later BSD"
depends=""
depends_dev="gtk+2.0-dev gtk+3.0-dev libsoup-dev gstreamer1-dev
	gst-plugins-base1-dev"
makedepends="$depends_dev
	autoconf automake libtool
	bison
	enchant-dev
	expat-dev
	flex
	gnutls-dev
	gobject-introspection-dev
	gperf
	gtk-doc
	icu-dev
	libgcrypt-dev
	libgpg-error-dev
	libjpeg-turbo-dev
	libpng-dev
	libsecret-dev
	libsoup-dev
	libwebp-dev
	libxcomposite-dev
	libxcursor-dev
	libxdamage-dev
	libxi-dev
	libxml2-dev
	libxrandr-dev
	libxslt-dev
	libxt-dev
	mesa-dev
	pango-dev
	perl-switch
	ruby
	sqlite-dev
	zlib-dev
	"
install=
replaces="webkit"
subpackages="$pkgname-dev $pkgname-lang webkitgtk2"
source="http://webkitgtk.org/releases/webkitgtk-$pkgver.tar.xz
	webkit-gtk-1.7.90-parallel-make-hack.patch
	webkitgtk-1.10-textrels.patch
	harfbuzz.patch
	fix-execinfo.patch
	disallow-ctype.patch
	webkitgtk-2.4.9-abs.patch
	"

_builddir="$srcdir"/$pkgname-$pkgver
prepare() {
	cd "$_builddir"
	update_config_sub || return 1
	for i in $source; do
		case "$i" in
		*.patch)
			msg "Applying $i"
			patch -p1 -i "$srcdir"/$i || return 1
			;;
		esac
	done
	libtoolize --force && aclocal -I Source/autotools \
		&& autoconf && automake --force --add-missing || return 1
}

_build() {
	local _ver=$1

	# disable jit on aarch64 and ppc64le
	if [ "$CARCH" = "aarch64" ] || [ "CARCH" = "ppc64le" ]; then
		local _conf="--disable-jit"
		export CXXFLAGS="$CXXFLAGS -DENABLE_YARR_JIT=0"
	fi

	# Workaround crashes with gcc 6.1
	export CXXFLAGS="$CXXFLAGS -fno-delete-null-pointer-checks"

	shift
	../configure $@\
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--libexecdir=/usr/lib/webkitgtk-$_ver \
		--disable-geolocation \
		--enable-introspection \
		--with-gtk=$_ver \
		--disable-webkit2 \
		$_conf \
		|| return 1

	# fight overlinking
	# https://bugzilla.gnome.org/show_bug.cgi?id=655517
	sed -i 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool || return 1

	# hack to work around parallel make problems,
	# see https://bugs.webkit.org/show_bug.cgi?id=79498
	make -j1 all-built-sources-local \
		&& make all-ltlibraries-local \
		&& make all-programs-local \
		&& make || return 1
}

build() {
	cd "$_builddir"
	mkdir -p build-2.0
	msg "building for gtk2"
	(cd build-2.0 && _build 2.0) || return 1

	msg "building for gtk3"
	mkdir -p build-3.0
	(cd build-3.0 && _build 3.0) || return 1
}


package() {
	cd "$_builddir"
	for i in 2.0 3.0; do
		cd build-$i
		make DESTDIR="$pkgdir" install || return 1
		# verify so we dont have textrels
		if scanelf -qRt "$pkgdir" | grep TEXTREL; then
			error "found textrels"
			return 1
		fi
		cd ..
	done
}

webkitgtk2() {
	pkgdesc="portable web rendering engine WebKit for GTK+2"
	local dir
	mkdir -p "$subpkgdir"/usr/share \
		"$subpkgdir"/usr/lib \
		"$subpkgdir"/usr/lib/girepository-1.0 \
		"$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/share/webkitgtk-1.0 "$subpkgdir"/usr/share/ \
		|| return 1
	mv "$pkgdir"/usr/lib/girepository-1.0/*-1.0* \
		"$subpkgdir"/usr/lib/girepository-1.0/ || return 1
	mv "$pkgdir"/usr/lib/lib*-1.0* \
		"$subpkgdir"/usr/lib/ || return 1
	mv "$pkgdir"/usr/bin/jsc-1 \
		"$subpkgdir"/usr/bin/ || return 1
}

md5sums="24a25ccc30a7914ae50922aedf24b7bc  webkitgtk-2.4.11.tar.xz
de77a3e7e61753e7f1cce3f4bd00a3f6  webkit-gtk-1.7.90-parallel-make-hack.patch
9ace721086b25f0f32d7f76b29789f67  webkitgtk-1.10-textrels.patch
b1f455b3ea4db1598b60f5aa59f27fd5  harfbuzz.patch
c114751c30cdcaede5a7ed5568b2b0d4  fix-execinfo.patch
f5b41e756d2dfdc2bbee034d4f2d2e66  disallow-ctype.patch
f5f1f913a4abd3bb9cff2055305ead16  webkitgtk-2.4.9-abs.patch"
sha256sums="588aea051bfbacced27fdfe0335a957dca839ebe36aa548df39c7bbafdb65bf7  webkitgtk-2.4.11.tar.xz
e20d7d45e6230308f7d4a7aac1095cb1fe8d9c7eb0f3e65b061acf8bc4bbaf73  webkit-gtk-1.7.90-parallel-make-hack.patch
754bbf13c7a6c9bd745f642367ff884156020dd2ea7611c3d20a509c6685c836  webkitgtk-1.10-textrels.patch
0b7c1ce7e0e8548507eed8911c73d4a06434e5ca3b84275e785013f8b04433a2  harfbuzz.patch
b2bc9e03fd5d968d6df4531a7d102496139120e666e6fed397a19ae4026751c6  fix-execinfo.patch
6e972b5cb3f1101be646d1a018ff61c0e6614310a971eb392c4fd0fee5623455  disallow-ctype.patch
ec294bbb5588a1802a68e3615c6718486b22f922645c5fef686d3d103014bf70  webkitgtk-2.4.9-abs.patch"
sha512sums="2e2cf01a52b8593765a0a3c2d7f0ad306121660019eb402226bd2826c7d4666dab4e91ca6ccbd29abe0ad3993549f256ed1ab88de22e9c8516d5f40a4edd6bfb  webkitgtk-2.4.11.tar.xz
907356faab08ebf65da8760ad11ee8ecd4e97274b1c00c1e207fd52e479d64a0545ba66859b1a79bd150a95da4a9e8724b3c461a24f803fb341b8242566b5cc0  webkit-gtk-1.7.90-parallel-make-hack.patch
c3502a11ce4777abc164209c0087ec7cb6c28b376056bee52651b4e4bd2d49f2d6e4a74422f21d9bce848479a4a1b02052935b3c9397f1d43a59b3de22ef2758  webkitgtk-1.10-textrels.patch
8eb77ed1a1c60aac44fb00cfa6ddd46a23c4701fd6a24eac901d07eb49e0191080f7410fa3801115da5448b514e5d2095a4c4072a8c1e9f8c668eebb78afe6a1  harfbuzz.patch
602630468ee80b9f9bb53ee7808f4b2f2c86d1d4db14ac9c244b3e2e79a245510a289eb321cb7dbefd3b7a2dde13cf444b8ecf7cd46f23eaa5c0f04670914e42  fix-execinfo.patch
40a213548d4f76152d2cae57c15c6fb079b64a681a2b033b0c8265c5dbe2653818c898d1ac76ae59298cbf568dc4b811f86c3913e9d2c3d3f33e5cb8c1bd217e  disallow-ctype.patch
64ec41fc02d6bfc4e6cdc13cc2560aaefcf2b5c9c6ac62a6e3d3b85221487b44bf8b7edbf972635d1628f1d3919f96f4dd417774b8d39691b3b0d7925e499f82  webkitgtk-2.4.9-abs.patch"
