1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
#!/usr/bin/tclsh
#
# To build a single huge source file holding all of SQLite (or at
# least the core components - the test harness, shell, and TCL
# interface are omitted.) first do
#
# make target_source
#
# 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 --srcdir $SRC
#
# The amalgamated SQLite code will be written into sqlite3.c
#
# Begin by reading the "sqlite3.h" header file. Extract the version number
# from in this file. The version number is needed to generate the header
# comment of the amalgamation.
#
set addstatic 1
set linemacros 0
for {set i 0} {$i<[llength $argv]} {incr i} {
set x [lindex $argv $i]
if {[regexp {^-+nostatic$} $x]} {
set addstatic 0
} elseif {[regexp {^-+linemacros} $x]} {
set linemacros 1
} else {
error "unknown command-line option: $x"
}
}
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]
# Force the output to use unix line endings, even on Windows.
fconfigure $out -translation lf
set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
puts $out [subst \
{/******************************************************************************
** This file is an 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 single translation
** unit. This allows many compilers to do optimizations that would not be
** possible if the files were compiled separately. Performance improvements
** of 5% or 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 embedded within
** the text of this file. Search for "Begin file sqlite3.h" to find the start
** of the embedded sqlite3.h header file.) 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.
*/
#define SQLITE_CORE 1
#define SQLITE_AMALGAMATION 1}]
if {$addstatic} {
puts $out \
{#ifndef SQLITE_PRIVATE
# define SQLITE_PRIVATE static
#endif}
}
# 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.
#
foreach hdr {
btree.h
btreeInt.h
fts3.h
fts3Int.h
fts3_hash.h
fts3_tokenizer.h
hash.h
hwtime.h
keywordhash.h
msvc.h
mutex.h
opcodes.h
os_common.h
os_setup.h
os_win.h
os.h
pager.h
parse.h
pcache.h
pragma.h
rtree.h
sqlite3.h
sqlite3ext.h
sqlite3rbu.h
sqliteicu.h
sqliteInt.h
sqliteLimit.h
vdbe.h
vdbeInt.h
vxworks.h
wal.h
whereInt.h
} {
set available_hdr($hdr) 1
}
set available_hdr(sqliteInt.h) 0
# These headers should be copied into the amalgamation without modifying any
# of their function declarations or definitions.
set varonly_hdr(sqlite3.h) 1
# These are the functions that accept a variable number of arguments. They
# always need to use the "cdecl" calling convention even when another calling
# convention (e.g. "stcall") is being used for the rest of the library.
set cdecllist {
sqlite3_config
sqlite3_db_config
sqlite3_log
sqlite3_mprintf
sqlite3_snprintf
sqlite3_test_control
sqlite3_vtab_config
}
# 78 stars used for comment formatting.
set s78 \
{*****************************************************************************}
# Insert a comment into the code
#
proc section_comment {text} {
global out s78
set n [string length $text]
set nstar [expr {60 - $n}]
set stars [string range $s78 0 $nstar]
puts $out "/************** $text $stars/"
}
# Read the source file named $filename and write it into the
# sqlite3.c output file. If any #include statements are seen,
# process them appropriately.
#
proc copy_file {filename} {
global seen_hdr available_hdr varonly_hdr cdecllist out addstatic linemacros
set ln 0
set tail [file tail $filename]
section_comment "Begin file $tail"
if {$linemacros} {puts $out "#line 1 \"$filename\""}
set in [open $filename r]
set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)}
set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)}
if {[file extension $filename]==".h"} {
set declpattern " *$declpattern"
}
set declpattern ^$declpattern\$
while {![eof $in]} {
set line [gets $in]
incr ln
if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
if {[info exists available_hdr($hdr)]} {
if {$available_hdr($hdr)} {
if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
set available_hdr($hdr) 0
}
section_comment "Include $hdr in the middle of $tail"
copy_file tsrc/$hdr
section_comment "Continuing where we left off in $tail"
if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
} else {
# Comment out the entire line, replacing any nested comment
# begin/end markers with the harmless substring "**".
puts $out "/* [string map [list /* ** */ **] $line] */"
}
} elseif {![info exists seen_hdr($hdr)]} {
if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} {
set seen_hdr($hdr) 1
}
puts $out $line
} elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} {
# This include file must be kept because there was a "keep"
# directive inside of a line comment.
puts $out $line
} else {
# Comment out the entire line, replacing any nested comment
# begin/end markers with the harmless substring "**".
puts $out "/* [string map [list /* ** */ **] $line] */"
}
} elseif {[regexp {^#ifdef __cplusplus} $line]} {
puts $out "#if 0"
} elseif {!$linemacros && [regexp {^#line} $line]} {
# Skip #line directives.
} elseif {$addstatic && ![regexp {^(static|typedef)} $line]} {
# Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before
# functions if this header file does not need it.
if {![info exists varonly_hdr($tail)]
&& [regexp $declpattern $line all rettype funcname rest]} {
regsub {^SQLITE_API } $line {} line
# Add the SQLITE_PRIVATE or SQLITE_API keyword before functions.
# so that linkage can be modified at compile-time.
if {[regexp {^sqlite3(_|rbu_)} $funcname]} {
set line SQLITE_API
append line " " [string trim $rettype]
if {[string index $rettype end] ne "*"} {
append line " "
}
if {[lsearch -exact $cdecllist $funcname] >= 0} {
append line SQLITE_CDECL
} else {
append line SQLITE_STDCALL
}
append line " " $funcname $rest
puts $out $line
} else {
puts $out "SQLITE_PRIVATE $line"
}
} elseif {[regexp $varpattern $line all varname]} {
# Add the SQLITE_PRIVATE before variable declarations or
# definitions for internal use
regsub {^SQLITE_API } $line {} line
if {![regexp {^sqlite3_} $varname]} {
regsub {^extern } $line {} line
puts $out "SQLITE_PRIVATE $line"
} else {
if {[regexp {const char sqlite3_version\[\];} $line]} {
set line {const char sqlite3_version[] = SQLITE_VERSION;}
}
regsub {^SQLITE_EXTERN } $line {} line
puts $out "SQLITE_API $line"
}
} elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
regsub {^SQLITE_API } $line {} line
regsub {^SQLITE_EXTERN } $line {} line
puts $out $line
} elseif {[regexp {^void \(\*sqlite3Os} $line]} {
regsub {^SQLITE_API } $line {} line
puts $out "SQLITE_PRIVATE $line"
} else {
puts $out $line
}
} else {
puts $out $line
}
}
close $in
section_comment "End of $tail"
}
# Process the source files. Process files containing commonly
# used subroutines first in order to help the compiler find
# inlining opportunities.
#
foreach file {
sqliteInt.h
global.c
ctime.c
status.c
date.c
os.c
fault.c
mem0.c
mem1.c
mem2.c
mem3.c
mem5.c
mutex.c
mutex_noop.c
mutex_unix.c
mutex_w32.c
malloc.c
printf.c
treeview.c
random.c
threads.c
utf.c
util.c
hash.c
opcodes.c
os_unix.c
os_win.c
bitvec.c
pcache.c
pcache1.c
rowset.c
pager.c
wal.c
btmutex.c
btree.c
backup.c
vdbemem.c
vdbeaux.c
vdbeapi.c
vdbetrace.c
vdbe.c
vdbeblob.c
vdbesort.c
journal.c
memjournal.c
walker.c
resolve.c
expr.c
alter.c
analyze.c
attach.c
auth.c
build.c
callback.c
delete.c
func.c
fkey.c
insert.c
legacy.c
loadext.c
pragma.c
prepare.c
select.c
table.c
trigger.c
update.c
vacuum.c
vtab.c
wherecode.c
whereexpr.c
where.c
parse.c
tokenize.c
complete.c
main.c
notify.c
fts3.c
fts3_aux.c
fts3_expr.c
fts3_hash.c
fts3_porter.c
fts3_tokenizer.c
fts3_tokenizer1.c
fts3_tokenize_vtab.c
fts3_write.c
fts3_snippet.c
fts3_unicode.c
fts3_unicode2.c
rtree.c
icu.c
fts3_icu.c
sqlite3rbu.c
dbstat.c
} {
copy_file tsrc/$file
}
close $out
|