#!/bin/sh -e

# Enable streaming related options if gstreamer is installed.
kiss list gst-plugins-base && streaming=ON

# Enable the use of openjpeg if the package is installed.
kiss list openjpeg2 && jpeg=ON

# Enable WEB_CRYPTO if libtasn1 is installed.
kiss list libtasn1 && tasn=ON

# Remove gettext requirement.
sed -i 's/ngettext/printf/g' Tools/MiniBrowser/gtk/BrowserDownloadsBar.c
sed -i '/po_files \*\.po/d'  Source/WebCore/platform/gtk/po/CMakeLists.txt
sed -i '/^GETTEXT_C/d'       Source/WebCore/platform/gtk/po/CMakeLists.txt

# Fix clang build.
sed -i '/LC_ALL/d'       Source/JavaScriptCore/jsc.cpp
sed -i '/WTFLogAlways/d' Source/JavaScriptCore/jsc.cpp

export DESTDIR="$1"

cmake -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBEXECDIR=/usr/lib \
    -DLIB_INSTALL_DIR=/usr/lib \
    -DPORT=GTK \
    -DCMAKE_SKIP_RPATH=ON \
    -DENABLE_BUBBLEWRAP_SANDBOX=OFF \
    -DENABLE_SAMPLING_PROFILER=OFF \
    -DENABLE_GAMEPAD=OFF \
    -DENABLE_GEOLOCATION=OFF \
    -DENABLE_GLES2=ON \
    -DENABLE_INTROSPECTION=OFF \
    -DENABLE_MINIBROWSER=OFF \
    -DENABLE_SPELLCHECK=OFF \
    -DUSE_GSTREAMER_GL=OFF \
    -DUSE_LIBHYPHEN=OFF \
    -DUSE_LIBNOTIFY=OFF \
    -DUSE_LIBSECRET=OFF \
    -DUSE_OPENJPEG=${jpeg:-OFF} \
    -DUSE_SYSTEMD=OFF \
    -DUSE_WOFF2=OFF \
    -DUSE_WPE_RENDERER=OFF \
    -DENABLE_WEB_CRYPTO=${tasn:-OFF} \
    -DENABLE_VIDEO=${streaming:-OFF} \
    -DENABLE_WEB_AUDIO=${streaming:-OFF} \
    -Wno-dev

cmake --build   build
cmake --install build
