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

_realname=nauty
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.9.1
pkgrel=2
pkgdesc="Programs for computing automorphism groups of graphs and digraphs. (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' '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")
sha256sums=('488fa906d10a372c72d2364c5dee48e0f7307004fbe52c2bce50c52de8cd873e')

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

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

  # This is required to build shared libraries with libtool, too.
  # Otherwise just the static libraries are generated.
  sed -i 's/allow_undefined=yes/allow_undefined=no/g' libtool

  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"
}
