# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=perl-dbd-sqlite
pkgver=1.76
pkgrel=2
pkgdesc="Self-contained RDBMS in a DBI driver"
arch=('x86_64')
url="https://search.cpan.org/dist/DBD-SQLite"
license=('GPL' 'PerlArtistic')
depends=('perl-dbi' 'sqlite')
source=("https://www.cpan.org/authors/id/I/IS/ISHIGAKI/DBD-SQLite-$pkgver.tar.gz"
        $pkgname-sqlite-3.37.patch::https://github.com/DBD-SQLite/DBD-SQLite/commit/ba4f472e7372.patch
        libsqlite.patch)
sha512sums=('3c2d9f2dc9a544b03474913d416e09a3aa5ce74c9359603211dfd6ad7dfa91fd9920480ab3e1572ba8bea486372477214471a8859b9d88f384a1edfebc3ff926'
            'ed468728a6a1d1e7228ccb8df9fd14ad0c22ae7b5e1b9e7bb32352e4e34794684bcd570da322a94f34e8e967d6155520c4f4652c0ec2f4d0fc0aee6f89314ec7'
            'cf492402f9127c40130c052a6b3f78e86abc0342385130be386aa12e23b1166f20deac50eee1dcc1e43598ba5785d0a218f2cb0a6bb7f5dd7f7c0fc3220bd2bb')

prepare() {
  cd DBD-SQLite-$pkgver

  # Ensure that we can never ever build this. If the perl module links against
  # the system lib this won't matter, if it does not, it will fail during
  # make test.
  rm sqlite3.c

  # https://github.com/DBD-SQLite/DBD-SQLite/issues/92
  patch -Np1 -i ../$pkgname-sqlite-3.37.patch

  # Makefile asks us to patch this to allow to link with system sqlite...
  patch -i "$srcdir/libsqlite.patch"
}

build() {
  cd DBD-SQLite-$pkgver

  # USE_LOCAL_SQLITE=0 disables use of the bundled sqlite
  perl Makefile.PL INSTALLDIRS=vendor USE_LOCAL_SQLITE=0
  make
}

check() {
  cd DBD-SQLite-$pkgver
  make test
}

package() {
  cd DBD-SQLite-$pkgver
  make install DESTDIR="$pkgdir"
}
