OLD | NEW |
1 #!/usr/bin/tclsh | 1 #!/usr/bin/tclsh |
2 # | 2 # |
3 # To build a single huge source file holding all of SQLite (or at | 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 | 4 # least the core components - the test harness, shell, and TCL |
5 # interface are omitted.) first do | 5 # interface are omitted.) first do |
6 # | 6 # |
7 # make target_source | 7 # make target_source |
8 # | 8 # |
9 # The make target above moves all of the source code files into | 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 | 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 | 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. | 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 | 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 | 14 # the parser are derived from "parse.y" using lemon. And the |
15 # "keywordhash.h" files is generated by a program named "mkkeywordhash". | 15 # "keywordhash.h" files is generated by a program named "mkkeywordhash". |
16 # | 16 # |
17 # After the "tsrc" directory has been created and populated, run | 17 # After the "tsrc" directory has been created and populated, run |
18 # this script: | 18 # this script: |
19 # | 19 # |
20 # tclsh mksqlite3c.tcl | 20 # tclsh mksqlite3c.tcl |
21 # | 21 # |
22 # The amalgamated SQLite code will be written into sqlite3.c | 22 # The amalgamated SQLite code will be written into sqlite3.c |
23 # | 23 # |
24 | 24 |
25 # Begin by reading the "sqlite3.h" header file. Extract the version number | 25 # 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 | 26 # from in this file. The version number is needed to generate the header |
27 # comment of the amalgamation. | 27 # comment of the amalgamation. |
28 # | 28 # |
29 if {[lsearch $argv --nostatic]>=0} { | 29 if {[lsearch $argv --nostatic]>=0} { |
30 set addstatic 0 | 30 set addstatic 0 |
31 } else { | 31 } else { |
32 set addstatic 1 | 32 set addstatic 1 |
33 } | 33 } |
| 34 if {[lsearch $argv --linemacros]>=0} { |
| 35 set linemacros 1 |
| 36 } else { |
| 37 set linemacros 0 |
| 38 } |
34 set in [open tsrc/sqlite3.h] | 39 set in [open tsrc/sqlite3.h] |
35 set cnt 0 | 40 set cnt 0 |
36 set VERSION ????? | 41 set VERSION ????? |
37 while {![eof $in]} { | 42 while {![eof $in]} { |
38 set line [gets $in] | 43 set line [gets $in] |
39 if {$line=="" && [eof $in]} break | 44 if {$line=="" && [eof $in]} break |
40 incr cnt | 45 incr cnt |
41 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION | 46 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION |
42 } | 47 } |
43 close $in | 48 close $in |
44 | 49 |
45 # Open the output file and write a header comment at the beginning | 50 # Open the output file and write a header comment at the beginning |
46 # of the file. | 51 # of the file. |
47 # | 52 # |
48 set out [open sqlite3.c w] | 53 set out [open sqlite3.c w] |
| 54 # Force the output to use unix line endings, even on Windows. |
| 55 fconfigure $out -translation lf |
49 set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1] | 56 set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1] |
50 puts $out [subst \ | 57 puts $out [subst \ |
51 {/****************************************************************************** | 58 {/****************************************************************************** |
52 ** This file is an amalgamation of many separate C source files from SQLite | 59 ** This file is an amalgamation of many separate C source files from SQLite |
53 ** version $VERSION. By combining all the individual C code files into this | 60 ** version $VERSION. By combining all the individual C code files into this |
54 ** single large file, the entire code can be compiled as a single translation | 61 ** single large file, the entire code can be compiled as a single translation |
55 ** unit. This allows many compilers to do optimizations that would not be | 62 ** unit. This allows many compilers to do optimizations that would not be |
56 ** possible if the files were compiled separately. Performance improvements | 63 ** possible if the files were compiled separately. Performance improvements |
57 ** of 5% or more are commonly seen when SQLite is compiled as a single | 64 ** of 5% or more are commonly seen when SQLite is compiled as a single |
58 ** translation unit. | 65 ** translation unit. |
(...skipping 30 matching lines...) Expand all Loading... |
89 fts3.h | 96 fts3.h |
90 fts3Int.h | 97 fts3Int.h |
91 fts3_hash.h | 98 fts3_hash.h |
92 fts3_tokenizer.h | 99 fts3_tokenizer.h |
93 hash.h | 100 hash.h |
94 hwtime.h | 101 hwtime.h |
95 keywordhash.h | 102 keywordhash.h |
96 mutex.h | 103 mutex.h |
97 opcodes.h | 104 opcodes.h |
98 os_common.h | 105 os_common.h |
| 106 os_setup.h |
| 107 os_win.h |
99 os.h | 108 os.h |
100 os_os2.h | |
101 pager.h | 109 pager.h |
102 parse.h | 110 parse.h |
103 pcache.h | 111 pcache.h |
104 rtree.h | 112 rtree.h |
105 sqlite3ext.h | 113 sqlite3ext.h |
106 sqlite3.h | 114 sqlite3.h |
107 sqliteicu.h | 115 sqliteicu.h |
108 sqliteInt.h | 116 sqliteInt.h |
109 sqliteLimit.h | 117 sqliteLimit.h |
110 vdbe.h | 118 vdbe.h |
111 vdbeInt.h | 119 vdbeInt.h |
112 wal.h | 120 wal.h |
| 121 whereInt.h |
113 } { | 122 } { |
114 set available_hdr($hdr) 1 | 123 set available_hdr($hdr) 1 |
115 } | 124 } |
116 set available_hdr(sqliteInt.h) 0 | 125 set available_hdr(sqliteInt.h) 0 |
117 | 126 |
118 # 78 stars used for comment formatting. | 127 # 78 stars used for comment formatting. |
119 set s78 \ | 128 set s78 \ |
120 {*****************************************************************************} | 129 {*****************************************************************************} |
121 | 130 |
122 # Insert a comment into the code | 131 # Insert a comment into the code |
123 # | 132 # |
124 proc section_comment {text} { | 133 proc section_comment {text} { |
125 global out s78 | 134 global out s78 |
126 set n [string length $text] | 135 set n [string length $text] |
127 set nstar [expr {60 - $n}] | 136 set nstar [expr {60 - $n}] |
128 set stars [string range $s78 0 $nstar] | 137 set stars [string range $s78 0 $nstar] |
129 puts $out "/************** $text $stars/" | 138 puts $out "/************** $text $stars/" |
130 } | 139 } |
131 | 140 |
132 # Read the source file named $filename and write it into the | 141 # Read the source file named $filename and write it into the |
133 # sqlite3.c output file. If any #include statements are seen, | 142 # sqlite3.c output file. If any #include statements are seen, |
134 # process them approprately. | 143 # process them appropriately. |
135 # | 144 # |
136 proc copy_file {filename} { | 145 proc copy_file {filename} { |
137 global seen_hdr available_hdr out addstatic | 146 global seen_hdr available_hdr out addstatic linemacros |
| 147 set ln 0 |
138 set tail [file tail $filename] | 148 set tail [file tail $filename] |
139 section_comment "Begin file $tail" | 149 section_comment "Begin file $tail" |
| 150 if {$linemacros} {puts $out "#line 1 \"$filename\""} |
140 set in [open $filename r] | 151 set in [open $filename r] |
141 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} | 152 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} |
142 set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} | 153 set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} |
143 if {[file extension $filename]==".h"} { | 154 if {[file extension $filename]==".h"} { |
144 set declpattern " *$declpattern" | 155 set declpattern " *$declpattern" |
145 } | 156 } |
146 set declpattern ^$declpattern | 157 set declpattern ^$declpattern |
147 while {![eof $in]} { | 158 while {![eof $in]} { |
148 set line [gets $in] | 159 set line [gets $in] |
| 160 incr ln |
149 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { | 161 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { |
150 if {[info exists available_hdr($hdr)]} { | 162 if {[info exists available_hdr($hdr)]} { |
151 if {$available_hdr($hdr)} { | 163 if {$available_hdr($hdr)} { |
152 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} { | 164 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} { |
153 set available_hdr($hdr) 0 | 165 set available_hdr($hdr) 0 |
154 } | 166 } |
155 section_comment "Include $hdr in the middle of $tail" | 167 section_comment "Include $hdr in the middle of $tail" |
156 copy_file tsrc/$hdr | 168 copy_file tsrc/$hdr |
157 section_comment "Continuing where we left off in $tail" | 169 section_comment "Continuing where we left off in $tail" |
| 170 if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} |
158 } | 171 } |
159 } elseif {![info exists seen_hdr($hdr)]} { | 172 } elseif {![info exists seen_hdr($hdr)]} { |
160 set seen_hdr($hdr) 1 | 173 if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} { |
| 174 set seen_hdr($hdr) 1 |
| 175 } |
161 puts $out $line | 176 puts $out $line |
| 177 } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} { |
| 178 # This include file must be kept because there was a "keep" |
| 179 # directive inside of a line comment. |
| 180 puts $out $line |
| 181 } else { |
| 182 # Comment out the entire line, replacing any nested comment |
| 183 # begin/end markers with the harmless substring "**". |
| 184 puts $out "/* [string map [list /* ** */ **] $line] */" |
162 } | 185 } |
163 } elseif {[regexp {^#ifdef __cplusplus} $line]} { | 186 } elseif {[regexp {^#ifdef __cplusplus} $line]} { |
164 puts $out "#if 0" | 187 puts $out "#if 0" |
165 } elseif {[regexp {^#line} $line]} { | 188 } elseif {!$linemacros && [regexp {^#line} $line]} { |
166 # Skip #line directives. | 189 # Skip #line directives. |
167 } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { | 190 } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { |
168 regsub {^SQLITE_API } $line {} line | 191 regsub {^SQLITE_API } $line {} line |
169 if {[regexp $declpattern $line all funcname]} { | 192 if {[regexp $declpattern $line all funcname]} { |
170 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. | 193 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. |
171 # so that linkage can be modified at compile-time. | 194 # so that linkage can be modified at compile-time. |
172 if {[regexp {^sqlite3_} $funcname]} { | 195 if {[regexp {^sqlite3_} $funcname]} { |
173 puts $out "SQLITE_API $line" | 196 puts $out "SQLITE_API $line" |
174 } else { | 197 } else { |
175 puts $out "SQLITE_PRIVATE $line" | 198 puts $out "SQLITE_PRIVATE $line" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 os.c | 241 os.c |
219 | 242 |
220 fault.c | 243 fault.c |
221 mem0.c | 244 mem0.c |
222 mem1.c | 245 mem1.c |
223 mem2.c | 246 mem2.c |
224 mem3.c | 247 mem3.c |
225 mem5.c | 248 mem5.c |
226 mutex.c | 249 mutex.c |
227 mutex_noop.c | 250 mutex_noop.c |
228 mutex_os2.c | |
229 mutex_unix.c | 251 mutex_unix.c |
230 mutex_w32.c | 252 mutex_w32.c |
231 malloc.c | 253 malloc.c |
232 printf.c | 254 printf.c |
233 random.c | 255 random.c |
| 256 threads.c |
234 utf.c | 257 utf.c |
235 util.c | 258 util.c |
236 hash.c | 259 hash.c |
237 opcodes.c | 260 opcodes.c |
238 | 261 |
239 os_os2.c | |
240 os_unix.c | 262 os_unix.c |
241 os_win.c | 263 os_win.c |
242 | 264 |
243 bitvec.c | 265 bitvec.c |
244 pcache.c | 266 pcache.c |
245 pcache1.c | 267 pcache1.c |
246 rowset.c | 268 rowset.c |
247 pager.c | 269 pager.c |
248 wal.c | 270 wal.c |
249 | 271 |
250 btmutex.c | 272 btmutex.c |
251 btree.c | 273 btree.c |
252 backup.c | 274 backup.c |
253 | 275 |
254 vdbemem.c | 276 vdbemem.c |
255 vdbeaux.c | 277 vdbeaux.c |
256 vdbeapi.c | 278 vdbeapi.c |
257 vdbetrace.c | 279 vdbetrace.c |
258 vdbe.c | 280 vdbe.c |
259 vdbeblob.c | 281 vdbeblob.c |
| 282 vdbesort.c |
260 journal.c | 283 journal.c |
261 memjournal.c | 284 memjournal.c |
262 | 285 |
263 walker.c | 286 walker.c |
264 resolve.c | 287 resolve.c |
265 expr.c | 288 expr.c |
266 alter.c | 289 alter.c |
267 analyze.c | 290 analyze.c |
268 attach.c | 291 attach.c |
269 auth.c | 292 auth.c |
(...skipping 25 matching lines...) Expand all Loading... |
295 | 318 |
296 recover.c | 319 recover.c |
297 | 320 |
298 fts3.c | 321 fts3.c |
299 fts3_aux.c | 322 fts3_aux.c |
300 fts3_expr.c | 323 fts3_expr.c |
301 fts3_hash.c | 324 fts3_hash.c |
302 fts3_porter.c | 325 fts3_porter.c |
303 fts3_tokenizer.c | 326 fts3_tokenizer.c |
304 fts3_tokenizer1.c | 327 fts3_tokenizer1.c |
| 328 fts3_tokenize_vtab.c |
305 fts3_write.c | 329 fts3_write.c |
306 fts3_snippet.c | 330 fts3_snippet.c |
| 331 fts3_unicode.c |
| 332 fts3_unicode2.c |
307 | 333 |
308 rtree.c | 334 rtree.c |
309 icu.c | 335 icu.c |
310 fts3_icu.c | 336 fts3_icu.c |
311 } { | 337 } { |
312 copy_file tsrc/$file | 338 copy_file tsrc/$file |
313 } | 339 } |
314 | 340 |
315 close $out | 341 close $out |
OLD | NEW |