Receipt for: webkit2gtk

source
# SliTaz package receipt v2.

PACKAGE="webkit2gtk"
VERSION="2.4.11"
CATEGORY="network"
SHORT_DESC="Web content engine (WebKit2) for GTK+3."
MAINTAINER="devel@slitaz.org"
LICENSE="LGPL2 BSD"
SOURCE="webkitgtk"
TARBALL="$SOURCE-$VERSION.tar.xz"
WEB_SITE="https://webkitgtk.org"
WGET_URL="$WEB_SITE/releases/$TARBALL"
PROVIDE="webkit2gtk-3.0"

# Created for the 64-bit native desktop (modern WebKit2/GTK3 replacing the old
# libwebkit WebKit1/GTK2 which needs gcc49). 2.4.11 is the last autotools
# WebKit2 that matches our gtk+3 3.14 + libsoup 2.x stack (no libwpe/woff2/
# gstreamer-hard-deps yet). i486: 2.4.11 predates the 32-bit JIT removal
# (JSVALUE32_64), so it can build 32-bit; the risk is ld address space at the
# final link -- see the parades block in compile_rules if it OOMs.
HOST_ARCH="i486 x86_64"

DEPENDS="gtk+3 glib libsoup icu enchant libxslt libxml2 sqlite cairo \
harfbuzz jpeg libpng libwebp atk gdk-pixbuf pango freetype fontconfig libsecret \
libjavascriptcoregtk xorg-libX11 xorg-libXcomposite xorg-libXdamage \
xorg-libXrender xorg-libXt gcc-lib-base"
SPLIT="libjavascriptcoregtk webkit2gtk-lang webkit2gtk-dev"
BUILD_DEPENDS="gtk+3-dev gtk+-dev glib-dev libsoup-dev icu-dev enchant-dev libxslt-dev \
libxml2-dev sqlite-dev cairo-dev harfbuzz-dev jpeg-dev libpng-dev libwebp-dev \
atk-dev gdk-pixbuf-dev pango-dev freetype-dev fontconfig-dev libsecret-dev \
xorg-dev gperf ruby libruby-extras bison flex perl python gettext gtk-doc"

# What is the latest version available today?
current_version()
{
	wget -O - $(dirname $WGET_URL) 2>/dev/null | \
	sed "/$SOURCE-2\.4/!d;/tar/!d;s|.*$SOURCE-\\(.*\\).tar.*\".*|\\1|" | sort -Vr | sed q
}

