# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=osl
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.7
pkgrel=1
pkgdesc="OpenScop Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://icps.u-strasbg.fr/people/bastoul/public_html/development/openscop/index.html"
msys2_references=(
  'aur: osl'
  'gentoo: '
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gmp")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "autoconf-archive")
source=("https://github.com/periscop/openscop/releases/download/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-osl-0.9.2-fix-shared-libs.patch")
sha256sums=('56b4f4053e8d27a74049436a69a679054070e6b7d5cff6954d64bf31d46cd7c7'
            'e84b67954a46105b7007d3ba7fa536ac6d84f3fd3cc8d267b0904b26d33dd186')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-osl-0.9.2-fix-shared-libs.patch"
  autoreconf -fiv
}

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

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --with-gmp=system \
    --with-gmp-prefix=${MINGW_PREFIX}
  
  # Just build library and header includes target since tests will fail from lack of posix headers
  make libosl.la include/osl/scop.h
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install-libLTLIBRARIES install-pkgincludeHEADERS DESTDIR="${pkgdir}"
  install -D -m644 "${srcdir}"/${_realname}-${pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
