# Maintainer: William D. Jones <thor0505@comcast.net>

_realname=yices
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.6.2
pkgrel=1
pkgdesc="Yices is a fast SMT solver with C and Python bindings."
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://yices.csl.sri.com"
license=('GPLv3')
depends=("${MINGW_PACKAGE_PREFIX}-gmp")
makedepends=("dos2unix"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gperf"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=() # 'debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://yices.csl.sri.com/releases/${pkgver}/yices-${pkgver}-src.tar.gz")
sha256sums=('1f205c056dd430f830c688fba6c87d8bd07bd8fa05f65936e12c27e71fa3576a')

prepare() {
  cd "${srcdir}"/yices-${pkgver}

  if [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]]; then
    sed -i "s/-Wl,--no-undefined //g" src/Makefile
  fi
}

build() {
  local build
  local mode

  # Autodetection of build architecture isn't great within the build system.
  # Using config.guess directly works.
  build=`"${srcdir}"/yices-${pkgver}/config.guess`

  if check_option "debug" "y"; then
    mode="debug"
  else
    mode="release"
  fi

  CFLAGS+=" -fcommon"  # work around gcc 10 being stricter here

  [[ -d "${srcdir}"/yices-${pkgver}/build/${build}-${mode} ]] && rm -rf "${srcdir}"/yices-${pkgver}/build/${build}-${mode}
  cd "${srcdir}"/yices-${pkgver}

  ./configure --prefix=${MINGW_PREFIX} \
    --build=${build}

  MODE=${mode} make
}

check() {
  cd "${srcdir}"/yices-${pkgver}
  # make check # wd/parser-bug-reduced fails as of 2.6.1
}

package() {
  cd "${srcdir}"/yices-${pkgver}
  make install DESTDIR="${pkgdir}"

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