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

pkgname=swig
pkgver=4.5.1
pkgrel=1
pkgdesc='Generate scripting interfaces to C/C++ code'
arch=('i686' 'x86_64')
url='https://www.swig.org'
msys2_repository_url='https://github.com/swig/swig'
msys2_documentation_url='https://www.swig.org/doc.html'
msys2_changelog_url='https://www.swig.org/news.html'
msys2_references=(
  'anitya: 4919'
  'archlinux: swig'
  'cygwin: swig'
  'gentoo: dev-lang/swig'
)
license=('spdx:GPL-3.0-or-later AND LicenseRef-SWIG-Universities')
depends=(
  'libpcre2_8'
  'zlib'
)
makedepends=(
  'autotools'
  'gcc'
  'pcre2-devel'
  'zlib-devel'
)
source=(
  "https://github.com/swig/swig/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz"
  '0001-no-stdcall.patch'
)
sha256sums=('dd219a0c8947afe63b818892304390427c2ee7f6edfa1a37853d4efd891982be'
            '61f4b47694e89f566d50702def201bafba2ac84c2b35b3f0a00a5ccb834acf62')

prepare() {
  cd "${pkgname}-${pkgver}"

  patch -Np1 -i "${srcdir}/0001-no-stdcall.patch"

  ./autogen.sh
}

build() {
  cd "${pkgname}-${pkgver}"

  export MSYSTEM=CYGWIN

  ./configure \
    --prefix=/usr \
    --build="${CHOST}"

  make
}

package() {
  cd "${pkgname}-${pkgver}"

  make DESTDIR="${pkgdir}" install

  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm644 LICENSE-UNIVERSITIES "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE-UNIVERSITIES"
}
