# 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.

pkgname=mingw-w64-clang-aarch64-qt6-activeqt
_qtver=6.8.0
pkgver=${_qtver/-/}
pkgrel=1
arch=(any)
url='https://www.qt.io'
license=(GPL3 LGPL3 FDL custom)
pkgdesc='ActiveX integration framework (mingw-w64-clang-aarch64)'
depends=('mingw-w64-clang-aarch64-qt6-base')
optdepends=('mingw-w64-clang-aarch64-qt6-declarative: QML bindings')
makedepends=('mingw-w64-clang-aarch64-cmake' 'mingw-w64-clang-aarch64-qt6-declarative' 'mingw-w64-clang-aarch64-vulkan-headers' 'mingw-w64-clang-aarch64-vulkan-icd-loader' 'qt6-declarative' 'ninja')
options=('!strip' '!buildflags' 'staticlibs' '!emptydirs')
groups=(mingw-w64-clang-aarch64-qt6)
_pkgfqn="qtactiveqt-everywhere-src-${_qtver}"
source=("https://download.qt.io/official_releases/qt/${pkgver%.*}/${_qtver}/submodules/${_pkgfqn}.tar.xz"
        '0001-Handle-win64-in-dumpcpp-and-MetaObjectGenerator-read.patch'
        '0002-Build-tools-for-the-target-platform.patch'
        '0003-Fix-compile-error-about-missing-QStringView-overload.patch')
sha256sums=('2319df34c52e98bf20e69e09c3bba194d28c7ae5922a67e36601d4e881d5cc5b'
            'f3acb4ec27e59824b1ad45d59dffa628c9dd6290f4790d6533205ad3539899b9'
            '083e7ee89a011bffbe49d3b2635e57863f29bcc9062ad89ee5e83da3f4c639e7'
            'a2f38234e05226a9fee916fcb313402f4bab32a687380fb6ed0f107f319462fd')

_architectures=${MINGW_W64_QT6_ARCHS:-aarch64-w64-mingw32}

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() {
  for _arch in ${_architectures}; do
    source mingw-clang-env $_arch
    export PKG_CONFIG=/usr/bin/$_arch-pkg-config
    $_arch-cmake -G Ninja -B build-$_arch -S $_pkgfqn \
      -DFEATURE_pkg_config=ON
    cmake --build build-$_arch
  done
}

package() {
  for _arch in ${_architectures}; do
    source mingw-clang-env $_arch
    DESTDIR="$pkgdir" cmake --install build-$_arch

    find "$pkgdir/usr/$_arch" -iname '*.exe' -exec $STRIP --strip-all {} \;
    find "$pkgdir/usr/$_arch" -iname '*.dll' -exec $STRIP --strip-unneeded {} \;
    find "$pkgdir/usr/$_arch" -iname '*.a'   -exec $STRIP -g {} \;
    [[ -d "$pkgdir/usr/$_arch/share/doc" ]] && rm -r "$pkgdir/usr/$_arch/share/doc"
  done

  install -d "$pkgdir"/usr/share/licenses
  ln -s /usr/share/licenses/mingw-w64-clang-aarch64-qt6-base "$pkgdir"/usr/share/licenses/$pkgname

}
