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

_realname=coin-or-cgl
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.60.9
pkgrel=1
pkgdesc="COIN-OR Cut Generator Library. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/coin-or/Cgl'
msys2_references=(
  'archlinux: coin-or-cgl'
)
license=('spdx:EPL-2.0')
groups=("${MINGW_PACKAGE_PREFIX}-coin-or")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-coin-or-coinutils"
         "${MINGW_PACKAGE_PREFIX}-coin-or-osi"
         "${MINGW_PACKAGE_PREFIX}-coin-or-clp"
         "${MINGW_PACKAGE_PREFIX}-suitesparse")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-coin-or-buildtools")
source=("${url}/archive/releases/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('558421ccd6aa91d6922dd1baa04e37aa4c75ba0472118dc11779e5d6a19bfb38')

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

  cd Cgl-releases-${pkgver}/Cgl

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

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

  export lt_cv_deplibs_check_method='pass_all'

  CFLAGS+=" -Wno-implicit-function-declaration" \
  ../"Cgl-releases-${pkgver}"/Cgl/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}/Cgl-releases-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
