# Exit on error:
set -e

wget https://webkitgtk.org/releases/webkitgtk-2.2.5a.tar.xz
tar xf webkitgtk-2.2.5a.tar.xz
cd webkitgtk-2.2.5

# Fixes for MIPS n32:
sed -e '87s/defined(_ABIO32)/(defined(_ABIO32) || defined(_ABIN32))/' \
    -e '101s/$/\n\n#define ENABLE_JIT 0\n#define ENABLE_YARR_JIT 0\n#define ENABLE_ASSEMBLER 0\n/' \
    -e '707s/$/\n#if CPU(MIPS)\n#define USE_SYSTEM_MALLOC 1\n#endif\n/' \
    -e '710s/CPU(MIPS))/(CPU(MIPS) \&\& defined(_ABIO32)))/' \
    -i.orig Source/WTF/wtf/Platform.h

mkdir build
cd build

../configure --prefix= \
    --disable-credential-storage \
    --disable-geolocation \
    --disable-gtk-doc-html \
    --disable-spellcheck \
    --disable-svg-fonts \
    --disable-video \
    --disable-web-audio \
    --disable-webgl \
    --disable-webkit2 \
    --with-gtk=3.0

make install
cd ../..
rm -rf webkitgtk-2.2.5
rm webkitgtk-2.2.5a.tar.xz

exit 0
