# Maintainer: Dirk Stolle

_realname=cliquer
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.23
pkgrel=1
pkgdesc="A set of C routines for finding cliques in an arbitrary weighted graph (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://users.aalto.fi/~pat/cliquer.html'
msys2_repository_url='https://github.com/dimpase/autocliquer'
msys2_references=(
  'archlinux: cliquer'
  'gentoo: sci-mathematics/cliquer'
)
license=('spdx:GPL-2.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/dimpase/autocliquer/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-timing-code.patch")
noextract=("${_realname}-${pkgver}.tar.gz")
sha256sums=('089b06d8898a6cf55db3ee100888d1c0099e083db93eba5d1440bfe85ad85b11'
            '2c702be9f7a33f270f20679c4f9791c118d7b7427ad016a3e9f00d8082d41b34')

prepare() {
  # Workaround for symlinks in archive, see <https://www.msys2.org/docs/symlinks/>.
  bsdtar -xzf "${srcdir}/${_realname}-${pkgver}.tar.gz" 2>/dev/null || bsdtar -xzf "${srcdir}/${_realname}-${pkgver}.tar.gz"

  cd "auto${_realname}-${pkgver}"
  # Remove references to <sys/times.h> (not present in MINGW / MSYS2) and its
  # functions to make cliquer build.
  # Patch originally by pranavrajpal at GitHub, taken from passagemath
  # <https://github.com/passagemath/passagemath/commit/a90633c0c1cf7637abf04ad9030bcd626a1f32c1>,
  # slightly modified.
  patch -Nbp1 -i "${srcdir}/0001-fix-timing-code.patch"

  autoreconf -fiv
}

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

  ../"auto${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}" \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "build-${MSYSTEM}"

  make check
}

package() {
  cd "build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

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