# Maintainer: Haroogan <Haroogan@gmail.com>

_realname=tor
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.5.7
pkgrel=2
pkgdesc="Anonymizing overlay network (mingw-w64)"
url="https://www.torproject.org/"
license=('BSD')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
depends=("${MINGW_PACKAGE_PREFIX}-libevent"
         "${MINGW_PACKAGE_PREFIX}-libssp"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-zstd")
makedepends=("${MINGW_PACKAGE_PREFIX}-ca-certificates")
options=('strip')
source=("https://dist.torproject.org/${_realname}-${pkgver}.tar.gz"{,.asc})
sha256sums=('447fcaaa133e2ef22427e98098a60a9c495edf9ff3e0dd13f484b9ad0185f074'
            'SKIP')
validpgpkeys=('2133BC600AB133E1D826D173FE43009C4607B1FB') # Nick Mathewson <nickm@alum.mit.edu>

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  CPPFLAGS="-isystem ${MINGW_PREFIX}/include"
  CFLAGS="-pipe -O3 -fomit-frame-pointer -funroll-loops"
  LDFLAGS="-s -Wl,-s"
  "${srcdir}/${_realname}-${pkgver}/configure" \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --disable-seccomp \
    --disable-libscrypt \
    --enable-lzma \
    --enable-zstd

  make
}

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

  make DESTDIR="${pkgdir}" install

  cd "${srcdir}/${_realname}-${pkgver}"

  install -D "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -d           "${pkgdir}${MINGW_PREFIX}/var/lib/tor"
}
