Richard Bucker

Merge Sqlite and Tclsh

Posted at — Apr 5, 2021

I’ve mentioned my DSL strategy before … and while I’m comfortable with bash I’m getting more reliant on tclsh because it’s more granular than bash and sh. I’ve also become more reliant on sqlite3 and from the docs compiling an all-in-one also makes me happy.

Here’s how… for openbsd

sqlite

Download the source and build

ver=3350400
root=${HOME}
fname=sqlite-autoconf-${ver}.tar.gz
dir=sqlite-autoconf-${ver}

if [ ! -f $fname ]; then
  wget -O ${fname} https://sqlite.org/2021/${fname}
fi
if [ -d ${dir} ]; then
  rm -rf ${dir}
fi

tar zxvf ${fname}
cd ${dir}
./configure --prefix=${root}
make install

tcl tools

tclsh does not have readline embedded in it… readline has a crazy GPL requirement. So install the wrapper instead

sudo pkg_add rlwrap

alias tclsh='rlwrap -c tclsh'

tclsh

Download the source and build per usual.

wget https://core.tcl-lang.org/tcl/sqlar/release/tcl.sqlar
sqlite3 tcl.sqlar -Ax
cd tcl/unix
./configure --prefix=$HOME
make
make install
tclsh8.6 <<< 'puts [info patchlevel]'
which tclsh8.6
cd ~/Download/sqlite-autoconf-3350400/tea
./configure --prefix=$HOME --with-tcl=$HOME/lib --with-tclinclude=$HOME/include
make
make install

Now build the loadable sqlitelib for tcl. See the references to how to use the project

cd ~/Download/sqlite-autoconf-3350400/tea/generic
gcc -I$HOME/include -I$HOME/Download/sqlite-autoconf-3350400 -L$HOME/lib -L/usr/lib -o libtclsqlite3.so -shared tclsqlite3.c -lpthread -fPIC
mv libtclsqlite3.so $HOME/lib

Now build the all in one… not the mv command and the name of the executable… there are multiple versions of tclsh all over the place.

cd ~/Download/sqlite-autoconf-3350400/tea/generic
gcc -I$HOME/include -I$HOME/Download/sqlite-autoconf-3350400 -L /home/rbucker/lib/tcl8 -L/usr/local/lib  -DTCLSH=1 tclsqlite3.c  -lpthread -fPIC -ltcl86
mv a.out $HOME/bin/tclshsql

some tests, references, and docs

I was going to document the necessary differences for ClearLinux… but the howto is reasonable… in the commands above remove -fPIC -tcl86 and add -ltcl -ldl.

https://sqlite.org/howtocompile.html
https://www.sqlite.org/tclsqlite.html

DONE