# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=coin-or-mp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.8.4
pkgrel=2
pkgdesc="C-API library for CLP, CBC, and CGL. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/coin-or/CoinMP'
msys2_references=(
  'archlinux: coin-or-mp'
)
license=('spdx:CPL-1.0')
groups=("${MINGW_PACKAGE_PREFIX}-coin-or")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-coin-or-cbc"
         "${MINGW_PACKAGE_PREFIX}-coin-or-cgl"
         "${MINGW_PACKAGE_PREFIX}-coin-or-clp"
         "${MINGW_PACKAGE_PREFIX}-coin-or-coinutils")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-coin-or-buildtools")
source=("${url}/archive/releases/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-fix-build-on-mingw.patch")
sha256sums=('ec03a5110d9d79da950669e3400f3b81c4391747b14821d8997f9f8755873150'
            '27fbe44fdfc011e61e061a4471d9757718a3b97695624f035f7fe0c93952527a')

prepare() {
  cp -r ${MINGW_PREFIX}/share/coin-or-buildtools/BuildTools CoinMP-releases-${pkgver}/CoinMP

  cd CoinMP-releases-${pkgver}
  patch -p1 -i "${srcdir}"/001-fix-build-on-mingw.patch

  cd CoinMP

  ACLOCAL="aclocal -I${srcdir}/CoinMP-releases-${pkgver}/CoinMP/BuildTools" \
  autoreconf -fiv
}

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

  export lt_cv_deplibs_check_method='pass_all'

  ../"CoinMP-releases-${pkgver}"/CoinMP/configure \
    --prefix="${MINGW_PREFIX}" \
    --enable-shared \
    --disable-static \
    --enable-dependency-linking \
    ac_cv_c_compiler_gnu=yes

  make
}

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

  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/CoinMP-releases-${pkgver}/CoinMP/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
