# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Andreas Radke <andyrtr@archlinux.org>
# Contributor: spider-mario <spidermario@free.fr>
# Contributor: Daniel Ehlers <danielehlers@mindeye.net>

pkgname=coin-or-mp
pkgver=1.8.4
pkgrel=6
pkgdesc='C-API library that supports most of the functionality of CLP (Coin LP), CBC (Coin Branch-and-Cut), and CGL (Cut Generation Library) projects'
arch=(x86_64 aarch64)
url='https://projects.coin-or.org/CoinMP'
license=(EPL)
groups=(coin-or)
depends=(coin-or-cbc
         coin-or-cgl
         coin-or-clp
         coin-or-coinutils
         gcc-libs
         glibc)
source=(https://www.coin-or.org/download/source/CoinMP/CoinMP-$pkgver.tgz)
sha256sums=('3459fb0ccbdd39342744684338984ac4cc153fb0434f4cae8cf74bd67490a38d')

prepare() {
  cd CoinMP-$pkgver/CoinMP
  # Apply same fix as for coin-or-coinutils
  cp -vf /usr/share/autoconf/build-aux/config.guess .
  cp -vf /usr/share/autoconf/build-aux/config.sub .
}

build() {
  cd CoinMP-$pkgver/CoinMP
  export CXXFLAGS+=" -Wp,-U_GLIBCXX_ASSERTIONS"
  ./configure --prefix=/usr \
              --with-osi-lib="$(pkg-config --libs osi)" \
              --with-osi-incdir="/usr/include/coin/" \
              --with-clp-lib="$(pkg-config --libs clp)" \
              --with-clp-incdir="/usr/include/coin/" \
              --with-cgl-lib="$(pkg-config --libs cgl)" \
              --with-cgl-incdir="/usr/include/coin/" \
              --with-cbc-lib="$(pkg-config --libs cbc)" \
              --with-cbc-incdir="/usr/include/coin/" \
              --with-coinutils-lib="$(pkg-config --libs coinutils)" \
              --with-coinutils-incdir="/usr/include/coin/"
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool # Fix overlinking
  make
}

check() {
  cd CoinMP-$pkgver/CoinMP
  make test
}

package() {
  cd CoinMP-$pkgver/CoinMP

  make DESTDIR="$pkgdir" install
  rm -r "$pkgdir"/$(dirname "${srcdir}")
}
