# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=libnova
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.15.0
pkgrel=1
pkgdesc="A general purpose, double precision, celestial mechanics, astrometry and astrodynamics library. (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://libnova.sourceforge.net/"
license=('GPL2')
source=("https://downloads.sourceforge.net/sourceforge/libnova/${_realname}-${pkgver}.tar.gz"
        "libnova-remove-conflicting-definition.patch")
sha256sums=('7c5aa33e45a3e7118d77df05af7341e61784284f1e8d0d965307f1663f415bb1'
            '94b980a65c48ace22851b714f1eadafbf1f9162be3fda40a200ad40538efc161')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/libnova-remove-conflicting-definition.patch"
  autoreconf -fiv
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
