Tuesday, June 5, 2018

Building SQLite 3.24.0

I'm updating my SQLite to the latest version as by the time of this writing. The last time I did that (on July 2017, hence almost 1 year ago) I was able to build version 3.19.3. This time I'm building version 3.24.0. Just to make things more interesting I'm building it on an even older system, a 32-bits Solaris 11 Express SRU-14, wow!

Roughly speaking the procedure is virtually the same, but there were minor hurdles which I still don't know if they are due to new version or the older system. Anyway, I document the workarounds so that it shall help build some knowledge on the matter for future attempts on building newer versions.

The basic building strategy and general assumptions have been detailed on a previous post Staged Building.

NOTE
I have to conform the tarball filename so that my script could appropriately handle all the preparations. Basically, as root, I've extracted (xf) the tarball and then have archived back (cjf) to a .tar.bz2.
$ pwd
/stage/build

$ ./gnu-build-preparation ../source/.../sqlite-3.24.0.tar.bz2
...

NOTE
The sqlite-3.24.0-32-build is the recommended empty brother of sqlite-3.24.0-32 ZFS clone created by the preceding gnu-build-preparation shell script.
$ mkdir sqlite/sqlite-3.24.0-32-build
$ cd sqlite/sqlite-3.24.0-32-build

NOTE
The setenv script must specify gnu89 for the CFLAGS. It's nevertheless unfortunate that one of the test cases following the make will require c99.
NOTE
I have also updated Tcl/Tk beforehand to latest versions 8.6.8 (as of this writing).
$ source ../setenv-3.24.0 32
...

$ ../sqlite-3.24.0-32/configure \
  --build=i386-pc-solaris2.11 \
  --prefix=/opt/usr \
  --enable-fts3 \
  --enable-fts5  \
  --with-tcl=/opt/usr/lib \
   TCLLIBDIR=/opt/usr/lib 
   LIBS="$(icu-config --ldflags-libsonly)" 
...

$ OPTS="\
-DSQLITE_ENABLE_DBSTAT_VTAB=1 \
-DSQLITE_SECURE_DELETE=1 \
-DSQLITE_THREADSAFE=1 \
-DSQLITE_ENABLE_FTS3=1 \
-DSQLITE_ENABLE_FTS5=1 \
-DSQLITE_ENABLE_UNLOCK_NOTIFY=1 \
-DSQLITE_SOUNDEX \
-DSQLITE_ENABLE_ICU \
-DSQLITE_ENABLE_JSON1 \
-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 \

-DSQLITE_USE_ALLOCA=1 \
-DHAVE_USLEEP \
-DHAVE_STRCHRNUL \
-DHAVE_LOCALTIME_R \
-DHAVE_ISNAN \
-DHAVE_FDATASYNC "


$ gmake -j3 "OPTS=$OPTS"
...


$ gmake test
...
SQLite 2018-06-04 19:24:41 c7ee0833225bfd8c5ec2f9bf62b97c4e04d03bd9566366d5221ac8fb199a87ca
0 errors out of 184438 tests on ... SunOS 32-bit little-endian
All memory allocations freed - no leaks
Maximum memory usage: 9254280 bytes
Current memory usage: 0 bytes
Number of malloc()  : -1 calls


NOTE
The first time gmake test fails, edit the CFLAGS on the Makefile and change it to from gnu89 to c99. Rerun gmake test. The second time it fails, revert the change on the Makefile and rerun once more.
$ sudo gmake install
...

$ sudo zfs snapshot -r .../opt/usr@sqlite-3.24.0

$ ./sqlite3 --version
3.24.0 2018-06-04 19:24:41 ...


$ ./sqlite3
SQLite version 3.24.0 2018-06-04 19:24:41
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
.quit


There one has it!

One may wish to create a symbolic link on $PREFIX such as:

$ sudo bash -c "cd /opt/usr/bin; ln -s sqlite3 sqlite"

$ which sqlite
/opt/usr/bin/sqlite


Great!