# Maintainer: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=include-what-you-use
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.25
pkgrel=1
pkgdesc="A tool for use with clang to analyze #includes in C and C++ source files (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://include-what-you-use.org'
msys2_repository_url="https://github.com/include-what-you-use/include-what-you-use"
msys2_references=(
  'aur: include-what-you-use'
)
license=('spdx:NCSA')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-clang-libs"
         "${MINGW_PACKAGE_PREFIX}-llvm-libs"
         "${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-llvm"
             "${MINGW_PACKAGE_PREFIX}-clang-tools-extra")
source=("https://github.com/${_realname}/${_realname}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('2e8381368ec0a6ecb770834bce00fc62efa09a2b2f9710ed569acbb823ead9cc')

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DCMAKE_INSTALL_LIBDIR=lib \
      "${extra_config[@]}" \
      -DPython3_EXECUTABLE=${MINGW_PREFIX}/bin/python \
      -S ${_realname}-${pkgver} \
      -B build-${MSYSTEM}

  cmake --build build-${MSYSTEM}
}

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

  install -Dm644 "${_realname}-${pkgver}"/LICENSE.TXT \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
