# Maintainer: Mateusz Mikuła <mati865@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

pkgname=ccache
pkgver=4.12.1
pkgrel=2
pkgdesc="A compiler cache (mingw-w64)"
arch=('i686' 'x86_64')
url="https://ccache.dev/"
msys2_repository_url="https://github.com/ccache/ccache"
msys2_changelog_url="https://ccache.dev/releasenotes.html"
msys2_references=(
  'anitya: 257'
  'archlinux: ccache'
  'gentoo: dev-util/ccache'
)
license=("spdx:GPL-3.0-or-later")
replaces=("${pkgname}-git")
makedepends=("cmake"
             "ninja"
             "pkgconf"
             "zlib-devel"
             "libzstd-devel"
             "libxxhash-devel"
             'gcc')
depends=("gcc-libs" "zlib" "libzstd" "fmt" "doctest" "libxxhash" "libblake3")
options=('staticlibs' 'strip')
install="${pkgname}.install"
source=(https://github.com/ccache/ccache/releases/download/v${pkgver}/ccache-${pkgver}.tar.xz{,.minisig})
validpgpkeys=("5A939A71A46792CF57866A51996DDA075594ADB8") #Joel Rosdahl <joel@rosdahl.net>
sha256sums=('42e6c4b260cffd92dfa755e26390f45f5842e8c1a5f64f2b2e68adfbe82d1542'
            'bda06a7172e0a9977bd046b3e5623b09c5c5de3028145a09d427af489b521d0b')

prepare() {
  cd "${pkgname}-${pkgver}"
}

build() {
  [[ -d build-${CHOST} ]] && rm -rf build-${CHOST}
  mkdir -p build-${CHOST}  && cd build-${CHOST}

  unset CI
  /usr/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=Release \
    -DREDIS_STORAGE_BACKEND=OFF \
    -DDEPS=LOCAL \
    ../${pkgname}-${pkgver}

  cmake --build .
}

check() {
  cd "build-${CHOST}"
  /usr/bin/ctest .
}

package() {
  cd "${srcdir}/build-${CHOST}"
  DESTDIR="${pkgdir}" cmake --build . --target install

  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/GPL-3.0.txt ${pkgdir}/usr/share/licenses/${pkgname}/GPL-3.0.txt
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/LGPL-3.0.txt ${pkgdir}/usr/share/licenses/${pkgname}/LGPL-3.0.txt
}
