# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=nauty
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.8.8
pkgrel=1
pkgdesc="Programs for computing automorphism groups of graphs and digraphs. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://pallini.di.uniroma1.it/'
msys2_references=(
  'archlinux: nauty'
)
license=('spdx:Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://pallini.di.uniroma1.it/nauty${pkgver//./_}.tar.gz"
        001-fix-install-destinations.patch)
sha256sums=('159d2156810a6bb240410cd61eb641add85088d9f15c888cdaa37b8681f929ce'
            '827ad94474d8913967dbbe93bd69a0d89dfa01bd523b586afbc27afab1d1b98e')

prepare() {
  cd nauty${pkgver//./_}
  patch -p1 -i "${srcdir}"/001-fix-install-destinations.patch
}

build() {
  rm -rf "build-${MSYSTEM}"
  cp -r "nauty${pkgver//./_}" "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  ./configure \
    --prefix="${MINGW_PREFIX}" \
    --enable-generic

  make
}

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

  make check || true
}

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

  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/nauty${pkgver//./_}/LICENSE-2.0.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
