# Maintainer: Mateusz Mikuła <mati865@gmail.com>

_realname=sqlcipher
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.4.3
pkgrel=1
pkgdesc="SQLite extension that provides transparent 256-bit AES encryption of database files"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.zetetic.net/sqlcipher/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-tcl")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/${_realname}/${_realname}/archive/v${pkgver}.tar.gz"
        "02-fix-tcl-find.patch")
sha256sums=('b8df69b998c042ce7f8a99f07cf11f45dfebe51110ef92de95f1728358853133'
            'd30c43a28eaeedcafde98d0f9a76fd8d676ee77732c9dc38e028147faa5adca0')

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

  patch -p1 -i "${srcdir}"/02-fix-tcl-find.patch
  autoreconf -fiv
}

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

  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-tempstore=yes \
    --disable-tcl \
    --enable-json1 \
    --enable-fts4 \
    --enable-fts5 \
    --enable-rtree \
    --enable-session \
    --disable-editline \
    --enable-readline \
    --with-readline-lib="-L${MINGW_PREFIX}/lib -lreadline" \
    --with-readline-inc="-I${MINGW_PREFIX}/include" \
    CFLAGS="$CFLAGS -DSQLITE_HAS_CODEC -DSQLITE_ENABLE_COLUMN_METADATA" \
    LDFLAGS="$LDFLAGS -lcrypto"

  make
}

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

  cd "${srcdir}"/${_realname}-${pkgver}
  install -Dm644 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
