# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=liboauth
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.3
pkgrel=7
pkgdesc="liboauth is a collection of POSIX-c functions implementing the OAuth Core RFC 5849 standard (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://liboauth.sourceforge.io/"
msys2_repository_url="https://github.com/x42/liboauth"
license=('spdx:MIT OR GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-nss")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/x42/liboauth/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "noundefined.patch")
sha256sums=('bbe73b9f576fab0deefadb242c069f2f8bfa4068c738b7666ccd01381502c854'
            'ae77e26395eedd19e27359579ace90976e6d7746bb3fcfa56493c2b1a60f9970')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/noundefined.patch

  autoreconf -fi
}

build() {
  mkdir -p build-${MSYSTEM}
  cd build-${MSYSTEM}

  ../${_realname}-${pkgver}/configure \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib \
    --enable-nss

  make
  # make dox # Generate doxygen docs
}

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

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING.GPL \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-GPL
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING.MIT \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-MIT
}
