# 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=qtforkawesome
_pkgver_forkawesome=1.2.0
_reponame_forkawesome=Fork-Awesome-$_pkgver_forkawesome
pkgname=static-compat-qtforkawesome
_name=${pkgname#static-compat-}
pkgver=0.1.0
pkgrel=1
arch=('i686' 'x86_64' 'armv6h' 'armv7h' 'aarch64')
pkgdesc='Library that bundles ForkAwesome for use within Qt applications'
license=('GPL')
depends=('static-compat-qt6-base')
makedepends=('static-compat-cmake' 'ninja' 'perl-yaml-libyaml' 'static-compat-qtutilities' 'static-compat-qt6-declarative' 'clang')
optdepends=(
  'static-compat-qt6-declarative: Qt Quick integration'
  "$_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"
        "${_reponame_forkawesome}::https://github.com/ForkAwesome/Fork-Awesome/archive/refs/tags/${_pkgver_forkawesome}.tar.gz")
sha256sums=('2d71cc6824148194263fda763a78d3ae7ed5a4d0e673181fc5afeabc47e2445e'
            '23fba5f191f204e0414c547bf4c9b10fd7ca42c151260e8f64698449a75fbdb3')

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 \
    -DFORK_AWESOME_FONT_FILE="$srcdir/${_reponame_forkawesome}/fonts/forkawesome-webfont.woff2" \
    -DFORK_AWESOME_ICON_DEFINITIONS="$srcdir/${_reponame_forkawesome}/src/icons/icons.yml" \
    .
  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
}
