# SliTaz package receipt.

PACKED_SIZE="452.0K"
UNPACKED_SIZE="1.0M"
PACKAGE="sqlite"
_realver="3390200"
VERSION="$(printf "%d.%d.%d" ${_realver:0:1} ${_realver:1:2} ${_realver:3:2})"
CATEGORY="office"
SHORT_DESC="Small SQL database engine."
MAINTAINER="pankso@slitaz.org"
LICENSE="PublicDomain"
WEB_SITE="https://www.sqlite.org/index.html"

TARBALL="$PACKAGE-src-${_realver}.zip"
WGET_URL="http://www.sqlite.org/2022/$TARBALL"

EXTRA_SOURCE_FILES="mysql2sqlite.sh"

DEPENDS="libsqlite"
BUILD_DEPENDS="tcl-dev"

HOST_ARCH="i486 arm"

current_version()
{
	wget -O - $WEB_SITE 2>/dev/null | \
	sed '/Version [0-9]/!d;s|.*Version \(.*\)<.*|\1|' | sed q
}

# Rules to configure and make the package.
compile_rules()
{
	case "$ARCH" in
		(arm*)
			ARCH_ARGS="--with-tcl=/cross/arm/sysroot/usr/lib"
			;;
	esac

	[ -s "$SOURCES_REPOSITORY/mysql2sqlite.sh" ] ||
		wget -O "$SOURCES_REPOSITORY/mysql2sqlite.sh" \
			https://gist.github.com/esperlu/943776/raw/dd87f4088f6d5ec7563478f7a28a37ba02cf26e2/mysql2sqlite.sh

	export CFLAGS="$CFLAGS -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_SECURE_DELETE -DSQLITE_ENABLE_UNLOCK_NOTIFY=1 -DSQLITE_ENABLE_DBSTAT_VTAB=1 -DTCLSH=1"

	./configure			\
		--prefix=/usr		\
		--disable-readline	\
		--enable-load-extension	\
		LDFLAGS="$LDFLAGS -ldl"	\
		$ARCH_ARGS		\
		$CONFIGURE_ARGS &&
	make &&
	make install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	cook_copy_folders	bin
	cp "$SOURCES_REPOSITORY/mysql2sqlite.sh"	$fs/usr/bin

	chmod +x					$fs/usr/bin/mysql2sqlite.sh
	if [ -f $fs/usr/bin/lemon ]
	  then
		rm -f $fs/usr/bin/lemon
	fi
}
