# Description: Small, efficient and fast rendering engine for Web Browsers
# URL: https://www.webkitgtk.org/
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: gst-plugins-base gtk4 hyphen icu lcms2 libseccomp libsecret libsoup3 libwebp ruby unifdef woff2 xorg-libxcomposite
# Optional: bubblewrap enchant geoclue gst-plugins-bad libavif libmanette libnotify openjpeg2 wpebackend-fdo xdg-dbus-proxy

name=webkitgtk
version=2.44.1
release=1
source=(https://webkitgtk.org/releases/webkitgtk-$version.tar.xz)

build() {
  # fail the build if dependencies are not met
  ls /usr/include/harfbuzz/hb-icu.h || (printf '\e[1;31m%-6s\e[m\n' "You need to install icu, then rebuild harfbuzz for webkitgtk to work, quitting..." ; exit 1)

  # Make sure we do not have ccache masquerade directory in PATH.
  #[ -e '/usr/bin/ccache' ] && PATH="$(echo ${PATH} | awk -v RS=: -v ORS=: '/ccache/ {next} {print}' | sed 's/:*$//')"

  prt-get isinst openjpeg2 || PKGMK_WEBKITGTK+=' -DUSE_OPENJPEG=OFF'
  prt-get isinst enchant || PKGMK_WEBKITGTK+=' -DENABLE_SPELLCHECK=OFF'
  prt-get isinst libnotify && PKGMK_WEBKITGTK+=' -DUSE_LIBNOTIFY=ON' || PKGMK_WEBKITGTK+=' -DUSE_LIBNOTIFY=OFF'
  prt-get isinst geoclue && PKGMK_WEBKITGTK+=' -DENABLE_GEOLOCATION=ON' || PKGMK_WEBKITGTK+=' -DENABLE_GEOLOCATION=OFF'
  prt-get isinst bubblewrap xdg-dbus-proxy && PKGMK_WEBKITGTK+=' -DENABLE_BUBBLEWRAP_SANDBOX=ON' \
  || PKGMK_WEBKITGTK+=' -DENABLE_BUBBLEWRAP_SANDBOX=OFF'
  prt-get isinst wpebackend-fdo || PKGMK_WEBKITGTK+=' -DUSE_WPE_RENDERER=OFF'
  prt-get isinst libmanette || PKGMK_WEBKITGTK+=' -DENABLE_GAMEPAD=OFF'
  prt-get isinst libavif || PKGMK_WEBKITGTK+=' -DUSE_AVIF=OFF'
  prt-get isinst gst_plugins-bad || PKGMK_WEBKITGTK+=' -DUSE_GSTREAMER_TRANSCODER=OFF'

  cmake -S webkitgtk-$version -B build -G Ninja ${PKGMK_WEBKITGTK} \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_INSTALL_LIBDIR=/usr/lib \
    -D CMAKE_INSTALL_LIBEXECDIR=/usr/lib \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_CXX_FLAGS_RELEASE="${CXXFLAGS} -DNDEBUG -ffat-lto-objects" \
    -D CMAKE_C_FLAGS_RELEASE="${CFLAGS} -DNDEBUG -ffat-lto-objects" \
    -D CMAKE_EXE_LINKER_FLAGS="${LDFLAGS} -Wl,-fuse-ld=gold" \
    -D CMAKE_SKIP_RPATH=ON \
    -D PORT=GTK \
    -D ENABLE_MINIBROWSER=ON \
    -D ENABLE_JOURNALD_LOG=OFF \
    -D ENABLE_DOCUMENTATION=OFF \
    -D USE_LIBBACKTRACE=OFF \
    -D USE_JPEGXL=OFF \
    -Wno-dev

  cmake --build build
  DESTDIR=$PKG cmake --install build

  rm -r $PKG/usr/share/locale
}
