First, we download the sqlite-2002 (i.e. sqlite-2.2.1
release) sources. We will use the following folder in
user's home folder to store all the files related to this
exercise: $HOME/sr/sqlite/2.2.1/.
## Download source for sqlite-2.2.1
mkdir -p $HOME/sr/sqlite/2.2.1/
cd $HOME/sr/sqlite/2.2.1/
wget https://www.sqlite.org/src/tarball/61c38f3b/SQLite-61c38f3b.tar.gz
tar -zxvf SQLite-61c38f3b.tar.gz
mv SQLite-61c38f3b sqlite
Next, we look for instructions to compile the source code in Unix like platform. Such instructions are commonly included in a README file contained within the source distribution.
$ cat sqlite/README
This directory contains source code to
SQLite: An SQL Database Engine in a C Library
...
tar xzf sqlite.tar.gz ;# Unpack the source tree into "sqlite"
mkdir bld ;# Build will occur in a sibling directory
cd bld ;# Change to the build directory
../sqlite/configure ;# Run the configure script
make ;# Run the makefile.
...
Recall that the compilation instructions were prepared in the year 2002 and at that time the developers of SQLite could not have seen how hardware and software platforms would change in 20 years. Still, the compilation instructions looks familiar to a reader in the year 2022. We start the compilation process as advised by the SQLite developers.
## Build sqlite-2.2.1
cd $HOME/sr/sqlite/2.2.1/
mkdir build
cd build
../sqlite/configure
All the above commands successfully execute to
completion. In the next section, we execute the build
process using the make command and get a
glimpse of our first issue.
The sqlite-2002 software can be built using the GCC
compiler by executing the make as follows.
$ make gcc -g -O2 -o lemon ../sqlite/tool/lemon.c In file included from ../sqlite/tool/lemon.c:10: /usr/lib/gcc/x86_64-linux-gnu/10/include/varargs.h:4:2: error: #error "GCC no longer implements <varargs.h>." 4 | #error "GCC no longer implements <varargs.h>." | ^~~~~ /usr/lib/gcc/x86_64-linux-gnu/10/include/varargs.h:5:2: error: #error "Revise your code to use <stdarg.h>." 5 | #error "Revise your code to use <stdarg.h>." | ^~~~~ ... ../sqlite/tool/lemon.c:1096:1: error: expected declaration specifiers before ‘va_dcl’ 1096 | va_dcl | ^~~~~~ ...
sqlite-2002 does not compile in gcc-10.2.1 (2021) and
autoconf 2.69 (2012) because tool/lemon.c
uses varargs.h which was deprecated by the gcc
compiler since 4.0 (2005) release. How would we fix this
compilation issue? Learners will be able to go through the
experience of true self learning — which may lead to
some profound insights, for example, about atomic version
control commits — if they work to find a solution to
this issue on their own. Clicking the "Issue 1:
..." box below will first reveal a tip which may help
arrive at the solution.
The vararg issue was fixed only in
sqlite-2.8.1
release by replacing dependence on varargs.h
with
stdarg.h. Unfortunately, a fix for this issue
did not appear in a single commit and therefore we had to
selectively we borrow code updates for
tool/lemon.c
from sqlite-2.8.1
release. The patch that fixes this issue can be applied to
sqlite-2.2.1 source code as follows.
## Apply patch to fix the issue about <varargs.h> (i.e. Issue 1)
mkdir -p $HOME/sr/sqlite/2.2.1/patches
cd $HOME/sr/sqlite/2.2.1/patches
wget https://abhishekdutta.org/sr/exercise/sqlite/2.2.1/patches.tar.gz
tar -zxvf patches.tar.gz
cd $HOME/sr/sqlite/2.2.1/sqlite
patch -p1 < $HOME/sr/sqlite/2.2.1/patches/1-varargs.patch
The patching process confirmation is provided by the following message.
patching file tool/lemon.c
After fixing Issue
2.1, we run the make command again to continue
the build process for sqlite-2002.
## Build sqlite-2.2.1 again after fixing Issue 1
cd $HOME/sr/sqlite/2.2.1/build
../sqlite/configure
make
The compilation process proceeds ahead and now stops at another point with the following compilation error message.
../sqlite/src/shell.c:50:14: error: conflicting types for 'getline'
50 | static char *getline(char *zPrompt, FILE *in){
| ^~~~~~~
In file included from ../sqlite/src/shell.c:19:
/usr/include/stdio.h:616:18: note: previous declaration of 'getline' was here
616 | extern __ssize_t getline (char **__restrict __lineptr,
| ^~~~~~~
make: *** [Makefile:129: sqlite] Error 1
The error message suggests that getline() method defined in
src/shell.c:50 of sqlite-2002 source conflicts with
the getline() method defined in <stdio.h>
standard library.
If we search the version control system of sqlite for the
keyword "getline()",
we get only one result which corresponds to
the commit
that resolved the name conflict. The conflict resolution
(see patch)
involved renaming the method
to local_getline().
The patch that fixes this issue can be viewed here and this patch can be applied to the sqlite-2002 source as follows.
## Apply patch to fix the issue about(i.e. Issue 1) ## Assumption: Issue 1 (i.e. varargs issue) has already been fixed cd $HOME/sr/sqlite/2.2.1/sqlite patch -p1 < $HOME/sr/sqlite/2.2.1/patches/2-getline.patch
The patching process confirmation is provided by the following message.
patching file src/shell.c
After fixing Issue 2, the sqlite-2002 source
compiles successfully and produces the executable
(e.g. sqlite) that can be used to run the SQLite
database engine.
$ cd $HOME/sr/sqlite/2.2.1/build && make
...
gcc -g -O2 -DOS_UNIX=1 -DOS_WIN=0 -DHAVE_USLEEP=1 -I. -I../sqlite/src -DHAVE_READLINE=1 -I/usr/include/readline -o .libs/sqlite ../sqlite/src/shell.c ./.libs/libsqlite.so -lreadline -Wl,--rpath -Wl,/usr/local/lib
creating sqlite
In the next section, we test the sqlite-2002 software on a modern platform.