# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=redland
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.0.17
pkgrel=1
pkgdesc="Library that provides a high-level interface to RDF (Resource Description Framework) data. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url="https://librdf.org"
msys2_repository_url="https://github.com/dajobe/librdf"
msys2_references=(
  'archlinux: redland'
)
license=('spdx:Apache-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libltdl"
         "${MINGW_PACKAGE_PREFIX}-raptor"
         "${MINGW_PACKAGE_PREFIX}-rasqal")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
             "${MINGW_PACKAGE_PREFIX}-postgresql"
             "${MINGW_PACKAGE_PREFIX}-sqlite3")
optdepends=("${MINGW_PACKAGE_PREFIX}-libmariadbclient: MySQL/MariaDB storage support"
            "${MINGW_PACKAGE_PREFIX}-postgresql: PostgreSQL storage support"
            "${MINGW_PACKAGE_PREFIX}-sqlite3: SQLite storage support")
source=("http://download.librdf.org/source/redland-${pkgver}.tar.gz"
        "001-fix-build-with-mingw.patch")
sha256sums=('de1847f7b59021c16bdc72abb4d8e2d9187cd6124d69156f3326dd34ee043681'
            '7a311554b6838b153425a385baa48e7a1006d94848f9e4dd4a6134dd7eed53f3')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/001-fix-build-with-mingw.patch

  autoreconf -fiv
}

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

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("--enable-release")
  else
    _extra_config+=("--enable-debug")
  fi

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --disable-static \
    --with-mysql=${MINGW_PREFIX}/bin/mariadb_config.exe \
    "${_extra_config[@]}"

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" make install

  install -d "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE-2.0.txt" -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
}
