# Contributor: Dirk Stolle

_realname=buckygen
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.1
pkgrel=1
pkgdesc="A program for the efficient generation of all nonisomorphic fullerenes (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://caagt.ugent.be/buckygen/'
msys2_references=(
  'archlinux: buckygen'
)
license=('spdx:GPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://caagt.ugent.be/buckygen/${_realname}-${pkgver}.zip"
        "001-fix-forward-declaration.patch"
        # GPL 3.0 license file
        "LICENSE")
sha256sums=('c151b33078913bed7f72977821d246c6dda5e01b64a53d963b5f95b65852e634'
            '291e40792e0aa9a919d146c5539bdce9ac2c9803ba0fc0eec11913623096d6ae'
            '3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986')

prepare() {
  cd "${_realname}-${pkgver}"

  # Set CPUTIME to zero to avoid including <sys/times.h> which we don't have on Windows.
  sed -i 's/define CPUTIME 1/define CPUTIME 0/g' buckygen.c

  # Patch old style forward declarations with empty parameter lists.
  patch -Np1 -i ../001-fix-forward-declaration.patch
}

build() {
  cd "${_realname}-${pkgver}"

  make CC="cc ${CFLAGS} ${LDFLAGS}"
}

check() {
  cd "${_realname}-${pkgver}"

  # There are no tests for buckygen in the source archive, so let's just call the program with some
  # random parameters and get some output.
  ./buckygen.exe 15 -a
}

package() {
  cd "${_realname}-${pkgver}"

  install -Dm755 buckygen.exe "${pkgdir}${MINGW_PREFIX}/bin/buckygen.exe"
  install -Dm644 "../LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 "buckygen-guide.txt" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/buckygen-guide.txt"
}
