blob: 23241e27a6ee4fa79e1c92f31c575f5c7a40b988 [file] [log] [blame]
drh91c58e22007-03-27 12:04:04 +00001#!/usr/bin/tclsh
2#
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
6#
7# make target_source
8#
drh98495b42007-03-31 22:29:05 +00009# 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".
drh91c58e22007-03-27 12:04:04 +000016#
drh98495b42007-03-31 22:29:05 +000017# After the "tsrc" directory has been created and populated, run
18# this script:
drh91c58e22007-03-27 12:04:04 +000019#
drh84ab9532015-05-04 17:06:39 +000020# tclsh mksqlite3c.tcl --srcdir $SRC
drh91c58e22007-03-27 12:04:04 +000021#
drh98495b42007-03-31 22:29:05 +000022# The amalgamated SQLite code will be written into sqlite3.c
23#
24
drh8de5a172009-07-20 12:25:44 +000025# Begin by reading the "sqlite3.h" header file. Extract the version number
drh339d6c62013-03-19 16:12:40 +000026# from in this file. The version number is needed to generate the header
drh8de5a172009-07-20 12:25:44 +000027# comment of the amalgamation.
drh98495b42007-03-31 22:29:05 +000028#
drh84ab9532015-05-04 17:06:39 +000029set addstatic 1
30set linemacros 0
drh84ab9532015-05-04 17:06:39 +000031for {set i 0} {$i<[llength $argv]} {incr i} {
32 set x [lindex $argv $i]
33 if {[regexp {^-+nostatic$} $x]} {
34 set addstatic 0
35 } elseif {[regexp {^-+linemacros} $x]} {
36 set linemacros 1
drh84ab9532015-05-04 17:06:39 +000037 } else {
38 error "unknown command-line option: $x"
39 }
drh96e50882011-08-15 15:27:20 +000040}
drh98495b42007-03-31 22:29:05 +000041set in [open tsrc/sqlite3.h]
42set cnt 0
43set VERSION ?????
44while {![eof $in]} {
45 set line [gets $in]
46 if {$line=="" && [eof $in]} break
47 incr cnt
48 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
49}
50close $in
drh91c58e22007-03-27 12:04:04 +000051
52# Open the output file and write a header comment at the beginning
53# of the file.
54#
55set out [open sqlite3.c w]
shaneh5e0fb2c2011-06-17 15:54:59 +000056# Force the output to use unix line endings, even on Windows.
drhced174b2011-06-20 15:24:22 +000057fconfigure $out -translation lf
drh98495b42007-03-31 22:29:05 +000058set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
59puts $out [subst \
60{/******************************************************************************
drh19df3352007-04-01 01:57:41 +000061** This file is an amalgamation of many separate C source files from SQLite
drh98495b42007-03-31 22:29:05 +000062** version $VERSION. By combining all the individual C code files into this
drh1d210212011-04-01 18:12:58 +000063** single large file, the entire code can be compiled as a single translation
drh98495b42007-03-31 22:29:05 +000064** unit. This allows many compilers to do optimizations that would not be
65** possible if the files were compiled separately. Performance improvements
drh0ee68622010-10-31 22:42:27 +000066** of 5% or more are commonly seen when SQLite is compiled as a single
drh98495b42007-03-31 22:29:05 +000067** translation unit.
68**
69** This file is all you need to compile SQLite. To use SQLite in other
70** programs, you need this file and the "sqlite3.h" header file that defines
71** the programming interface to the SQLite library. (If you do not have
drh8de5a172009-07-20 12:25:44 +000072** the "sqlite3.h" header file at hand, you will find a copy embedded within
73** the text of this file. Search for "Begin file sqlite3.h" to find the start
74** of the embedded sqlite3.h header file.) Additional code files may be needed
75** if you want a wrapper to interface SQLite with your choice of programming
76** language. The code for the "sqlite3" command-line shell is also in a
77** separate file. This file contains only code for the core SQLite library.
drhbd08af42007-04-05 21:58:33 +000078*/
danielk19777c9aaa72008-01-01 05:49:07 +000079#define SQLITE_CORE 1
drhbd08af42007-04-05 21:58:33 +000080#define SQLITE_AMALGAMATION 1}]
drhb6a9ece2007-06-26 00:37:27 +000081if {$addstatic} {
82 puts $out \
83{#ifndef SQLITE_PRIVATE
84# define SQLITE_PRIVATE static
85#endif}
86}
drh91c58e22007-03-27 12:04:04 +000087
88# These are the header files used by SQLite. The first time any of these
89# files are seen in a #include statement in the C code, include the complete
90# text of the file in-line. The file only needs to be included once.
91#
92foreach hdr {
93 btree.h
drha3152892007-05-05 11:48:52 +000094 btreeInt.h
drh820a9062008-01-31 13:35:48 +000095 fts3.h
drhf7829ad2009-11-25 22:42:22 +000096 fts3Int.h
drh820a9062008-01-31 13:35:48 +000097 fts3_hash.h
98 fts3_tokenizer.h
drh91c58e22007-03-27 12:04:04 +000099 hash.h
shane9bcbdad2008-05-29 20:22:37 +0000100 hwtime.h
drh91c58e22007-03-27 12:04:04 +0000101 keywordhash.h
mistachkin2318d332015-01-12 18:02:52 +0000102 msvc.h
drh428e2822007-08-30 16:23:19 +0000103 mutex.h
drh91c58e22007-03-27 12:04:04 +0000104 opcodes.h
105 os_common.h
mistachkinf74b9e02013-11-26 01:00:31 +0000106 os_setup.h
mistachkin8bc52622013-11-25 09:36:07 +0000107 os_win.h
drh91c58e22007-03-27 12:04:04 +0000108 os.h
drh91c58e22007-03-27 12:04:04 +0000109 pager.h
110 parse.h
danielk19778c0a7912008-08-20 14:49:23 +0000111 pcache.h
drh67e65e52015-02-02 21:34:54 +0000112 pragma.h
drh58f1c8b2008-05-26 20:19:25 +0000113 rtree.h
drh91c58e22007-03-27 12:04:04 +0000114 sqlite3.h
dancd732442015-02-10 20:00:38 +0000115 sqlite3ext.h
drhcfb8f8d2015-07-23 20:44:49 +0000116 sqlite3rbu.h
danielk19771c826652008-09-08 08:08:09 +0000117 sqliteicu.h
drh91c58e22007-03-27 12:04:04 +0000118 sqliteInt.h
drhc551dd82007-06-19 15:23:48 +0000119 sqliteLimit.h
drh91c58e22007-03-27 12:04:04 +0000120 vdbe.h
121 vdbeInt.h
drh8cd5b252015-03-02 22:06:43 +0000122 vxworks.h
drhc438efd2010-04-26 00:19:45 +0000123 wal.h
drhe54df422013-11-12 18:37:25 +0000124 whereInt.h
drh91c58e22007-03-27 12:04:04 +0000125} {
126 set available_hdr($hdr) 1
127}
drh71674ce2007-10-23 15:51:26 +0000128set available_hdr(sqliteInt.h) 0
drh91c58e22007-03-27 12:04:04 +0000129
mistachkin59b9b022015-03-24 21:27:27 +0000130# These headers should be copied into the amalgamation without modifying any
131# of their function declarations or definitions.
132set varonly_hdr(sqlite3.h) 1
133
134# These are the functions that accept a variable number of arguments. They
135# always need to use the "cdecl" calling convention even when another calling
136# convention (e.g. "stcall") is being used for the rest of the library.
137set cdecllist {
138 sqlite3_config
139 sqlite3_db_config
140 sqlite3_log
141 sqlite3_mprintf
142 sqlite3_snprintf
143 sqlite3_test_control
144 sqlite3_vtab_config
145}
146
drh91c58e22007-03-27 12:04:04 +0000147# 78 stars used for comment formatting.
148set s78 \
149{*****************************************************************************}
150
151# Insert a comment into the code
152#
153proc section_comment {text} {
154 global out s78
155 set n [string length $text]
156 set nstar [expr {60 - $n}]
157 set stars [string range $s78 0 $nstar]
158 puts $out "/************** $text $stars/"
159}
160
161# Read the source file named $filename and write it into the
162# sqlite3.c output file. If any #include statements are seen,
mistachkin2a43c282013-08-31 05:46:42 +0000163# process them appropriately.
drh91c58e22007-03-27 12:04:04 +0000164#
165proc copy_file {filename} {
mistachkin59b9b022015-03-24 21:27:27 +0000166 global seen_hdr available_hdr varonly_hdr cdecllist out addstatic linemacros
drh96e50882011-08-15 15:27:20 +0000167 set ln 0
drh91c58e22007-03-27 12:04:04 +0000168 set tail [file tail $filename]
169 section_comment "Begin file $tail"
drh96e50882011-08-15 15:27:20 +0000170 if {$linemacros} {puts $out "#line 1 \"$filename\""}
drh91c58e22007-03-27 12:04:04 +0000171 set in [open $filename r]
drh73be5012007-08-08 12:11:21 +0000172 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)}
mistachkin59b9b022015-03-24 21:27:27 +0000173 set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)}
drhee858132007-05-08 20:37:38 +0000174 if {[file extension $filename]==".h"} {
drhf7083bf2007-08-08 01:04:52 +0000175 set declpattern " *$declpattern"
drhee858132007-05-08 20:37:38 +0000176 }
mistachkin59b9b022015-03-24 21:27:27 +0000177 set declpattern ^$declpattern\$
drh91c58e22007-03-27 12:04:04 +0000178 while {![eof $in]} {
179 set line [gets $in]
drh96e50882011-08-15 15:27:20 +0000180 incr ln
drh9965a042008-10-14 18:21:11 +0000181 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
drh91c58e22007-03-27 12:04:04 +0000182 if {[info exists available_hdr($hdr)]} {
183 if {$available_hdr($hdr)} {
shane9bcbdad2008-05-29 20:22:37 +0000184 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
drh91c58e22007-03-27 12:04:04 +0000185 set available_hdr($hdr) 0
186 }
187 section_comment "Include $hdr in the middle of $tail"
188 copy_file tsrc/$hdr
189 section_comment "Continuing where we left off in $tail"
drh96e50882011-08-15 15:27:20 +0000190 if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
mistachkin3a2a6862015-07-15 21:00:33 +0000191 } else {
192 # Comment out the entire line, replacing any nested comment
193 # begin/end markers with the harmless substring "**".
194 puts $out "/* [string map [list /* ** */ **] $line] */"
drh91c58e22007-03-27 12:04:04 +0000195 }
196 } elseif {![info exists seen_hdr($hdr)]} {
drh1a8a0d32014-05-05 20:21:52 +0000197 if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} {
198 set seen_hdr($hdr) 1
199 }
drh91c58e22007-03-27 12:04:04 +0000200 puts $out $line
mistachkin1a88b142013-08-31 18:06:52 +0000201 } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} {
202 # This include file must be kept because there was a "keep"
203 # directive inside of a line comment.
204 puts $out $line
drh96e50882011-08-15 15:27:20 +0000205 } else {
mistachkin1a88b142013-08-31 18:06:52 +0000206 # Comment out the entire line, replacing any nested comment
207 # begin/end markers with the harmless substring "**".
208 puts $out "/* [string map [list /* ** */ **] $line] */"
drh91c58e22007-03-27 12:04:04 +0000209 }
210 } elseif {[regexp {^#ifdef __cplusplus} $line]} {
211 puts $out "#if 0"
drh96e50882011-08-15 15:27:20 +0000212 } elseif {!$linemacros && [regexp {^#line} $line]} {
drh91c58e22007-03-27 12:04:04 +0000213 # Skip #line directives.
drh45fac882015-10-09 01:42:49 +0000214 } elseif {$addstatic
215 && ![regexp {^(static|typedef|SQLITE_PRIVATE)} $line]} {
mistachkin59b9b022015-03-24 21:27:27 +0000216 # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before
217 # functions if this header file does not need it.
218 if {![info exists varonly_hdr($tail)]
219 && [regexp $declpattern $line all rettype funcname rest]} {
220 regsub {^SQLITE_API } $line {} line
drh0a0e1312007-08-07 17:04:59 +0000221 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions.
222 # so that linkage can be modified at compile-time.
drhcfb8f8d2015-07-23 20:44:49 +0000223 if {[regexp {^sqlite3(_|rbu_)} $funcname]} {
mistachkin59b9b022015-03-24 21:27:27 +0000224 set line SQLITE_API
225 append line " " [string trim $rettype]
226 if {[string index $rettype end] ne "*"} {
227 append line " "
228 }
229 if {[lsearch -exact $cdecllist $funcname] >= 0} {
230 append line SQLITE_CDECL
231 } else {
232 append line SQLITE_STDCALL
233 }
234 append line " " $funcname $rest
235 puts $out $line
drh0a0e1312007-08-07 17:04:59 +0000236 } else {
237 puts $out "SQLITE_PRIVATE $line"
238 }
239 } elseif {[regexp $varpattern $line all varname]} {
mistachkin59b9b022015-03-24 21:27:27 +0000240 # Add the SQLITE_PRIVATE before variable declarations or
241 # definitions for internal use
242 regsub {^SQLITE_API } $line {} line
243 if {![regexp {^sqlite3_} $varname]} {
244 regsub {^extern } $line {} line
245 puts $out "SQLITE_PRIVATE $line"
246 } else {
247 if {[regexp {const char sqlite3_version\[\];} $line]} {
248 set line {const char sqlite3_version[] = SQLITE_VERSION;}
249 }
250 regsub {^SQLITE_EXTERN } $line {} line
251 puts $out "SQLITE_API $line"
drhb3190c12008-12-08 21:37:14 +0000252 }
mlcreech3a00f902008-03-04 17:45:01 +0000253 } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
mistachkin59b9b022015-03-24 21:27:27 +0000254 regsub {^SQLITE_API } $line {} line
mlcreech3a00f902008-03-04 17:45:01 +0000255 regsub {^SQLITE_EXTERN } $line {} line
dan80389532014-12-24 17:17:30 +0000256 puts $out $line
drhf1581622009-02-03 13:51:17 +0000257 } elseif {[regexp {^void \(\*sqlite3Os} $line]} {
mistachkin59b9b022015-03-24 21:27:27 +0000258 regsub {^SQLITE_API } $line {} line
drhf1581622009-02-03 13:51:17 +0000259 puts $out "SQLITE_PRIVATE $line"
drh26b0fc02007-06-26 00:52:39 +0000260 } else {
drh0a0e1312007-08-07 17:04:59 +0000261 puts $out $line
drh26b0fc02007-06-26 00:52:39 +0000262 }
drh91c58e22007-03-27 12:04:04 +0000263 } else {
264 puts $out $line
265 }
266 }
267 close $in
268 section_comment "End of $tail"
269}
270
271
272# Process the source files. Process files containing commonly
273# used subroutines first in order to help the compiler find
274# inlining opportunities.
275#
276foreach file {
drh71674ce2007-10-23 15:51:26 +0000277 sqliteInt.h
drh98495b42007-03-31 22:29:05 +0000278
drh40257ff2008-06-13 18:24:27 +0000279 global.c
drh735b9cb2010-03-10 23:13:53 +0000280 ctime.c
drhf7141992008-06-19 00:16:08 +0000281 status.c
drha55ca9e2007-04-02 12:22:44 +0000282 date.c
drh970f7242007-03-31 16:29:06 +0000283 os.c
284
drh643167f2008-01-22 21:30:53 +0000285 fault.c
drhd1370b62008-10-28 18:58:20 +0000286 mem0.c
drh97c8ec32007-08-27 21:49:34 +0000287 mem1.c
288 mem2.c
danielk19776b39c2e2008-06-25 14:57:53 +0000289 mem3.c
290 mem5.c
drh97c8ec32007-08-27 21:49:34 +0000291 mutex.c
drh18472fa2008-10-07 15:25:48 +0000292 mutex_noop.c
drh61f6dc62007-08-30 17:15:37 +0000293 mutex_unix.c
294 mutex_w32.c
drha3152892007-05-05 11:48:52 +0000295 malloc.c
drh91c58e22007-03-27 12:04:04 +0000296 printf.c
drh38b41492015-06-08 15:08:15 +0000297 treeview.c
drh91c58e22007-03-27 12:04:04 +0000298 random.c
drhf51446a2012-07-21 19:40:42 +0000299 threads.c
drh91c58e22007-03-27 12:04:04 +0000300 utf.c
301 util.c
302 hash.c
303 opcodes.c
304
drh91c58e22007-03-27 12:04:04 +0000305 os_unix.c
306 os_win.c
307
drhf5e7bb52008-02-18 14:47:33 +0000308 bitvec.c
danielk19778c0a7912008-08-20 14:49:23 +0000309 pcache.c
danielk1977d17e71c2008-11-13 14:42:18 +0000310 pcache1.c
drh3d4501e2008-12-04 20:40:10 +0000311 rowset.c
drh91c58e22007-03-27 12:04:04 +0000312 pager.c
shanehfd068632010-05-06 19:20:29 +0000313 wal.c
drh61f6dc62007-08-30 17:15:37 +0000314
shane9bcbdad2008-05-29 20:22:37 +0000315 btmutex.c
drh91c58e22007-03-27 12:04:04 +0000316 btree.c
danielk197704103022009-02-03 16:51:24 +0000317 backup.c
drh91c58e22007-03-27 12:04:04 +0000318
drh91c58e22007-03-27 12:04:04 +0000319 vdbemem.c
320 vdbeaux.c
321 vdbeapi.c
drhc7bc4fd2009-11-25 18:03:42 +0000322 vdbetrace.c
drh91c58e22007-03-27 12:04:04 +0000323 vdbe.c
drh3f755842007-05-03 16:55:32 +0000324 vdbeblob.c
dan7fe62702011-08-02 10:56:22 +0000325 vdbesort.c
drh97c8ec32007-08-27 21:49:34 +0000326 journal.c
danielk1977b3175382008-10-17 18:51:52 +0000327 memjournal.c
drh91c58e22007-03-27 12:04:04 +0000328
drh7d10d5a2008-08-20 16:35:10 +0000329 walker.c
330 resolve.c
drh91c58e22007-03-27 12:04:04 +0000331 expr.c
332 alter.c
333 analyze.c
334 attach.c
335 auth.c
336 build.c
337 callback.c
drh91c58e22007-03-27 12:04:04 +0000338 delete.c
drh70a8ca32008-08-21 18:49:27 +0000339 func.c
dan3be7d6e2009-09-19 17:59:59 +0000340 fkey.c
drh91c58e22007-03-27 12:04:04 +0000341 insert.c
342 legacy.c
343 loadext.c
344 pragma.c
345 prepare.c
346 select.c
347 table.c
348 trigger.c
349 update.c
350 vacuum.c
351 vtab.c
drh6f82e852015-06-06 20:12:09 +0000352 wherecode.c
drh6c1f4ef2015-06-08 14:23:15 +0000353 whereexpr.c
drh91c58e22007-03-27 12:04:04 +0000354 where.c
355
356 parse.c
357
358 tokenize.c
drh46c99e02007-08-27 23:26:59 +0000359 complete.c
drh91c58e22007-03-27 12:04:04 +0000360
361 main.c
danielk1977404ca072009-03-16 13:19:36 +0000362 notify.c
drh820a9062008-01-31 13:35:48 +0000363
364 fts3.c
dan290c9392011-02-01 18:59:34 +0000365 fts3_aux.c
drhaeba0202008-12-31 16:01:04 +0000366 fts3_expr.c
drh820a9062008-01-31 13:35:48 +0000367 fts3_hash.c
368 fts3_porter.c
369 fts3_tokenizer.c
370 fts3_tokenizer1.c
dand7a959c2013-04-22 15:30:37 +0000371 fts3_tokenize_vtab.c
dan16708c42009-11-19 15:25:25 +0000372 fts3_write.c
373 fts3_snippet.c
dan3d403c72012-05-25 17:50:19 +0000374 fts3_unicode.c
375 fts3_unicode2.c
drh58f1c8b2008-05-26 20:19:25 +0000376
377 rtree.c
danielk19770c8a5d02008-08-04 11:49:20 +0000378 icu.c
danielk1977f9449d02008-09-24 09:58:00 +0000379 fts3_icu.c
drhcfb8f8d2015-07-23 20:44:49 +0000380 sqlite3rbu.c
drh1a4a6802015-05-04 18:31:09 +0000381 dbstat.c
drh50065652015-10-08 19:29:18 +0000382 json1.c
383 fts5.c
drh91c58e22007-03-27 12:04:04 +0000384} {
385 copy_file tsrc/$file
386}
387
drh91c58e22007-03-27 12:04:04 +0000388close $out