pkgname=coin-or-ipopt
pkgver=3.14.19
pkgrel=5
pkgdesc="Interior Point OPTimizer"
arch=('aarch64' 'armv7h' 'x86_64')
url="https://github.com/coin-or/Ipopt"
license=('EPL')
depends=('lapack' 'coin-or-asl' 'mumps-seq')
source=("https://github.com/coin-or/Ipopt/archive/refs/tags/releases/${pkgver}.tar.gz")
sha256sums=('b3eb84a23812b53a3325bcd2c599de2b0f5df45a18ed251f9e3c1cd893136287')

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

  ../Ipopt-releases-$pkgver/configure \
    CFLAGS="$CFLAGS -O3 -DNDEBUG" \
    CXXFLAGS="$CXXFLAGS -O3 -DNDEBUG" \
    FFLAGS="$FFLAGS -O3" \
    FCFLAGS="$FCFLAGS -O3" \
    --prefix=/usr \
    --enable-shared \
    --enable-static \
    --with-pic \
    --disable-dependency-tracking \
    lt_cv_deplibs_check_method=pass_all \
    --with-lapack-lflags="-llapack" \
    --with-mumps-cflags="-I/usr/include/mumps-seq -I/usr/include/mpiseq" \
    --with-mumps-lflags="-ldmumps_seq -lzmumps_seq -lcmumps_seq -lsmumps_seq -lmumps_common_seq -lmpiseq -lpord_seq -lmetis -llapack -lgfortran -lpthread" \
    --with-asl-cflags="-I/usr/include/coin-or/asl" \
    --with-asl-lflags="-lcoinasl -lrt"
  # Disable spral for now since I got much lower performance
  # (and no threading from OpenBLAS) with this enabled.
  # --with-spral-lflags="-lspral"

  make -j1
}

package() {
  cd "$srcdir/build"
  PKG_CONFIG_LIBDIR="${pkgdir}/usr/lib/pkgconfig/" \
                   make DESTDIR="$pkgdir" install
}
