# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=qt6-webengine
pkgver=6.7.2
pkgrel=1
arch=(x86_64)
url='https://www.qt.io'
license=(GPL3 LGPL3 FDL custom)
pkgdesc='Provides support for web applications using the Chromium browser project'
depends=(alsa-lib
         dbus
         expat
         ffmpeg
         fontconfig
         freetype2
         gcc-libs
         glib2
         glibc
         harfbuzz
         icu
         lcms2
         libdrm
         libevent
         libjpeg-turbo
         libpng
         libtiff
         libwebp
         libx11
         libxcb
         libxcomposite
         libxfixes
         libxkbcommon
         libxkbfile
         libxdamage
         libxext
         libxml2
         libxrandr
         libxslt
         libxtst
         mesa
         minizip
         nspr
         nss
         openjpeg2
         opus
         qt6-base
         qt6-declarative
         qt6-positioning
         qt6-webchannel
         snappy
         ttf-font
         zlib)
       # system libvpx disabled since https://codereview.qt-project.org/c/qt/qtwebengine/+/454908
       # libvpx pciutils re2
makedepends=(cmake
             git
             gperf
             jsoncpp
             libepoxy
             ninja
             nodejs
             perf
             pipewire
             python-html5lib
             qt6-tools
             qt6-websockets)
optdepends=('pipewire: WebRTC desktop sharing under Wayland')
groups=(qt6)
_pkgfn=${pkgname/6-/}
source=(git+https://code.qt.io/qt/$_pkgfn#tag=v$pkgver
        git+https://code.qt.io/qt/qtwebengine-chromium
        qtwebengine-6.7.0-ninja1.12.patch
        qtwebengine-ffmpeg-7.patch
        no-h264.patch)
sha256sums=('e4ea371bbe91763e0499b7d12166b43162f29e57ba81705870a0f8c4ba784408'
            'SKIP'
            'c037cccc1d43bcd9d67045354ca48b405acec217149cb4b2bd3cfb7b5561cc33'
            'd31143fcb04acdb4d0a183eb0e1f37be66aad19454ebbbd326a8fa68ce6f0d35'
            '5e41df98141a5a3c6ab1ef1f1a45ea4a27631cfa3fe8b0cdd524624424d74541')

prepare() {
  cd $_pkgfn
  git submodule init
  git submodule set-url src/3rdparty "$srcdir"/qtwebengine-chromium
  git -c protocol.file.allow=always submodule update

# Fix build with ninja 1.12 - Gentoo patch
  patch -p1 -i ../qtwebengine-6.7.0-ninja1.12.patch
# Fix build with ffmpeg 7 - OpenSUSE and Chromium patches
  patch -d src/3rdparty/chromium -p1 -i "$srcdir"/qtwebengine-ffmpeg-7.patch
  patch -p1 -i ../no-h264.patch
}

build() {
  cmake -B build -S $_pkgfn -G Ninja \
    -DCMAKE_MESSAGE_LOG_LEVEL=STATUS \
    -DCMAKE_TOOLCHAIN_FILE=/usr/lib/cmake/Qt6/qt.toolchain.cmake \
    -DQT_FEATURE_webengine_system_ffmpeg=ON \
    -DQT_FEATURE_webengine_system_icu=ON \
    -DQT_FEATURE_webengine_system_libevent=ON \
    -DQT_FEATURE_webengine_proprietary_codecs=ON \
    -DQT_FEATURE_webengine_kerberos=ON \
    -DQT_FEATURE_webengine_webrtc_pipewire=ON
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build

  install -Dm644 "$srcdir"/${_pkgfn}/src/3rdparty/chromium/LICENSE "$pkgdir"/usr/share/licenses/${pkgname}/LICENSE.chromium
}
