NAME="webkitgtk"
DESC="Port of the portable web rendering engine WebKit to the GTK3 and GTK4 platforms"
VERSION="2.42.5"

FILES=("https://webkitgtk.org/releases/webkitgtk-${VERSION}.tar.xz")
HASHES=("9cf27d88b55e5b8168f4835b17ea6fd0")

DEPENDS=(
  "cairo" "gst-plugins-base" "gst-plugins-bad"
  "gtk4" "icu" "lcms2" "libgudev" "libsecret"
  "libsoup" "libtasn1" "mesa" "openjpeg"
  "sqlite" "unifdef" "which" "wpebackend-fdo"
  "bubblewrap" "enchant" "geoclue" "libwebp"
  "hicolor-icon-theme" "libavif" "xdg-dbus-proxy"
  "harfbuzz" "woff2" "libwpe"
)
BUILD=(
  "cmake" "gobject-introspection" "glib"
  "ninja" "python3" "ruby" "systemd"
)

PACKAGE() {
  tar xf "${NAME}-${VERSION}.tar.xz"
  cd "${NAME}-${VERSION}"

  mkdir -pv build
  cd        build

  # prevent optimization issues
  CFLAGS="$(echo "${CFLAGS}" | sed 's/-O3/-O1/g' | sed 's/-O2/-O1/g')"
  CXXFLAGS="$(echo "${CXXFLAGS}" | sed 's/-O3/-O1/g' | sed 's/-O2/-O1/g')"
  CPPFLAGS="$(echo "${CPPFLAGS}" | sed 's/-O3/-O1/g' | sed 's/-O2/-O1/g')"

  cmake -DCMAKE_BUILD_TYPE=Release   \
      -DCMAKE_INSTALL_PREFIX=/usr    \
      -DCMAKE_SKIP_RPATH=ON          \
      -DPORT=GTK                     \
      -DLIB_INSTALL_DIR=/usr/lib     \
      -DUSE_LIBHYPHEN=OFF            \
      -DENABLE_GAMEPAD=OFF           \
      -DENABLE_MINIBROWSER=ON        \
      -DENABLE_DOCUMENTATION=OFF     \
      -DUSE_WOFF2=OFF                \
      -DUSE_GTK4=ON                  \
      -DUSE_WPE_RENDERER=ON          \
      -DUSE_JPEGXL=OFF               \
      -DENABLE_BUBBLEWRAP_SANDBOX=ON \
      -Wno-dev -G Ninja ..

  ninja
  DESTDIR="${ROOTDIR}" ninja install

  install -vdm755 "${ROOTDIR}/usr/share/gtk-doc/html/"{jsc-glib,webkit2gtk{,-web-extension}}-4.1
  install -vm644  ../Documentation/jsc-glib-4.1/*              \
                "${ROOTDIR}/usr/share/gtk-doc/html/jsc-glib-4.1"
  install -vm644  ../Documentation/webkit2gtk-4.1/*            \
                "${ROOTDIR}/usr/share/gtk-doc/html/webkit2gtk-4.1"
  install -vm644  ../Documentation/webkit2gtk-web-extension-4.1/* \
                "${ROOTDIR}/usr/share/gtk-doc/html/webkit2gtk-web-extension-4.1"

  cd ../.. && rm -r "${NAME}-${VERSION}"
}
