# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=cfitsio
pkgver=4.5.0
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)
url='https://heasarc.gsfc.nasa.gov/fitsio/'
license=(LicenseRef-cfitsio)
depends=(curl
         glibc
         zlib)
makedepends=(cmake)
source=(https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/$pkgname-$pkgver.tar.gz)
sha256sums=('e4854fc3365c1462e493aa586bfaa2f3d0bb8c20b75a524955db64c27427ce09')

prepare() {
# Fix install dir for pc and cmake files
  sed -e 's|/lib/|/|g' -i $pkgname-$pkgver/CMakeLists.txt
}

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

check() {
  cd build
  ctest
}

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