SUMMARY="Open source web browser engine"
DESCRIPTION="
WebKit is an open source web browser engine. WebKit is also the name of the \
Mac OS X system framework version of the engine that's used by Safari, \
Dashboard, Mail, and many other OS X applications. WebKit's HTML and \
JavaScript code began as a branch of the KHTML and KJS libraries from KDE.
"
HOMEPAGE="http://www.webkit.org/"
COPYRIGHT="1998-2012 Apple Inc., Google Inc., et al"
LICENSE="
	GNU LGPL v2
	GNU LGPL v2.1
	WebKit Apple
	MIT
	"
SRC_URI="http://www.haiku-files.org/files/haiku-webkit-lastgood-no-tests-2013-08-09.tar.bz2"
CHECKSUM_SHA256="5df4e69bf765fffc030c431f5af9b3b285fe747cb9d355ef4657d461e025b245"
REVISION="2"
ARCHITECTURES="x86 x86_64"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
	# x86_gcc2 is fine as primary target architecture as long as we're building
	# for a different secondary architecture.
	ARCHITECTURES="$ARCHITECTURES x86_gcc2"
fi
SECONDARY_ARCHITECTURES="x86"

PATCHES="haikuwebkit-1.1.3_2013_08_09.patchset"

# version info -- usually derived from the git repository
webkitRevision=r115944
haikuWebkitRevision=de778f7

PROVIDES="
	haikuwebkit$secondaryArchSuffix = $portVersion
	lib:libjavascriptcore$secondaryArchSuffix = $portVersion
	lib:libwebcore$secondaryArchSuffix = $portVersion
	lib:libwebkit$secondaryArchSuffix = $portVersion
	lib:libwtf$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix >= $haikuVersion
	icu$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng$secondaryArchSuffix
	lib:libsqlite3$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel >= $haikuVersion
	icu${secondaryArchSuffix}_devel
	devel:libcurl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng$secondaryArchSuffix
	devel:libsqlite3$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:bison
	cmd:gcc$secondaryArchSuffix
	cmd:gperf
	cmd:jam
	cmd:ld$secondaryArchSuffix
	cmd:m4
	cmd:make
	cmd:perl
	cmd:python
	"

SOURCE_DIR="haiku-webkit-lastgood"

BUILD()
{
	export WEBKIT_REVISION=$webkitRevision
	export HAIKU_WEBKIT_REVISION=$haikuWebkitRevision

	libxml2Dir=$portPackageLinksDir/devel~libxml2$secondaryArchSuffix
	libxml2Includes=$libxml2Dir/$relativeIncludeDir/libxml2
	compileFlags="-sCCFLAGS=-I$libxml2Includes -sC++FLAGS=-I$libxml2Includes"

	cd Source/JavaScriptCore
    ./make-generated-sources.sh
	NDEBUG=1 jam -q $jobArgs $compileFlags libjavascriptcore.so

	cd ../../Source/WebCore
    ./make-generated-sources.sh
	NDEBUG=1 jam -q $jobArgs $compileFlags libwebkit.so
}

INSTALL()
{
	# collect the libraries
	local libraries="
		libjavascriptcore
		libwebcore
		libwebkit
		libwtf
		"
	mkdir -p $libDir
	local library
	for library in $libraries; do
		cp generated/release/${library}.so $libDir
	done

	# collect the headers
	local headers="
		WebWindow.h
		WebViewConstants.h
		WebView.h
		WebSettings.h
		WebPage.h
		WebKitInfo.h
		WebFrame.h
		WebDownload.h
		NetworkCookieJar.h
		NetworkCookie.h
		"
	mkdir -p $includeDir
	local header
	for header in $headers; do
		cp Source/WebKit/haiku/API/$header $includeDir
	done

	prepareInstalledDevelLibs $libraries

	# devel package
	packageEntries devel \
		$developDir
}

# ----- devel package -------------------------------------------------------

PROVIDES_devel="
	haikuwebkit${secondaryArchSuffix}_devel = $portVersion
	devel:libjavascriptcore$secondaryArchSuffix = $portVersion
	devel:libwebcore$secondaryArchSuffix = $portVersion
	devel:libwebkit$secondaryArchSuffix = $portVersion
	devel:libwtf$secondaryArchSuffix = $portVersion
	"
REQUIRES_devel="
	haikuwebkit$secondaryArchSuffix == $portVersion base
	"
