# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=libtomcrypt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.18.2
pkgrel=4
pkgdesc="A fairly comprehensive, modular and portable cryptographic toolkit (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.libtom.net/LibTomCrypt/"
msys2_references=(
  "cpe: cpe:/a:libtom:libtomcrypt"
  "cpe: cpe:/a:libtomcrypt:libtomcrypt"
)
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-libtommath")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-libtool")
source=("https://github.com/libtom/libtomcrypt/releases/download/v${pkgver}/crypt-${pkgver}.tar.xz"
        "0001-makefile-enable-no-undefined.patch")
sha256sums=('96ad4c3b8336050993c5bc2cf6c057484f2b0f9f763448151567fbab5e767b84'
            '28487492464901ca4a5b0965e5cc0a8ae5f368b4cf12dd03fc9112c25b4d595e')

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

  export CPPFLAGS+=" -DLTM_DESC -DGMP_DESC -DUSE_LTM"
  export EXTRALIBS="-ltommath -lgmp"
  make -f makefile.shared IGNORE_SPEED=1 library test
}

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

  ./test.exe
}

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

  make -f makefile.shared PREFIX="${MINGW_PREFIX}" DESTDIR="$pkgdir" install
  install -Dm644 doc/crypt.pdf "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/crypt.pdf"

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