# Maintainer: Rafal Brzegowy <rafal.brzegowy@yahoo.com>

_realname=adol-c
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.7.2
pkgrel=7
pkgdesc='Automatic Differentiation of Algorithms written in C/C++ (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/coin-or/ADOL-C'
license=('spdx:EPL-1.0')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-omp")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-boost")
source=(https://github.com/coin-or/ADOL-C/archive/releases/${pkgver}/${_realname}-${pkgver}.tar.gz
        001-do-not-search-for-boost-system.patch)
sha256sums=('701e0856baae91b98397960d5e0a87a549988de9d4002d0e9a56fa08f5455f6e'
            '4f1b56a6399b5fafc4a0344cd47a927aa8cbe1c81e16e2e5e27bb552c1b12e85')

prepare() {
  cd ${_realname}-releases-${pkgver}
  patch -p1 -i "${srcdir}"/001-do-not-search-for-boost-system.patch
  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  local -a extra_config
  extra_config+=(--with-openmp-flag="-fopenmp")
  if [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]]; then
    LDFLAGS+=" -lomp"
  fi

  ../${_realname}-releases-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --with-gnu-ld \
    --libdir=${MINGW_PREFIX}/lib \
    --with-boost=${MINGW_PREFIX} \
    "${extra_config[@]}"

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install DESTDIR="${pkgdir}"
  install -Dm644 "${srcdir}"/${_realname}-releases-${pkgver}/LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}

# vim: ts=2 sw=2 et:
