SUMMARY="Full Database Encryption for SQLite"
DESCRIPTION="SQLCipher extends the SQLite database library to add \
security enhancements that make it more suitable for encrypted \
local data storage such as on-the-fly encryption, tamper evidence, \
and key derivation. Based on SQLite, SQLCipher closely tracks SQLite and \
periodically integrates stable SQLite release features."
HOMEPAGE="https://www.zetetic.net/sqlcipher"
COPYRIGHT="2016-2020 ZETETIC LLC"
LICENSE="BSD (3-clause)"
REVISION="1"
SOURCE_URI="https://github.com/sqlcipher/sqlcipher/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="87458e0e16594b3ba6c7a1f046bc1ba783d002d35e0e7b61bb6b7bb862f362a7"
SOURCE_FILENAME="sqlcipher-$portVersion.tar.gz"
PATCHES="sqlcipher-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

libVersion="0.8.6"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"
majorVersion="${portVersion%%.*}"
tclVersion="8.6"

PROVIDES="
	sqlcipher$secondaryArchSuffix = $portVersion
	cmd:sqlcipher$secondaryArchSuffix = $portVersion
	lib:libsqlcipher$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	"

PROVIDES_devel="
	sqlcipher${secondaryArchSuffix}_devel = $portVersion
	devel:libsqlcipher$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	sqlcipher$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:cmp
	cmd:diff
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:sed
	cmd:tclsh$tclVersion
	"

defineDebugInfoPackage sqlcipher$secondaryArchSuffix \
	"$binDir/sqlcipher" \
	"$libDir/libsqlcipher.so.$libVersion"

BUILD()
{
	# Keep up-to-date with sqlite
	CPPFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA=1 \
		-DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_ENABLE_DBSTAT_VTAB \
		-DSQLITE_SECURE_DELETE=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS \
		-DSQLITE_HAS_CODEC -DOMIT_MEMLOCK" \
	LIBS="-Wl,--as-needed -lcrypto" \
	runConfigure ./configure --enable-tempstore --enable-fts3 --enable-fts5 \
		--enable-rtree --disable-tcl

	make $jobArgs
}

INSTALL()
{
	make install

	rm -f "$libDir"/*.la

	install -d -m 755 "$docDir"
	install -t "$docDir" -m 644 README.md

	prepareInstalledDevelLib libsqlcipher
	fixPkgconfig
	packageEntries devel "$developDir"
}

TEST()
{
	make fastfuzztest
}
