# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Tobias Powalowski <tpowa@archlinux.org>

pkgname=cfitsio
pkgver=4.6.3
pkgrel=1
epoch=1
pkgdesc='A library of C and Fortran subroutines for reading and writing data files in FITS (Flexible Image Transport System) data format'
arch=(x86_64 aarch64)
url='https://heasarc.gsfc.nasa.gov/fitsio/'
license=(LicenseRef-cfitsio)
depends=(curl
         glibc
         zlib)
makedepends=(cmake
             git)
source=(git+https://github.com/HEASARC/cfitsio#tag=cfitsio-$pkgver)
sha256sums=('5464c0e2b7250eed64fea975b2408211269aef702a0689e0bcd816b7cc769c4e')

build() {
  cmake -B build -S $pkgname \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DUSE_PTHREADS=ON \
    -DTESTS=OFF \
    -DUTILS=ON
  cmake --build build
}

check() {
  cd build
  ctest
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -D -m644 $pkgname/licenses/* "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

# Rename generic binaries
  for _bin in imcopy smem speed; do
    mv "$pkgdir"/usr/bin/{,cfitsio-}$_bin
  done
}
