# Maintainer (arch): Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor (arch): Eric Bélanger <eric@archlinux.org>
# Contributor: Andreas Grapentin <andreas@grapentin.org>
# Contributor: Jesús E. <heckyel@parabola.nu>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: Luke R. <g4jc@openmailbox.org>
# Contributor: Freemor <freemor@fremor.ca>
# Contributor: bill-auger <bill-auger@programmer.net>


# parabola changes and rationale:
#  - remove geoclue2 support
#  - pinned to 'icu' sodep


pkgname=webkit2gtk
pkgver=2.32.0
pkgrel=2
pkgrel+=.nonprism1
pkgdesc="Web content engine for GTK"
pkgdesc+=", without geoclue2 support"
url="https://webkitgtk.org"
arch=(x86_64)
arch+=(armv7h i686)
license=(custom)
depends=(cairo fontconfig freetype2 libgcrypt glib2 gtk3 harfbuzz harfbuzz-icu
         icu libjpeg libsoup libxml2 zlib libpng sqlite atk libwebp at-spi2-core
         libegl libgl libgles libwpe wpebackend-fdo libxslt libsecret libtasn1
         enchant libx11 libxext libice libxt wayland libnotify hyphen openjpeg2
         woff2 libsystemd bubblewrap libseccomp xdg-dbus-proxy gstreamer
         gst-plugins-base-libs libmanette)
makedepends=(cmake ninja gtk-doc python ruby gobject-introspection
             wayland-protocols systemd gst-plugins-bad gperf)
#makedepends=(${makedepends[@]/geoclue/})
optdepends=('gst-plugins-good: media decoding'
            'gst-plugins-bad: media decoding'
            'gst-libav: nonfree media decoding')
source=($url/releases/webkitgtk-$pkgver.tar.xz{,.asc}
        unhide-deprecated-api.patch)
source_i686=(webkitgtk-2.24.2-no-sse2.patch)
sha256sums=('9d7df4dae9ada2394257565acc2a68ace9308c4c61c3fcc00111dc1f11076bf0'
            'SKIP'
            '48ee7bee0b50776c8153c20b96854bd5086e0a7d04e621fd57ea7fc6c690c3a2')
sha256sums_i686=('e95391eceeb29d0ebc57d6b867afd7cd95ed92683edeb28c6a7a5048b5a9b85b')
validpgpkeys=('D7FCF61CF9A2DEAB31D81BD3F3D322D0EC4582C3'  # Carlos Garcia Campos <cgarcia@igalia.com>
              '5AA3BC334FD7E3369E7C77B291C559DBE4C9123B') # Adrián Pérez de Castro <aperez@igalia.com>

prepare() {
  cd webkitgtk-$pkgver
  case "$CARCH" in
    i686)
      # disable SSE2 on 486 and 686
      source+=('webkitgtk-2.24.2-no-sse2.patch')
      sha256sums+=('e95391eceeb29d0ebc57d6b867afd7cd95ed92683edeb28c6a7a5048b5a9b85b')
      options+=(!debug)
      patch -p1 < ../webkitgtk-2.24.2-no-sse2.patch
      ;;
  esac

  # Use deprecated API for ubrk_safeClone until ICU 69 is officially supported
  patch -Np1 -i ../unhide-deprecated-api.patch
}

build() {
#  CFLAGS+=" $CPPFLAGS"
#  CXXFLAGS+=" $CPPFLAGS"
  local parabola_options=( -DENABLE_GEOLOCATION=OFF )

  cmake -S webkitgtk-$pkgver -B build -G Ninja \
    ${parabola_options[@]} \
    -DPORT=GTK \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DCMAKE_INSTALL_LIBEXECDIR=lib \
    -DCMAKE_SKIP_RPATH=ON \
    -DENABLE_GTKDOC=ON \
    -DENABLE_MINIBROWSER=ON
  cmake --build build
}

package() {
  depends+=(libwpe-1.0.so libWPEBackend-fdo-1.0.so)
  depends+=(libicui18n.so libicuuc.so)
  provides+=(libjavascriptcoregtk-4.0.so libwebkit2gtk-4.0.so)

  DESTDIR="$pkgdir" cmake --install build

  cd webkitgtk-$pkgver
  find Source -name 'COPYING*' -or -name 'LICENSE*' -print0 | sort -z |
    while IFS= read -d $'\0' -r _f; do
      echo "### $_f ###"
      cat "$_f"
      echo
    done |
    install -Dm644 /dev/stdin "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
