# Template file for 'webkitgtk'
pkgname=webkitgtk
version=2.4.9
revision=1
build_style=gnu-configure
configure_args="--disable-gtk-doc --disable-schemas-compile
 --enable-accelerated-compositing $(vopt_enable gir introspection)
 $(vopt_enable wayland wayland-target) $(vopt_enable x11 x11-target)"
short_desc="GTK+3 port of the WebKit browser engine"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
homepage="http://webkitgtk.org/"
license="LGPL-2.1, 2-clause-BSD"
distfiles="${homepage}/releases/${pkgname}-${version}.tar.xz"
checksum=afdf29e7828816cad0be2604cf19421e96d96bf493987328ffc8813bb20ac564

# ETOOHUGE
nodebug=1

hostmakedepends="automake libtool perl python pkg-config intltool gperf flex
 ruby glib-devel geoclue2 gtk-doc $(vopt_if gir gobject-introspection)"
makedepends="
 at-spi2-core-devel libjpeg-turbo-devel libpng-devel sqlite-devel
 harfbuzz-devel gst-plugins-base1-devel libsoup-devel libxslt-devel
 icu-devel enchant-devel dbus-glib-devel libwebp-devel
 gtk+-devel gtk+3-devel libgudev-devel libsecret-devel MesaLib-devel geoclue2
 $(vopt_if wayland 'libxkbcommon-devel wayland-devel')
 $(vopt_if x11 libXt-devel)"

# Package build options
build_options="gir wayland x11"
# Disable gir for cross builds.
build_options_default="x11"
if [ -z "$CROSS_BUILD" ]; then
	build_options_default+=" gir"
fi

# Explicit order since webkitgtk2-devel depends on webkitgtk2
subpackages="webkitgtk-devel webkitgtk2 webkitgtk2-devel"

pre_configure() {
	autoreconf -fi

	local v
	for v in 3.0 2.0; do
		mkdir -p /tmp/$v
		cp -a $wrksrc/* /tmp/$v
		mv /tmp/$v $wrksrc/$v
	done
}

do_configure() {
	local v
	for v in 3.0 2.0; do
		cd $wrksrc/$v

		if [ $v = 2.0 ]; then
			configure_args+=" --disable-webkit2"
		fi
		./configure $configure_args --with-gtk=${v}
	done
}

do_build() {
	local v
	for v in 3.0 2.0; do
		cd $wrksrc/$v
		make $makejobs
	done
}

do_install() {
	cd $wrksrc/3.0
	make DESTDIR=$DESTDIR install
}

webkitgtk-devel_package() {
	depends="gtk+3-devel libsoup-devel ${sourcepkg}>=${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		if [ "$build_option_gir" ]; then
			vmove usr/share/gir-1.0
		fi
		vmove "usr/lib/*.so"
		vmove usr/share/gtk-doc
	}
}

webkitgtk2_package() {
	short_desc="${short_desc/3/2}"
	replaces="webkit-gtk>=0"
	pkg_install() {
		cd $wrksrc/2.0
		make DESTDIR=$PKGDESTDIR install
	}
}

webkitgtk2-devel_package() {
	depends="gtk+-devel libsoup-devel webkitgtk2>=${version}_${revision}"
	short_desc="${short_desc/3/2} - development files"
	replaces="webkit-gtk-devel>=0"
	pkg_install() {
		local parent=$PKGDESTDIR/../webkitgtk2-${version}

		install -d $PKGDESTDIR/usr/{lib,share}
		mv $parent/usr/include $PKGDESTDIR/usr
		mv $parent/usr/lib/pkgconfig $PKGDESTDIR/usr/lib
		if [ "$build_option_gir" ]; then
			mv $parent/usr/share/gir-1.0 $PKGDESTDIR/usr/share
		fi
		mv $parent/usr/lib/*.so $PKGDESTDIR/usr/lib
		mv $parent/usr/share/gtk-doc $PKGDESTDIR/usr/share
	}
}
