3 # To build a single huge source file holding all of SQLite (or at
4 # least the core components - the test harness, shell, and TCL
5 # interface are omitted.) first do
9 # The make target above moves all of the source code files into
10 # a subdirectory named "tsrc". (This script expects to find the files
11 # there and will not work if they are not found.) There are a few
12 # generated C code files that are also added to the tsrc directory.
13 # For example, the "parse.c" and "parse.h" files to implement the
14 # the parser are derived from "parse.y" using lemon. And the
15 # "keywordhash.h" files is generated by a program named "mkkeywordhash".
17 # After the "tsrc" directory has been created and populated, run
20 # tclsh mksqlite3c.tcl
22 # The amalgamated SQLite code will be written into sqlite3.c
25 # Begin by reading the "sqlite3.h" header file. Count the number of lines
26 # in this file and extract the version number. That information will be
27 # needed in order to generate the header of the amalgamation.
29 set in
[open tsrc
/sqlite3.h
]
34 if {$line=="" && [eof $in]} break
36 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
40 # Open the output file and write a header comment at the beginning
43 set out
[open sqlite3internal.h w
]
44 set today
[clock format [clock seconds
] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
46 {/******************************************************************************
47 ** This
file is an amalgamation of many private header files from SQLite
51 # These are the header files used by SQLite. The first time any of these
52 # files are seen in a #include statement in the C code, include the complete
53 # text of the file in-line. The file only needs to be included once.
73 set available_hdr
($hdr) 1
76 # 78 stars used for comment formatting.
78 {*****************************************************************************}
80 # Insert a comment into the code
82 proc section_comment
{text} {
84 set n
[string length
$text]
85 set nstar
[expr {60 - $n}]
86 set stars
[string range
$s78 0 $nstar]
87 puts $out "/************** $text $stars/"
90 # Read the source file named $filename and write it into the
91 # sqlite3.c output file. If any #include statements are seen,
92 # process them approprately.
94 proc copy_file
{filename} {
95 global seen_hdr available_hdr out
96 set tail
[file tail
$filename]
97 section_comment
"Begin file $tail"
98 set in
[open $filename r
]
101 if {[regexp {^
#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
102 if {[info exists available_hdr
($hdr)]} {
103 if {$available_hdr($hdr)} {
104 section_comment
"Include $hdr in the middle of $tail"
106 section_comment
"Continuing where we left off in $tail"
108 } elseif
{![info exists seen_hdr
($hdr)]} {
112 } elseif
{[regexp {^
#ifdef __cplusplus} $line]} {
114 } elseif
{[regexp {^
#line} $line]} {
115 # Skip #line directives.
121 section_comment
"End of $tail"
125 # Process the source files. Process files containing commonly
126 # used subroutines first in order to help the compiler find
127 # inlining opportunities.
140 if {$available_hdr($file)} {