blob: 2c569d7a4eb494e28977dcc95ea975b13e43af2a [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#
drh98495b42007-03-31 22:29:05 +000020# tclsh mksqlite3c.tcl
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
26# from in this file. The versioon number is needed to generate the header
27# comment of the amalgamation.
drh98495b42007-03-31 22:29:05 +000028#
drhb36d20d2007-05-16 13:55:26 +000029if {[lsearch $argv --nostatic]>=0} {
30 set addstatic 0
31} else {
32 set addstatic 1
33}
drh96e50882011-08-15 15:27:20 +000034if {[lsearch $argv --linemacros]>=0} {
35 set linemacros 1
36} else {
37 set linemacros 0
38}
drh98495b42007-03-31 22:29:05 +000039set in [open tsrc/sqlite3.h]
40set cnt 0
41set VERSION ?????
42while {![eof $in]} {
43 set line [gets $in]
44 if {$line=="" && [eof $in]} break
45 incr cnt
46 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
47}
48close $in
drh91c58e22007-03-27 12:04:04 +000049
50# Open the output file and write a header comment at the beginning
51# of the file.
52#
53set out [open sqlite3.c w]
shaneh5e0fb2c2011-06-17 15:54:59 +000054# Force the output to use unix line endings, even on Windows.
drhced174b2011-06-20 15:24:22 +000055fconfigure $out -translation lf
drh98495b42007-03-31 22:29:05 +000056set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
57puts $out [subst \
58{/******************************************************************************
drh19df3352007-04-01 01:57:41 +000059** This file is an amalgamation of many separate C source files from SQLite
drh98495b42007-03-31 22:29:05 +000060** version $VERSION. By combining all the individual C code files into this
drh1d210212011-04-01 18:12:58 +000061** single large file, the entire code can be compiled as a single translation
drh98495b42007-03-31 22:29:05 +000062** unit. This allows many compilers to do optimizations that would not be
63** possible if the files were compiled separately. Performance improvements
drh0ee68622010-10-31 22:42:27 +000064** of 5% or more are commonly seen when SQLite is compiled as a single
drh98495b42007-03-31 22:29:05 +000065** translation unit.
66**
67** This file is all you need to compile SQLite. To use SQLite in other
68** programs, you need this file and the "sqlite3.h" header file that defines
69** the programming interface to the SQLite library. (If you do not have
drh8de5a172009-07-20 12:25:44 +000070** the "sqlite3.h" header file at hand, you will find a copy embedded within
71** the text of this file. Search for "Begin file sqlite3.h" to find the start
72** of the embedded sqlite3.h header file.) Additional code files may be needed
73** if you want a wrapper to interface SQLite with your choice of programming
74** language. The code for the "sqlite3" command-line shell is also in a
75** separate file. This file contains only code for the core SQLite library.
drhbd08af42007-04-05 21:58:33 +000076*/
danielk19777c9aaa72008-01-01 05:49:07 +000077#define SQLITE_CORE 1
drhbd08af42007-04-05 21:58:33 +000078#define SQLITE_AMALGAMATION 1}]
drhb6a9ece2007-06-26 00:37:27 +000079if {$addstatic} {
80 puts $out \
81{#ifndef SQLITE_PRIVATE
82# define SQLITE_PRIVATE static
drh26b0fc02007-06-26 00:52:39 +000083#endif
84#ifndef SQLITE_API
85# define SQLITE_API
drhb6a9ece2007-06-26 00:37:27 +000086#endif}
87}
drh91c58e22007-03-27 12:04:04 +000088
89# These are the header files used by SQLite. The first time any of these
90# files are seen in a #include statement in the C code, include the complete
91# text of the file in-line. The file only needs to be included once.
92#
93foreach hdr {
94 btree.h
drha3152892007-05-05 11:48:52 +000095 btreeInt.h
drh820a9062008-01-31 13:35:48 +000096 fts3.h
drhf7829ad2009-11-25 22:42:22 +000097 fts3Int.h
drh820a9062008-01-31 13:35:48 +000098 fts3_hash.h
99 fts3_tokenizer.h
drh91c58e22007-03-27 12:04:04 +0000100 hash.h
shane9bcbdad2008-05-29 20:22:37 +0000101 hwtime.h
drh91c58e22007-03-27 12:04:04 +0000102 keywordhash.h
drh428e2822007-08-30 16:23:19 +0000103 mutex.h
drh91c58e22007-03-27 12:04:04 +0000104 opcodes.h
105 os_common.h
106 os.h
drh91c58e22007-03-27 12:04:04 +0000107 pager.h
108 parse.h
danielk19778c0a7912008-08-20 14:49:23 +0000109 pcache.h
drh58f1c8b2008-05-26 20:19:25 +0000110 rtree.h
drh91c58e22007-03-27 12:04:04 +0000111 sqlite3ext.h
112 sqlite3.h
danielk19771c826652008-09-08 08:08:09 +0000113 sqliteicu.h
drh91c58e22007-03-27 12:04:04 +0000114 sqliteInt.h
drhc551dd82007-06-19 15:23:48 +0000115 sqliteLimit.h
drh91c58e22007-03-27 12:04:04 +0000116 vdbe.h
117 vdbeInt.h
drhc438efd2010-04-26 00:19:45 +0000118 wal.h
drh91c58e22007-03-27 12:04:04 +0000119} {
120 set available_hdr($hdr) 1
121}
drh71674ce2007-10-23 15:51:26 +0000122set available_hdr(sqliteInt.h) 0
drh91c58e22007-03-27 12:04:04 +0000123
124# 78 stars used for comment formatting.
125set s78 \
126{*****************************************************************************}
127
128# Insert a comment into the code
129#
130proc section_comment {text} {
131 global out s78
132 set n [string length $text]
133 set nstar [expr {60 - $n}]
134 set stars [string range $s78 0 $nstar]
135 puts $out "/************** $text $stars/"
136}
137
138# Read the source file named $filename and write it into the
139# sqlite3.c output file. If any #include statements are seen,
140# process them approprately.
141#
142proc copy_file {filename} {
drh96e50882011-08-15 15:27:20 +0000143 global seen_hdr available_hdr out addstatic linemacros
144 set ln 0
drh91c58e22007-03-27 12:04:04 +0000145 set tail [file tail $filename]
146 section_comment "Begin file $tail"
drh96e50882011-08-15 15:27:20 +0000147 if {$linemacros} {puts $out "#line 1 \"$filename\""}
drh91c58e22007-03-27 12:04:04 +0000148 set in [open $filename r]
drh73be5012007-08-08 12:11:21 +0000149 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)}
drh40a390d2009-02-18 12:25:28 +0000150 set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(}
drhee858132007-05-08 20:37:38 +0000151 if {[file extension $filename]==".h"} {
drhf7083bf2007-08-08 01:04:52 +0000152 set declpattern " *$declpattern"
drhee858132007-05-08 20:37:38 +0000153 }
drhf7083bf2007-08-08 01:04:52 +0000154 set declpattern ^$declpattern
drh91c58e22007-03-27 12:04:04 +0000155 while {![eof $in]} {
156 set line [gets $in]
drh96e50882011-08-15 15:27:20 +0000157 incr ln
drh9965a042008-10-14 18:21:11 +0000158 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
drh91c58e22007-03-27 12:04:04 +0000159 if {[info exists available_hdr($hdr)]} {
160 if {$available_hdr($hdr)} {
shane9bcbdad2008-05-29 20:22:37 +0000161 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
drh91c58e22007-03-27 12:04:04 +0000162 set available_hdr($hdr) 0
163 }
164 section_comment "Include $hdr in the middle of $tail"
165 copy_file tsrc/$hdr
166 section_comment "Continuing where we left off in $tail"
drh96e50882011-08-15 15:27:20 +0000167 if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
drh91c58e22007-03-27 12:04:04 +0000168 }
169 } elseif {![info exists seen_hdr($hdr)]} {
170 set seen_hdr($hdr) 1
171 puts $out $line
drh96e50882011-08-15 15:27:20 +0000172 } else {
173 puts $out "/* $line */"
drh91c58e22007-03-27 12:04:04 +0000174 }
175 } elseif {[regexp {^#ifdef __cplusplus} $line]} {
176 puts $out "#if 0"
drh96e50882011-08-15 15:27:20 +0000177 } elseif {!$linemacros && [regexp {^#line} $line]} {
drh91c58e22007-03-27 12:04:04 +0000178 # Skip #line directives.
drh73be5012007-08-08 12:11:21 +0000179 } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} {
drhd9c50f72009-08-14 18:18:03 +0000180 regsub {^SQLITE_API } $line {} line
drh0a0e1312007-08-07 17:04:59 +0000181 if {[regexp $declpattern $line all funcname]} {
182 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions.
183 # so that linkage can be modified at compile-time.
184 if {[regexp {^sqlite3_} $funcname]} {
185 puts $out "SQLITE_API $line"
186 } else {
187 puts $out "SQLITE_PRIVATE $line"
188 }
189 } elseif {[regexp $varpattern $line all varname]} {
190 # Add the SQLITE_PRIVATE before variable declarations or
191 # definitions for internal use
192 if {![regexp {^sqlite3_} $varname]} {
193 regsub {^extern } $line {} line
194 puts $out "SQLITE_PRIVATE $line"
195 } else {
drhb3190c12008-12-08 21:37:14 +0000196 if {[regexp {const char sqlite3_version\[\];} $line]} {
197 set line {const char sqlite3_version[] = SQLITE_VERSION;}
198 }
mlcreech6f10b3c2008-03-09 01:14:41 +0000199 regsub {^SQLITE_EXTERN } $line {} line
200 puts $out "SQLITE_API $line"
drh0a0e1312007-08-07 17:04:59 +0000201 }
mlcreech3a00f902008-03-04 17:45:01 +0000202 } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
203 regsub {^SQLITE_EXTERN } $line {} line
204 puts $out "SQLITE_PRIVATE $line"
drhf1581622009-02-03 13:51:17 +0000205 } elseif {[regexp {^void \(\*sqlite3Os} $line]} {
206 puts $out "SQLITE_PRIVATE $line"
drh26b0fc02007-06-26 00:52:39 +0000207 } else {
drh0a0e1312007-08-07 17:04:59 +0000208 puts $out $line
drh26b0fc02007-06-26 00:52:39 +0000209 }
drh91c58e22007-03-27 12:04:04 +0000210 } else {
211 puts $out $line
212 }
213 }
214 close $in
215 section_comment "End of $tail"
216}
217
218
219# Process the source files. Process files containing commonly
220# used subroutines first in order to help the compiler find
221# inlining opportunities.
222#
223foreach file {
drh71674ce2007-10-23 15:51:26 +0000224 sqliteInt.h
drh98495b42007-03-31 22:29:05 +0000225
drh40257ff2008-06-13 18:24:27 +0000226 global.c
drh735b9cb2010-03-10 23:13:53 +0000227 ctime.c
drhf7141992008-06-19 00:16:08 +0000228 status.c
drha55ca9e2007-04-02 12:22:44 +0000229 date.c
drh970f7242007-03-31 16:29:06 +0000230 os.c
231
drh643167f2008-01-22 21:30:53 +0000232 fault.c
drhd1370b62008-10-28 18:58:20 +0000233 mem0.c
drh97c8ec32007-08-27 21:49:34 +0000234 mem1.c
235 mem2.c
danielk19776b39c2e2008-06-25 14:57:53 +0000236 mem3.c
237 mem5.c
drh97c8ec32007-08-27 21:49:34 +0000238 mutex.c
drh18472fa2008-10-07 15:25:48 +0000239 mutex_noop.c
drh61f6dc62007-08-30 17:15:37 +0000240 mutex_unix.c
241 mutex_w32.c
drha3152892007-05-05 11:48:52 +0000242 malloc.c
drh91c58e22007-03-27 12:04:04 +0000243 printf.c
244 random.c
245 utf.c
246 util.c
247 hash.c
248 opcodes.c
249
drh91c58e22007-03-27 12:04:04 +0000250 os_unix.c
251 os_win.c
252
drhf5e7bb52008-02-18 14:47:33 +0000253 bitvec.c
danielk19778c0a7912008-08-20 14:49:23 +0000254 pcache.c
danielk1977d17e71c2008-11-13 14:42:18 +0000255 pcache1.c
drh3d4501e2008-12-04 20:40:10 +0000256 rowset.c
drh91c58e22007-03-27 12:04:04 +0000257 pager.c
shanehfd068632010-05-06 19:20:29 +0000258 wal.c
drh61f6dc62007-08-30 17:15:37 +0000259
shane9bcbdad2008-05-29 20:22:37 +0000260 btmutex.c
drh91c58e22007-03-27 12:04:04 +0000261 btree.c
danielk197704103022009-02-03 16:51:24 +0000262 backup.c
drh91c58e22007-03-27 12:04:04 +0000263
drh91c58e22007-03-27 12:04:04 +0000264 vdbemem.c
265 vdbeaux.c
266 vdbeapi.c
drhc7bc4fd2009-11-25 18:03:42 +0000267 vdbetrace.c
drh91c58e22007-03-27 12:04:04 +0000268 vdbe.c
drh3f755842007-05-03 16:55:32 +0000269 vdbeblob.c
dan7fe62702011-08-02 10:56:22 +0000270 vdbesort.c
drh97c8ec32007-08-27 21:49:34 +0000271 journal.c
danielk1977b3175382008-10-17 18:51:52 +0000272 memjournal.c
drh91c58e22007-03-27 12:04:04 +0000273
drh7d10d5a2008-08-20 16:35:10 +0000274 walker.c
275 resolve.c
drh91c58e22007-03-27 12:04:04 +0000276 expr.c
277 alter.c
278 analyze.c
279 attach.c
280 auth.c
281 build.c
282 callback.c
drh91c58e22007-03-27 12:04:04 +0000283 delete.c
drh70a8ca32008-08-21 18:49:27 +0000284 func.c
dan3be7d6e2009-09-19 17:59:59 +0000285 fkey.c
drh91c58e22007-03-27 12:04:04 +0000286 insert.c
287 legacy.c
288 loadext.c
289 pragma.c
290 prepare.c
291 select.c
292 table.c
293 trigger.c
294 update.c
295 vacuum.c
296 vtab.c
297 where.c
298
299 parse.c
300
301 tokenize.c
drh46c99e02007-08-27 23:26:59 +0000302 complete.c
drh91c58e22007-03-27 12:04:04 +0000303
304 main.c
danielk1977404ca072009-03-16 13:19:36 +0000305 notify.c
drh820a9062008-01-31 13:35:48 +0000306
307 fts3.c
dan290c9392011-02-01 18:59:34 +0000308 fts3_aux.c
drhaeba0202008-12-31 16:01:04 +0000309 fts3_expr.c
drh820a9062008-01-31 13:35:48 +0000310 fts3_hash.c
311 fts3_porter.c
312 fts3_tokenizer.c
313 fts3_tokenizer1.c
dan16708c42009-11-19 15:25:25 +0000314 fts3_write.c
315 fts3_snippet.c
dan3d403c72012-05-25 17:50:19 +0000316 fts3_unicode.c
317 fts3_unicode2.c
drh58f1c8b2008-05-26 20:19:25 +0000318
319 rtree.c
danielk19770c8a5d02008-08-04 11:49:20 +0000320 icu.c
danielk1977f9449d02008-09-24 09:58:00 +0000321 fts3_icu.c
drh91c58e22007-03-27 12:04:04 +0000322} {
323 copy_file tsrc/$file
324}
325
drh91c58e22007-03-27 12:04:04 +0000326close $out