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

_realname=libotr
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.1.1
pkgrel=6
pkgdesc="Off-the-Record Messaging Library and Toolkit (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.cypherpunks.ca/otr/"
msys2_references=(
  "cpe: cpe:/a:cypherpunks:libotr"
)
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-libgcrypt")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=(https://otr.cypherpunks.ca/${_realname}-${pkgver}.tar.gz{,.asc}
        '002-libotr-no-undefined.patch'
        '003-fix-symlinks.patch')
sha256sums=('8b3b182424251067a952fb4e6c7b95a21e644fbb27fbd5f8af2b2ed87ca419f5'
            'SKIP'
            '4e7f9cc91ec623687d26d26e2f5e735df0de6bd0ab429f30d55f35a54be628e6'
            'f91be0fea077a562d39e50bb53d9b7dcca87bdb9303ee4fe63dc4be047947c9b')
validpgpkeys=('22DF3305DF56667CE15784FCF24DE08F42C2ABAD') # OTR Dev Team (Signing Key) <otr@cypherpunks.ca>

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/002-libotr-no-undefined.patch
  patch -p1 -i "${srcdir}"/003-fix-symlinks.patch

  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --mandir=${MINGW_PREFIX}/share/man

  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make -j1 DESTDIR="${pkgdir}" install
}
