# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=fastfetch
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.56.1
pkgrel=1
pkgdesc="An actively maintained, feature-rich and performance oriented, neofetch like system information tool (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url="https://github.com/fastfetch-cli/fastfetch"
msys2_changelog_url='https://github.com/fastfetch-cli/fastfetch/blob/dev/CHANGELOG.md'
msys2_references=(
  'anitya: 279670'
  'archlinux: fastfetch'
  'aur: fastfetch-git'
  'gentoo: app-misc/fastfetch'
)
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-chafa"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-imagemagick"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-vulkan-loader"
             "${MINGW_PACKAGE_PREFIX}-vulkan-headers"
             "${MINGW_PACKAGE_PREFIX}-opencl-icd"
             "${MINGW_PACKAGE_PREFIX}-opencl-headers"
             "${MINGW_PACKAGE_PREFIX}-cppwinrt")
optdepends=("${MINGW_PACKAGE_PREFIX}-vulkan-loader: For Vulkan detection support"
            "${MINGW_PACKAGE_PREFIX}-opencl-icd: For OpenCL detection support"
            "${MINGW_PACKAGE_PREFIX}-chafa: For chafa image protocol support"
            "${MINGW_PACKAGE_PREFIX}-imagemagick: For sixel image protocol support")
source=("https://github.com/fastfetch-cli/fastfetch/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('6ffd75c32b2a885fd8497867645ac837ed37d588c94e0df05408cdaa0c8fd2c7')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;-DCMAKE_INSTALL_SYSCONFDIR=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    "${extra_config[@]}" \
    -DCMAKE_INSTALL_SYSCONFDIR=${MINGW_PREFIX}/etc \
    -DPython_EXECUTABLE=${MINGW_PREFIX}/bin/python \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