# Rules to configure and make the package.
compile_rules()
{
	# The final libwebkit2gtk-3.0 link opens thousands of .o/.a at once;
	# bump the open-files limit or ld dies with "Too many open files".
	ulimit -n 65536 2>/dev/null || ulimit -n 8192 2>/dev/null || true

	# --- i486 (32-bit) link-memory parades --------------------------------
	# The final libwebkit2gtk-3.0 + JSC link can exhaust ld's ~3 GB address
	# space on 32-bit. If `cook webkit2gtk` dies at the LINK step with OOM /
	# "cannot allocate memory" / "File truncated", uncomment IN ORDER (least
	# invasive first) until it links:
	#case "$ARCH" in i486)
	#	# 1. lighter ld bookkeeping -- try this alone first
	#	export LDFLAGS="$LDFLAGS -Wl,--no-keep-memory -Wl,--reduce-memory-overheads"
	#	# 2. still OOM? switch to the gold linker (needs binutils-gold)
	#	#export LDFLAGS="$LDFLAGS -fuse-ld=gold"
	#	# 3. last resort: drop the JIT -> CLoop interpreter (far lighter link,
	#	#    slower JS). Add `--enable-jit=no` to the ./configure block below.
	#	;;
	#esac

	# Our ruby package ships no rubygems, so every ruby startup hits a
	# gem_prelude LoadError. WebKit's offlineasm needs no gems -> disable them.
	export RUBYOPT=--disable-gems

	# ICU compat for webkit 2.4.11 vs icu 70:
	#  - 68+ dropped the TRUE/FALSE macros -> re-enable them.
	#  - 59+ made UChar = char16_t; webkit assumes uint16_t (WKChar) -> pin it back.
	export CPPFLAGS="$CPPFLAGS -DU_DEFINE_FALSE_AND_TRUE=1 -DUCHAR_TYPE=uint16_t"
	# Old C++ vs gcc 6: char16_t*/uint16_t* (UChar) pointer conversions are
	# layout-safe; -fpermissive downgrades them from error to warning.
	export CXXFLAGS="$CXXFLAGS -fpermissive"

	# Bison 3 / newer toolchain fixups (mirrors the old libwebkit receipt).
	sed -i 's|%pure_parser|%define api.pure|' \
		Source/WebCore/css/CSSGrammar.y.in 2>/dev/null
	sed -i 's|%pure_parser|%define api.pure|' \
		Source/WebCore/xml/XPathGrammar.y 2>/dev/null

	# Bison 3 names the grammar header .hpp and the generated .cpp includes it,
	# but makegrammar.pl wraps it into .h and deletes the .hpp -> keep the .hpp.
	sed -i '/unlink.*fileBase\.hpp/d' Source/WebCore/css/makegrammar.pl

	# ICU 70: U16_NEXT is a do{}while(0) needing a trailing ';' that 2.4.11 omits.
	sed -i -E 's/(U16_NEXT\([^;]*\))[[:space:]]*$/\1;/' \
		Source/WebCore/dom/Document.cpp \
		Source/WebCore/platform/graphics/SegmentedFontData.cpp

	# gcc: abs(gdouble) is ambiguous -> std::abs (needs <cmath>). Idempotent
	# (collapse any std:: prefixes) so --continue re-runs don't double-prefix.
	sed -i -E 's/(std::)+abs\(buttonEvent->/std::abs(buttonEvent->/g; s/([^:])abs\(buttonEvent->/\1std::abs(buttonEvent->/g' \
		Source/WebCore/platform/gtk/GtkClickCounter.cpp
	grep -q '#include <cmath>' Source/WebCore/platform/gtk/GtkClickCounter.cpp || \
		sed -i '/#include "config.h"/a\#include <cmath>' Source/WebCore/platform/gtk/GtkClickCounter.cpp

	# RenderThemeGtk2 (GTK2 plugin process) uses toRenderBox but omits its
	# header (the GTK3 variant includes it). Guarded for --continue re-runs.
	grep -q '#include "RenderBox.h"' Source/WebCore/platform/gtk/RenderThemeGtk2.cpp || \
		sed -i '/#include "config.h"/a\#include "RenderBox.h"' Source/WebCore/platform/gtk/RenderThemeGtk2.cpp

	# WebKit2/GTK3 build, trimmed to our stack: no introspection (frozen
	# g-ir-scanner), no media (gstreamer not packaged), no webgl/geolocation.
	# NB: accelerated compositing is left at its "auto" default = OFF as long as
	# no GL/EGL *headers* are in the build chroot (webkit's BUILD_DEPENDS pull
	# none, and the lean cooker has no mesa-dev). If a polluted chroot has
	# GL/gl.h, AC auto-enables and the link dies on undefined
	# WebCore::GraphicsContext3D::* -> remove mesa-dev before cooking.
	./configure \
		--libdir=/usr/lib \
		--with-gtk=3.0 \
		--enable-webkit2 \
		--disable-webkit1 \
		--enable-introspection=no \
		--enable-video=no \
		--enable-web-audio=no \
		--disable-geolocation \
		--disable-webgl \
		--with-unicode-backend=glib \
		--disable-gtk-doc \
		$CONFIGURE_ARGS &&
	make $MAKEFLAGS || return 1
	# SliTaz ships no docs; webkit's doc install cats a version.xml that
	# --disable-gtk-doc doesn't generate -> stub it so make install succeeds.
	for d in webkit2gtk webkitdomgtk; do
		[ -d Documentation/$d ] && echo "$VERSION" > Documentation/$d/version.xml
	done
	make install DESTDIR=$DESTDIR
}

# Rules to gen SliTaz packages (v2: one cook packs main + all SPLIT).
genpkg_rules()
{
	case $PACKAGE in
		webkit2gtk)
			# Engine only. NO WebKitPluginProcess (27M NPAPI/Flash, unused) ->
			# also drops the gtk+ (GTK2) runtime dep. JSC/locale/dev -> splits.
			copy libwebkit2gtk-3.0.so.* webkit2gtk-3.0/ \
				WebKitWebProcess WebKitNetworkProcess webkitgtk-3.0/ ;;
		libjavascriptcoregtk)
			copy libjavascriptcoregtk-3.0.so.*
			DEPENDS="glib icu gcc-lib-base" ;;
		webkit2gtk-lang)
			copy *.mo
			DEPENDS="webkit2gtk" ;;
		webkit2gtk-dev)
			copy @dev
			DEPENDS="webkit2gtk libjavascriptcoregtk gtk+3-dev libsoup-dev glib-dev" ;;
	esac
}