Most open source projects provide a single download that
allows you to configure, build, and install the software with just a handful
of commands. SQLite works a bit differently. Because the most common way to
use SQLite is to integrate the core source directly into a host application,
the source distributions are designed to make integration as simple as
possible. Most of the source distributions contain only source code and
provide minimal (if any) configuration or build support files. This makes it
simpler to integrate SQLite into a host application, but if you want to
build a library or sqlite3 application,
you will often need to do that by hand. As we’ll see, that’s fairly
easy.
The official code distribution is known as the amalgamation. The amalgamation is a single C source file that contains the entire SQLite core. It is created by assembling the individual development files into a single C source file that is almost 4 megabytes in size and over 100,000 lines long. The amalgamation, along with its corresponding header file, is all that is needed to integrate SQLite into your application.
The amalgamation has two main advantages. First, with everything in one file, it is extremely easy to integrate SQLite into a host application. Many projects simply copy the amalgamation files into their own source directories. It is also possible to compile the SQLite core into a library and simply link the library into your application.
Second, the amalgamation also helps improve performance. Many compiler optimizations are limited to a single translation unit. In C, that’s a single source file. By putting the whole library into a single file, a good optimizer can process the whole package at once. Compared to compiling the individual source files, some platforms see a 5% or better performance boost just by using the amalgamation.
The only disadvantage of using the amalgamation is size. Some debuggers have issues with files more than 65,535 lines long. Things typically run correctly, but it can be difficult to set breakpoints or look at stack traces. Compiling a source file over 100,000 lines long also takes a fair number of resources. While this is no problem for most desktop systems, it may push the limits of any compilers running on limited platforms.
When working with the amalgamation, there are four important source files:
The first two, sqlite3.c and sqlite3.h, are all that is needed to integrate
SQLite into most applications. The sqlite3ext.h file is used to build extensions and
modules. Building extensions is covered in SQLite Extensions. The shell.c file contains the source code for the
sqlite3 command-line shell.
All of these files can be built on Linux, Mac OS X, or Windows,
without any additional configuration files.
The SQLite website offers five source distribution packages. Most people will be interested in one of the first two files.
The Windows amalgamation file consists of the four main files, plus a .def file to build a DLL. No makefile, project, or solution files are included.
The Unix amalgamation file, which works on Linux,
Mac OS X, and many other flavors of Unix, contains the four main files
plus an sqlite3 manual page. The
Unix distribution also contains a basic configure script, along with other autoconf files,
scripts, and makefiles. The autoconf files should also work under the
Minimalist GNU for Windows (MinGW) environment (http://www.mingw.org/).
The Tcl extension distribution is a specialized version of the amalgamation. It is only of interest to those working in the Tcl language. See the included documentation for more details.
The Unix source tree is an unsupported legacy distribution. This is what the standard distribution looked like before the amalgamation became the officially supported distribution. It is made available for those that have older build environments or development branches that utilize the old distribution format. This distribution also includes a number of README files that are unavailable elsewhere.
Although the source files are kept up to date, the configuration scripts and makefiles included in the Unix source tree distribution are no longer maintained and do not work properly on most platforms. Unless you have some significant need to use the source tree distribution, you should use one of the amalgamation distributions instead.
The Windows source distribution is essentially a .zip file of the source directory from the source tree distribution, minus some test files. It is strictly source files and header files, and contains no build scripts, makefiles, or project files.