Index: main.mk ================================================================== --- main.mk +++ main.mk @@ -247,12 +247,15 @@ # all that automatic generation. # target_source: $(SRC) rm -rf tsrc mkdir tsrc - cp $(SRC) $(TOP)/src/*.h tsrc + cp -f $(SRC) $(TOP)/src/*.h tsrc 2>/dev/null rm tsrc/sqlite.h.in tsrc/parse.y + +sqlite3.c: target_source $(TOP)/tool/mksqlite3c.tcl + tclsh $(TOP)/tool/mksqlite3c.tcl # Rules to build the LEMON compiler generator # lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c $(BCC) -o lemon $(TOP)/tool/lemon.c Index: tool/mksqlite3c.tcl ================================================================== --- tool/mksqlite3c.tcl +++ tool/mksqlite3c.tcl @@ -4,28 +4,68 @@ # least the core components - the test harness, shell, and TCL # interface are omitted.) first do # # make target_source # -# Then run this script +# The make target above moves all of the source code files into +# a subdirectory named "tsrc". (This script expects to find the files +# there and will not work if they are not found.) There are a few +# generated C code files that are also added to the tsrc directory. +# For example, the "parse.c" and "parse.h" files to implement the +# the parser are derived from "parse.y" using lemon. And the +# "keywordhash.h" files is generated by a program named "mkkeywordhash". +# +# After the "tsrc" directory has been created and populated, run +# this script: +# +# tclsh mksqlite3c.tcl +# +# The amalgamated SQLite code will be written into sqlite3.c # -# tclsh mkonebigsourcefile.tcl + +# Begin by reading the "sqlite3.h" header file. Count the number of lines +# in this file and extract the version number. That information will be +# needed in order to generate the header of the amalgamation. # -# The combined SQLite source code will be written into sqlite3.c -# +set in [open tsrc/sqlite3.h] +set cnt 0 +set VERSION ????? +while {![eof $in]} { + set line [gets $in] + if {$line=="" && [eof $in]} break + incr cnt + regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION +} +close $in # Open the output file and write a header comment at the beginning # of the file. # set out [open sqlite3.c w] -puts $out \ -"/****************************************************************************** -** This file is a amalgamation of many separate source files from SQLite. By -** pulling all the source files into this single unified source file, the -** entire code can be compiled as a single translation unit, which allows the -** compiler to do a better job of optimizing. -*/" +set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1] +puts $out [subst \ +{/****************************************************************************** +** This file is a amalgamation of many separate C source files from SQLite +** version $VERSION. By combining all the individual C code files into this +** single large file, the entire code can be compiled as a one translation +** unit. This allows many compilers to do optimizations that would not be +** possible if the files were compiled separately. Performance improvements +** of 5% are more are commonly seen when SQLite is compiled as a single +** translation unit. +** +** This file is all you need to compile SQLite. To use SQLite in other +** programs, you need this file and the "sqlite3.h" header file that defines +** the programming interface to the SQLite library. (If you do not have +** the "sqlite3.h" header file at hand, you will find a copy in the first +** $cnt lines past the header of this amalgamation.) Additional code +** files may be needed if you want a wrapper to interface SQLite with your +** choice of programming language. The code for the "sqlite3" command-line +** shell is also in a separate file. This file contains only code for the +** core SQLite library. +** +** This amalgamation was generated on $today. +*/}] # These are the header files used by SQLite. The first time any of these # files are seen in a #include statement in the C code, include the complete # text of the file in-line. The file only needs to be included once. # @@ -45,10 +85,11 @@ vdbe.h vdbeInt.h } { set available_hdr($hdr) 1 } +set available_hdr(sqlite3.h) 0 # 78 stars used for comment formatting. set s78 \ {*****************************************************************************} @@ -103,10 +144,12 @@ # Process the source files. Process files containing commonly # used subroutines first in order to help the compiler find # inlining opportunities. # foreach file { + sqlite3.h + os.c printf.c random.c utf.c