# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libtommath
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=1
pkgdesc="Highly optimized and portable routines for integer based number theoretic applications (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.libtom.net/LibTomMath/"
msys2_references=(
  "cpe: cpe:/a:libtom:libtommath"
)
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-libtool")
source=("https://github.com/libtom/libtommath/releases/download/v${pkgver}/ltm-${pkgver}.tar.xz"
        "0001-makefile-enable-no-undefined.patch")
sha256sums=('296272d93435991308eb73607600c034b558807a07e829e751142e65ccfa9d08'
            'b770559d51381e078bc84c9162fc711e0e3ebe17b94bc073c00ab5051cf85546')

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

  patch -Np1 -i "${srcdir}/0001-makefile-enable-no-undefined.patch"
}

build() {
  cp -rf "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  make -f makefile.shared \
    CC=${CC} PREFIX=${MINGW_PREFIX}
}

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

  make -f makefile.shared install \
    CC=${CC} PREFIX=${MINGW_PREFIX} DESTDIR="${pkgdir}"

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