_realname=calceph
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.0.5
pkgrel=1
pkgdesc='The CALCEPH Library is designed to access the binary planetary ephemeris files, such INPOPxx and JPL DExxx ephemeris files (mingw-w64)'
url='https://www.imcce.fr/inpop/calceph'
msys2_repository_url='https://gitlab.obspm.fr/imcce_calceph/calceph'
license=('spdx:CECILL-C OR CECILL-B OR CECILL-2.1')
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || echo "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran")
)
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || echo "${MINGW_PACKAGE_PREFIX}-fc")
)
source=("https://www.imcce.fr/content/medias/recherche/equipes/asd/calceph/${_realname}-${pkgver}.tar.gz")
sha256sums=('3460d8a3e10a86e7fe0228d5d9abcda589713b8ed3ee007ce061ae01f8c2e1ea')

build() {
 
  declare -a extra_config
  [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]]  && extra_config+=("-DENABLE_FORTRAN=OFF")

  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}"

}

check() {
  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}" --target test
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}"

    install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING_CECILL_B.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING_CECILL_B.LIB"
    install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING_CECILL_C.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING_CECILL_C.LIB"
    install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING_CECILL_V2.1.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING_CECILL_V2.1.LIB"
}
