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

_realname=swig
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.0.2
pkgrel=2
pkgdesc="Generate scripting interfaces to C/C++ code (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="http://www.swig.org/"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-pcre")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python"
              "${MINGW_PACKAGE_PREFIX}-lua"
              "${MINGW_PACKAGE_PREFIX}-ruby")
source=(https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz
        001-relocate.patch
        002-fix-python-find.patch)
sha256sums=('d53be9730d8d58a16bf0cbd1f8ac0c0c3e1090573168bfa151b01eb47fa906fc'
            'cf76da65d87738b68dbc633aa871f1fb3cb742db1fb603c8a37de2ccbef2b8bb'
            '057f0a306aee0d28a5bb6538b569c650e47c05b9848c9477cdeb7bb8c792944d')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  rm -f Source/Swig/pathtools.c Source/Swig/pathtools.h > /dev/null 2>&1 || true
  patch -p1 -i ${srcdir}/001-relocate.patch
  patch -p1 -i ${srcdir}/002-fix-python-find.patch

  ./autogen.sh
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure\
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --without-perl5 \
    --without-guile \
    --without-python \
    --with-python3=${MINGW_PREFIX}/bin/python
  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -k check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE-UNIVERSITIES "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE-UNIVERSITIES
}
