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

_reponame=qtutilities
pkgname=static-compat-qtutilities
_name=${pkgname#static-compat-}
pkgver=6.14.0
pkgrel=1
arch=('i686' 'x86_64' 'armv6h' 'armv7h' 'aarch64')
pkgdesc='Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models'
license=('GPL')
depends=('static-compat-c++utilities' 'static-compat-qt6-base' 'static-compat-libx11')
makedepends=('static-compat-cmake' 'ninja' 'static-compat-qt6-tools' 'clang')
optdepends=("$_name-doc: API documentation")
url="https://github.com/Martchus/${_reponame}"
source=("${_name}-${pkgver}.tar.gz::https://github.com/Martchus/${_reponame}/archive/v${pkgver}.tar.gz")
sha256sums=('4eab9ef26edf67c1c436596bea42890fcc0206f93c50413939ccce8c94bf7bc0')

build() {
  check_buildoption ccache y && ccache_args='
    -DCMAKE_C_COMPILER_LAUNCHER=ccache
    -DCMAKE_CXX_COMPILER_LAUNCHER=ccache'
  export CXXFLAGS+=' -static-libgcc -static-libstdc++'
  source static-compat-environment
  export PATH=$PWD:$PATH
  printf '#!/usr/bin/bash\nexec /usr/bin/pkg-config --static "$@"\n' > pkg-config
  chmod +x pkg-config
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame-$pkgver}"
  static-compat-cmake -G Ninja \
    -DQT_PACKAGE_PREFIX:STRING='Qt6' \
    -DBUILTIN_TRANSLATIONS:BOOL=ON \
    -DSVG_SUPPORT:BOOL=OFF \
    -DSVG_ICON_SUPPORT:BOOL=OFF \
    .
  ninja
}

check() {
  source static-compat-environment
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame-$pkgver}"
  QT_QPA_PLATFORM=offscreen ninja check
}

package() {
  source static-compat-environment
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame-$pkgver}"
  DESTDIR="${pkgdir}" ninja install
}
