# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=xapian-core
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libssp"
         "${MINGW_PACKAGE_PREFIX}-zlib")
epoch=1
pkgver=1.4.17
pkgrel=2
pkgdesc='Open source search engine library (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.xapian.org/'
license=('GPL')
# xapian config requires libxapian.la
options=('libtool')
source=("https://oligarchy.co.uk/xapian/${pkgver}/${_realname}-${pkgver}.tar.xz"
        "dont-set-msvcrt-version.patch")
sha256sums=('b5eb8556dea1b0cad4167a66223522e66d670ec1eba16c7fdc844ed6b652572e'
            '9ee6e7994395dd3a9ab55bfe192e511d972cf61282f4a46a6bef88d8f8cc19df')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}"/dont-set-msvcrt-version.patch
  autoreconf -fiv
}

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

  LDFLAGS+=" -fstack-protector"

  LIBS=" -lssp" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

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