# Maintainer: Dirk Stolle

_realname=bliss
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.77.r17.g104c138
pkgrel=1
_commit=104c1384251ea56d1a30abf4f5bd78d396d12ccc
pkgdesc="tool for computing canonical labelings and automorphism groups of graphs (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://users.aalto.fi/~tjunttil/bliss/'
msys2_repository_url='https://github.com/scipopt/bliss'
msys2_references=(
  'archlinux: bliss'
  'gentoo: sci-libs/bliss'
)
license=('spdx:LGPL-3.0-only')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "git")
source=("git+https://github.com/scipopt/bliss#commit=${_commit}")
sha256sums=('0e4b226ac69052c75cafebf6f40173aa3652eee6a65513eb6c4372d1bd54652f')

pkgver() {
  cd "${srcdir}/${_realname}"
  git describe --long --tags ${_commit} | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//g'
}

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DBUILD_{SHARED,STATIC}_LIBS=ON \
      -DCMAKE_POLICY_VERSION_MINIMUM=3.11 \
      -S "${_realname}" \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

check() {
  # There are no tests in the bliss source code, so let's just try to run the main executable as a
  # kind of minimal test that it works.
  ./"build-${MSYSTEM}"/bliss.exe -help
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}/${_realname}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 "${srcdir}/${_realname}/COPYING.LESSER" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LESSER"
}
