Small. Fast. Reliable.
Choose any three.
This page describes how the source code under configuration management is transformed into a working SQLite library. You do not need to know any of this in order to build SQLite. The makefiles should do everything for you automatically. But many people find a knowledge of what is going on behind the scenes helpful.

SQLite is implemented in ANSI-C. But many of the C code file that are input to the C compiler are generated from other scripts and programs rather than being typed in manually. The following diagram shows the complete build process:

make-lib.gif

In the image above, red ovals are original source files from the configuration management system. Green ovals are C code that is automatically generated. Blue rectangles are build tools and compilers that are needed on the host platform in order to compile SQLite. Yellow rectangles are build tools and compilers for which the source code is part of the SQLite source tree. The final output (the SQLite library) is a purple oval near the bottom of the diagram.

The files contained within the light-blue bubble are the C code files that become part of the SQLite library. You will notice that some files from CVS are within the blue bubble and others are not. Not every code file in the CVS repository ends up being part of the SQLite library. On the download page, the downloads with names of the form sqlite-X.X.X.tar.gz are snapshots of the CVS tree. These are the red ovals. The downloads with names of the form sqlite-source-X_X_X.zip contain just the files inside the light-blue bubble.

These are the generated C code files:

Generating the processed C code can be a little bit tricky. Note the dependency change of parse.h to opcodes.h to opcodes.c. You have to be careful to do things in the right order. Fortunately, the makefiles do this for you automatically.

Note: there is a makefile target that will generate just the processed C code and stop. If you type

   make target_source

Then the makefiles will construct a subdirectory named "tsrc" and put copies of the processed C code into that directory. That is how the sqlite-source-X_X_X.zip downloads are generated. We just run the target_source make target and ZIP up the "tsrc" subdirectory.

After all of the processed C code has been prepared as shown above, the SQLite library is generated simply by passing the processed C code into an ordinary C compiler.

Building The Amalgamation

Beginning with version 3.3.14, SQLite is available in the form of a single huge source file that contains all of the source code for SQLite. We call this single source file "the amalgamation". The diagram below shows how the amalgamation is built:

make-amal.gif

Very little has changed from the previous diagram. The processed C code in the light-blue bubble is the same and all the steps needed to generate that code are the same. The only difference is in what we do with the code.

To generate the amalgamation, there is a Tcl script named mksqlite3c.tcl that reads the processed C code and copies it all into the amalgamation file, "sqlite3.c", in the right order.

Attachments:

  • make-lib.gif 35363 bytes added by drh on 2007-Apr-07 13:34:31 UTC.
    Diagram of SQLite library build process
  • make-amal.gif 37905 bytes added by drh on 2007-Apr-07 13:35:16 UTC.
    Diagram of the process for constructed the source code amalgamation