# Maintainer: Martchus <martchus@gmx.net>

# All my PKGBUILDs are managed at https://github.com/Martchus/PKGBUILDs where
# you also find the URL of a binary repository.

# This file is created from PKGBUILD.sh.ep contained by the mentioned repository.
# Do not edit it manually! See README.md in the repository's root directory
# for more information.

# All patches are managed at https://github.com/Martchus/qtbase

pkgname=wasm-qt6-base
_qtver=6.7.1
pkgver=${_qtver/-/}
pkgrel=1.1
arch=(any)
url='https://www.qt.io'
license=(GPL3 LGPL3 FDL custom)
pkgdesc='A cross-platform application and UI framework (wasm)'
depends=('emscripten')
makedepends=('qt6-base' 'ninja' 'cmake')
optdepends=('qt6-base: development tools')
options=('!strip' '!buildflags' 'staticlibs' '!emptydirs')
groups=(wasm-qt6)
_pkgfqn="qtbase-everywhere-src-${_qtver}"
source=("https://download.qt.io/official_releases/qt/${pkgver%.*}/${_qtver}/submodules/${_pkgfqn}.tar.xz"
        '0001-Use-CMake-s-default-import-library-suffix.patch'
        '0002-Fix-finding-D-Bus.patch'
        '0003-Fix-using-static-PCRE2-and-DBus-1.patch'
        '0004-Fix-transitive-dependencies-of-static-libraries.patch'
        '0005-Fix-libjpeg-workaround-for-conflict-with-rpcndr.h.patch'
        '0006-Support-finding-static-MariaDB-client-library.patch'
        '0007-Allow-overriding-CMAKE_FIND_LIBRARY_SUFFIXES-to-pref.patch'
        '0008-Find-fontconfig-via-pkg-config-for-correct-handling-.patch'
        '0009-Fix-dependency-of-xcb-image-on-xcb-util.patch'
        '0010-Allow-using-properties-of-PkgConfig-targets-for-glib.patch'
        '0011-Allow-using-properties-of-PkgConfig-targets-for-Wayl.patch'
        '0012-Allow-overriding-preference-for-shared-libzstd-libra.patch'
        '0013-Fix-errors-due-to-disabled-exceptions-with-cpp_winrt.patch'
        '0014-Fix-setting-exception-flags-of-plugin-targets.patch'
        '0015-Link-corelib-correctly-against-runtimeobject-when-co.patch'
        '0016-Workaround-linker-error-about-missing-symbol-__sync_.patch'
        '0017-Workaround-Unknown-CMake-command-_qt_test_emscripten.patch'
        '0018-Fix-configuration-when-EMSCRIPTEN_ROOT-is-an-absolut.patch')
sha256sums=('b7338da1bdccb4d861e714efffaa83f174dfe37e194916bfd7ec82279a6ace19'
            'dfc050c3174cea92bf286ceba9e3f3404173d47befd16c6257bd53506eb6d308'
            '70534c7ca36c2606a3966a4e4bda05a30cac7351d0622bd8f26141efe4d722d9'
            'ea2bf419b95381370600f7cc91528379d35650116b65432ec37ae9b09dc811d6'
            '481dee525287b487c94b6ca0a10c7dbd098ccdd16e2aae7d2f50c5fc29e7400d'
            '4688f4e3245c3362da1121af485bd1e28175d9caf2078875d3258d173fb20154'
            '708e6a35075d33e83bd745c8a593dd403be88272430c1c4231559cb64aac5be9'
            '6f3bd9c31aa6b659d59fb55ee5aaf7c890fb4247c86a6cc903f6a498d08fcf0d'
            'f7a6c6ab9a514f07c55d5d067d8f094bea2094b896b6c764ef58fa5b75b30cf1'
            'f9badaf628f48f60a949f0726b8cdbd00268ea4322a9c041ae319120ab14dd6a'
            '5ecac31ce2b10e48bd3d75fb2ee40acb391d2aa82037663cb9b9b05acc10dccf'
            '11b11398fb0ac3e882264da8ce8b81cf8b53c6735f4b4ce08ec123304bc157ac'
            'c492388460c2db8eedc6b3fd73907aa9065fe262c0de6f6f0aaf129295188ecc'
            '57df537500c56ae213296f79a00bd3b9b7dd5c907a7a6f1d76efb14d6351b239'
            '8a230e11c6eaf73f4ea262ef2b5d094d75dca358536209cb7a3034a16e954fa0'
            '93201998b30512c815995469546f73cd65464e16abde9835749816bc17574a7d'
            '1f225673f38e054824ee29b05d6ece2d5b1073a6b55f23f6ed973509e3bf181c'
            '2e6332a923aabac928dcc98d6b16fdbc499512dee2e1c26768811c6025503e8f'
            '3faeebb2bddd972885d8b794fe6fe4a7ea4081e0729fb8d64560bff525ef970b')

prepare () {
  cd $_pkgfqn

  # apply patches; further descriptions can be found in patch files itself
  for patch in "$srcdir/"*.patch; do
    msg2 "Applying patch $patch"
    patch -p1 -i "$patch"
  done
}

build() {
  export EMSDK=/usr/lib/emscripten
  /usr/lib/emscripten/emcmake cmake -G Ninja -B build -S $_pkgfqn \
      -DCMAKE_FIND_ROOT_PATH:PATH="/usr/lib/emscripten/system" \
      -DCMAKE_INSTALL_PREFIX:PATH="/usr/lib/emscripten/system" \
      -DBUILD_SHARED_LIBS=OFF \
      -DFEATURE_static_runtime=ON \
      -DFEATURE_thread=ON \
      -DQT_INCLUDE_DIRS_NO_SYSTEM=ON \
      -DQT_HOST_PATH=/usr
  VERBOSE=1 cmake --build build
}

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

  install -Dm644 $_pkgfqn/LICENSES/* -t "$pkgdir"/usr/share/licenses/$pkgname

  find "${pkgdir}"/usr/lib/emscripten/system -type f -name 'lib*.so' -exec /usr/lib/emscripten/emstrip -g --strip-unneeded {} \;
  find "${pkgdir}"/usr/lib/emscripten/system -type f -name 'lib*.a' -exec /usr/lib/emscripten/emstrip -g {} \;
  [[ -d "${pkgdir}"/usr/lib/emscripten/system/share/doc ]] && rm -r "${pkgdir}"/usr/lib/emscripten/system/share/doc || true
}
