How to
compile SQLite with JDBC for an iPAQ.
Author:
Christoph Kecher
Contact: kecher@gmx.de
Version: 0.3
Date:
08.08.2003
Changes:
0.1 29.12.2002 Kecher File created
0.2 03.01.2003 Kecher Some files were unnecessarily copied to the
iPAQ, corrected
0.3 08.08.2003 Kecher Added Link to an Archive
containing the precompiled Files
This Howto describes step-by-step the
compilation of the JDBC-Driver (written by Christian Werner) for an
Compaq-iPAQ (3800 Series) running the Familiar-distribution (0.5.3)
of Linux.
I owe many thanks to Christian Werner, who
implemented the JDBC-Driver for SQLite and who helped me a lot
compiling his driver for the iPAQ.
I assume that you
are familiar with basic usage of Linux, that you know what „to
compile“ means and what a Makefile is. This will help you a lot
doing the next steps. But nevertheless, I will try to explain the
steps as precisely as I can, so a „Linux-newbie“ still
will be able to use the SQLite database
with a JDBC-Interface on his iPAQ.
Furthermore you need a PC
running Linux. I used the Suse 8.1 distribution, but it should work
with other up-to-date distributions, too. You can find an Archive
containing the precompiled files for this configuration under
http://www.kecher.de/howtos/sqlite-jdbc.tgz.
To
put Linux on your iPAQ, visit the
www.handhelds.org
homepage. There you'll find every information you need to run Linux
on your iPAQ. Furthermore you'll learn there, how to connect from
your PC to your iPAQ and how to install software on it.
Step 1: Install Java on your iPAQ
If
you followed the descriptions on the www.handhelds.org
page you should be
able to install the blackdown-jdk1.3 using the Familiar packet
manager ipkg:
#ipkg install
java1.3
Make sure that you've got enough memory left on
your iPAQ before installing Java. You'll need about 16MByte of Flash
left for the blackdown-JVM.
You can easily test if the
installation was successful by using the following command:
#java
-version
If you get an output like this, everything
worked fine:
java version
"1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition
(build Blackdown-1.3.1-RC1)
Classic VM (build Blackdown-1.3.1-RC1,
native threads, nojit)
Step 2: Install
SQLite on your iPAQ:
Just
do it the same way you installed Java:
#ipkg
install sqlite
After a successful installation you
should be able to type this into your iPAQ-shell:
#
sqlite test.db
And see something like this:
SQLite
version 2.7.4
Enter ".help" for
instructions
sqlite>
What you see is the
interactive SQLite shell. Now you can enter SQL-commands supported by
SQLite. For further information on SQLite and supported SQL-commands
visit www.hwaci.com/sw/sqlite/.
Step 3:
Download the Arm-Linux-Cross-Compiler to your PC
You
can use any cross-compiler you like. You can download one from
www.zauruszone.com
or from www.handhelds.org.
Here
are the direct links to get the compiler:
From zauruszone:
http://www.zauruszone.com/howtos/downloads/gcc-cross-sa1100-2.95.2-0.i386.rpm
http://www.zauruszone.com/howtos/downloads/binutils-cross-arm-2.11.2-0.i386.rpm
http://www.zauruszone.com/howtos/downloads/glibc-arm-2.2.2-0.i386.rpm
http://www.zauruszone.com/howtos/downloads/linux-headers-arm-sa1100-2.4.6-3.i386.rpm
From
handhelds:
http://handhelds.org/download/toolchain/arm-linux-libz.tar.gz
http://handhelds.org/download/toolchain/arm-linux-toolchain-current.tar.gz
Install
the packages using rpm. For example, to install the arm gcc compiler,
this should be run:
rpm
-Uvh gcc-cross-sa1100-2.95.2-0.i386.rpm
Add the path to
the new compiler to your PATH-environment-variable
by typing:
export
PATH=/opt/Embedix/tools/bin/:$PATH
You can check, if it
worked by using the
echo
$PATH
command.
Now you should be able to type
arm-linux-gcc --version
and
should see the version number of your cross-compiler:
2.95.2
Now
your cross compiler is working.
Step 4:
Download the SQLite-Sources
Get
the sources from http://www.hwaci.com/sw/sqlite/download.html
.
Download the newest version of the source tree
including all documentation, currently it is
sqlite-2.7.4.tar.gz.
Unpack
it using the command
tar -xvzf
sqlite-2.7.4.tar.gz
Now create a new directory named
“build”:
mkdir
build
Step 5: Compile
SQLite using the cross-compiler
Change into the
sqlite
directory and open the configure-script
using your favorite text-editor.
Comment
out the following commands by putting a '#'
in front of them:
#if
test "$cross_compiling" = "yes"; then
# { { echo "$as_me:12710: error: unable to find a compiler for building build tools" >&5
#echo "$as_me: error: unable to find a compiler for building build tools" >&2;}
# { (exit 1); exit 1; }; }
#fi
. . .
#else
# test "$cross_compiling" = yes &&
# { { echo "$as_me:13264: error: cannot check for file existence when cross compiling" >&5
#echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}
# { (exit 1); exit 1; }; }
.
. .
#else
# test "$cross_compiling" = yes &&
# { { echo "$as_me:13464: error: cannot check for file existence when cross compiling" >&5
#echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}
# { (exit 1); exit 1; }; }
.
. .
#else
# test "$cross_compiling" = yes &&
# { { echo "$as_me:13490: error: cannot check for file existence when cross compiling" >&5
#echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}
# { (exit 1); exit 1; }; }
Save
the configure
script, change into the build directory you created and call the
edited configure
script from the sqlite
directory by using the following option:
../sqlite/configure
--host=arm-linux
After
that configure should have
created a Makefile and a
libtool script in your build
directory.
Open the Makefile
using your favorite text editor and edit the following lines:
$(BCC)
-o temp temp.c
change into:
gcc
-o temp temp.c
$(BCC)
-o lemon $(TOP)/tool/lemon.c
change into:
gcc
-o lemon $(TOP)/tool/lemon.c
The
reason for these changes is that the created files have to be
executed on the PC during the compilation, so we have to compile them
with the standard gcc
and not the arm-linux-gcc.
Now
you should find a “.libs”
directory in your build
directory containing sqlite shared object files, like
libsqlite.so.
Step 6:
Download the JDBC-Driver-Source from Christian Werners Homepage
Get
it from http://www.ch-werner.de/javasqlite/javasqlite-20020724.tar.gz
.
Unpack it and change into the newly created directory
javasqlite-20020724.
Step 7: Compile
Christians JDBC-Driver using the arm-linux cross compiler
Call
the configure
script to create a Makefile
and a libtool
script using the following command:
CC=arm-linux-gcc
LD=arm-linux-ld ./configure
In
this command we first set the environment variables CC
for the standard compiler and LD
for the standard linker to our cross-compile-tools.
Now open
the Makefile
using your favorite text editor. Edit the following
lines:
SQLITE_INC =
/usr
change
into:
SQLITE_INC =
../build/
SQLITE_LIB
= /usr/lib/libsqlite.la
change
into:
SQLITE_LIB =
../build/libsqlite.la
LIBS=
/usr/lib/libsqlite.la
change
into:
LIBS=
../build/libsqlite.la
$(LIBTOOL)
$(CC) -I$(SQLITE_INC) -o native/mkconst native/mkconst.c
$(LIBS)
change into
gcc
-o native/mkconst -I"../build" native/mkconst.c
-L"../build" -lsqlite
Open
the script file libtool
with your favorite compiler and make sure that the variable CC
is set to arm-linux-gcc
and LD
to arm-linux-ld.
Compile
the JDBC-Driver using the following command:
make
CC=arm-linux-gcc LD=arm-linux-ld all
After
a successful compilation you should find the Java-Archive sqlite.jar
in the current javasqlite-20020724
directory and there a new directory “.libs”
with sqlite-jni shared object libraries, like libsqlite_jni.so.
Step 8: Install
the JDBC-Driver on the iPAQ
Now copy the
following files from your PC to your
iPAQ:
javasqlite-20020724/sqlite.jar
to
/usr/lib/jdk1.3/lib/ext/sqlite.jar
javasqlite-20020724/.libs/libsqlite_jni.so.0.0.0
to
/usr/lib/jdk1.3/lib/armv4l/libsqlite_jni.so
build/.libs/libsqlite.so*
(all “so”-files)
to
/usr/lib/
Step 9: Test
you JDBC-Driver on your iPAQ
Change into the
/usr/lib/jdk1.3/lib/ext/
directory.
Create a dummy database-file:
touch
test.db
Call the JDBC-SQLite-Console:
java
-jar sqlite.jar test.db
If you see something like
this:
SQLITE>
You're
done ! :-)