# Maintainer: Diego Sogari <diego.sogari@falker.com.br>

_realname=nanodbc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.14.0
pkgrel=2
pkgdesc="A small C++ wrapper for the native C ODBC API (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://nanodbc.io/"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=(https://github.com/nanodbc/nanodbc/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz
        "0001-disable-werror.patch")
sha256sums=('56228372042b689beccd96b0ac3476643ea85b3f57b3f23fb11ca4314e68b9a5'
            '84a809a25e252229cad5ed1d4eee6a0a24c2c8405bdc69b60a518e4f184d7824')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}"/0001-disable-werror.patch
}

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -DNANODBC_DISABLE_ASYNC=ON \
    -DNANODBC_DISABLE_EXAMPLES=ON \
    -DNANODBC_DISABLE_TESTS=ON \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/cmake --build .
}

#check() {
#  Note: to run the tests it would be necessary to have installed at least the
#  SQLite ODBC drivers for both 32- and 64-bit. In our local Windows machine,
#  all tests passed. The drivers used were:
#    - SQLite3 ODBC Driver 32-bit (version 0.9993.00.00)
#    - SQLite3 ODBC Driver 64-bit (version 0.9993.00.00)
#    - MySQL ODBC 5.3 ANSI Driver 32-bit (version 5.03.04.00)
#    - MySQL ODBC 5.3 ANSI Driver 64-bit (version 5.03.04.00)
#    - MySQL ODBC 5.3 Unicode Driver 32-bit (version 5.03.04.00)
#    - MySQL ODBC 5.3 Unicode Driver 64-bit (version 5.03.04.00)
#
#  cd "${srcdir}/build-${MSYSTEM}"
#  export NANODBC_TEST_CONNSTR=`cat ../../connection_string.txt`
#  SAVED_PATH=${PATH}
#  PATH=`pwd`:${PATH}
#  make test
#  PATH=${SAVED_PATH}
#}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
}
