# Maintainer: Ben Poest <ben@poest.com>
# Contributor: Jolly_Roberts
# Contributor: dreieck
# Contributor: Cirk2

_pkgname=libcpufeatures
pkgname="${_pkgname}-git"
epoch=2
pkgver=v0.11.0.r6.g5514d93
pkgrel=1
pkgdesc="A cross-platform C library to retrieve CPU features (such as available instructions) at runtime. By google."
url="https://github.com/google/cpu_features"
arch=(
  'i686'
  'x86_64'
)
license=(Apache)
depends=(
  'glibc'
)
makedepends=(
  'cmake'
  'git'
)
provides=(
  "${_pkgname}=${pkgver}"
)
conflicts=(
  "${_pkgname}"
  'libvolk'
)
source=(
  "${_pkgname}::git+https://github.com/google/cpu_features.git#branch=main"
)
sha256sums=(
  'SKIP'
)

prepare() {
  mkdir -p "${srcdir}/build"
  cd "${srcdir}/build"

  # cmake issued in `prepare()` since it downloads stuff.
  cmake "${srcdir}/${_pkgname}" \
    -DCMAKE_INSTALL_PREFIX=/ \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_TESTING=OFF
}

pkgver() {
  cd "${srcdir}/${_pkgname}"
  git describe --long --tags --abbrev=7 | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

build() {
  cd "${srcdir}/build"

  make
}

package() {
  cd "${srcdir}/build"
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_pkgname}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

