pkgname=cmake
pkgver=4.1.0
_basever="${pkgver%.*}"
pkgdesc='A cross-platform open-source make system'
arch=('x86_64')
homepage="https://www.cmake.org/"
license=('custom')
sources=("${pkgname}-${pkgver}.tar.gz")
urls=("https://cmake.org/files/v${_basever}/${sources[0]}")
md5sums=("80ae27faba5068c8ec12c77bf00e6db3")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  sed -i '/"lib64"/s/64//' Modules/GNUInstallDirs.cmake
}

src_build() {
  ./bootstrap --prefix=/usr        \
            --system-libs        \
            --mandir=/share/man  \
            --no-system-jsoncpp  \
            --no-system-cppdap   \
            --no-system-librhash \
            --docdir=/share/doc/${pkgname}-${pkgver} &&
  make
}

src_check() {
  bin/ctest -j${PARALLEL_JOBS}
}

src_install() {
  make DESTDIR="${pkgdir}" install
  install -Dm644 LICENSE.rst -t "${pkgdir}"/usr/share/licenses/$pkgname
}
