[buildout]
extends =
  ../readline/buildout.cfg
  ../tcl/buildout.cfg
  ../xz-utils/buildout.cfg
  ../zlib/buildout.cfg
parts =
  sqlite3

[sqlite3]
recipe = slapos.recipe.cmmi
shared = true
# Some options need the canonical source code (i.e. not as an amalgamation).
url = https://deb.debian.org/debian/pool/main/s/sqlite3/sqlite3_3.46.1.orig.tar.xz
md5sum = b7908531e276de581710c2619f1e8429
configure-options =
  --disable-static
  --disable-tcl
  --enable-update-limit
  --with-readline-inc=-I${readline:location}/include
post-install =
  gcc -I%(location)s/include -fPIC -shared ext/misc/cksumvfs.c -o %(location)s/lib/cksumvfs.so
  set %(location)s/bin/sqlite3-cksumvfs
  cat <<TEMPLATE >$1
  %(cksumvfs)s
  TEMPLATE
  chmod +x $1
# Increase MAX_VARIABLE_NUMBER like many os. For example:
# https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/sqlite
# NEO needs SQLITE_ENABLE_UPDATE_DELETE_LIMIT to drop partitions.
environment =
  CPPFLAGS=-I${zlib:location}/include -DSQLITE_MAX_VARIABLE_NUMBER=250000 -DSQLITE_ENABLE_RTREE=1
  LDFLAGS=-Wl,-rpath=@@LOCATION@@/lib -L${readline:location}/lib -Wl,-rpath=${readline:location}/lib -L${zlib:location}/lib -Wl,-rpath=${zlib:location}/lib
  PATH=${tcl:location}/bin:${xz-utils:location}/bin:%(PATH)s
cksumvfs =
  #!/bin/sh -e
  if [ \$# = 0 ]; then
    x=
  else
    [ "\$${1%%-*}" ]; [ -f "\$1" ] # options not supported
    x=".open \\"\$(printf %s "\$1" |sed 's/[\\\\"]/\\\\\\0/g')\\""
    shift
  fi
  y=/proc/self/fd/3
  [ ! -e \$y ]
  exec @@LOCATION@@/bin/sqlite3 -init \$y '' "\$@" 3<<EOF
  .load cksumvfs.so
  \$x
  EOF
