Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / third_party / sqlite / sqlite-src-3080704 / tool / mksqlite3c.tcl
blob0e979234f3203c35b9c97bc0e942d0f934adfada
1 #!/usr/bin/tclsh
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
7 # make target_source
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
18 # this script:
20 # tclsh mksqlite3c.tcl
22 # The amalgamated SQLite code will be written into sqlite3.c
25 # Begin by reading the "sqlite3.h" header file. Extract the version number
26 # from in this file. The version number is needed to generate the header
27 # comment of the amalgamation.
29 if {[lsearch $argv --nostatic]>=0} {
30 set addstatic 0
31 } else {
32 set addstatic 1
34 if {[lsearch $argv --linemacros]>=0} {
35 set linemacros 1
36 } else {
37 set linemacros 0
39 set in [open tsrc/sqlite3.h]
40 set cnt 0
41 set VERSION ?????
42 while {![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
48 close $in
50 # Open the output file and write a header comment at the beginning
51 # of the file.
53 set out [open sqlite3.c w]
54 # Force the output to use unix line endings, even on Windows.
55 fconfigure $out -translation lf
56 set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
57 puts $out [subst \
58 {/******************************************************************************
59 ** This file is an amalgamation of many separate C source files from SQLite
60 ** version $VERSION. By combining all the individual C code files into this
61 ** single large file, the entire code can be compiled as a single translation
62 ** unit. This allows many compilers to do optimizations that would not be
63 ** possible if the files were compiled separately. Performance improvements
64 ** of 5% or more are commonly seen when SQLite is compiled as a single
65 ** translation unit.
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
70 ** 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.
77 #define SQLITE_CORE 1
78 #define SQLITE_AMALGAMATION 1}]
79 if {$addstatic} {
80 puts $out \
81 {#ifndef SQLITE_PRIVATE
82 # define SQLITE_PRIVATE static
83 #endif
84 #ifndef SQLITE_API
85 # define SQLITE_API
86 #endif}
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.
93 foreach hdr {
94 btree.h
95 btreeInt.h
96 fts3.h
97 fts3Int.h
98 fts3_hash.h
99 fts3_tokenizer.h
100 hash.h
101 hwtime.h
102 keywordhash.h
103 mutex.h
104 opcodes.h
105 os_common.h
106 os_setup.h
107 os_win.h
108 os.h
109 pager.h
110 parse.h
111 pcache.h
112 rtree.h
113 sqlite3ext.h
114 sqlite3.h
115 sqliteicu.h
116 sqliteInt.h
117 sqliteLimit.h
118 vdbe.h
119 vdbeInt.h
120 wal.h
121 whereInt.h
123 set available_hdr($hdr) 1
125 set available_hdr(sqliteInt.h) 0
127 # 78 stars used for comment formatting.
128 set s78 \
129 {*****************************************************************************}
131 # Insert a comment into the code
133 proc section_comment {text} {
134 global out s78
135 set n [string length $text]
136 set nstar [expr {60 - $n}]
137 set stars [string range $s78 0 $nstar]
138 puts $out "/************** $text $stars/"
141 # Read the source file named $filename and write it into the
142 # sqlite3.c output file. If any #include statements are seen,
143 # process them appropriately.
145 proc copy_file {filename} {
146 global seen_hdr available_hdr out addstatic linemacros
147 set ln 0
148 set tail [file tail $filename]
149 section_comment "Begin file $tail"
150 if {$linemacros} {puts $out "#line 1 \"$filename\""}
151 set in [open $filename r]
152 set varpattern {^[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]+)\(}
154 if {[file extension $filename]==".h"} {
155 set declpattern " *$declpattern"
157 set declpattern ^$declpattern
158 while {![eof $in]} {
159 set line [gets $in]
160 incr ln
161 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
162 if {[info exists available_hdr($hdr)]} {
163 if {$available_hdr($hdr)} {
164 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
165 set available_hdr($hdr) 0
167 section_comment "Include $hdr in the middle of $tail"
168 copy_file tsrc/$hdr
169 section_comment "Continuing where we left off in $tail"
170 if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
172 } elseif {![info exists seen_hdr($hdr)]} {
173 if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} {
174 set seen_hdr($hdr) 1
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] */"
186 } elseif {[regexp {^#ifdef __cplusplus} $line]} {
187 puts $out "#if 0"
188 } elseif {!$linemacros && [regexp {^#line} $line]} {
189 # Skip #line directives.
190 } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} {
191 regsub {^SQLITE_API } $line {} line
192 if {[regexp $declpattern $line all funcname]} {
193 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions.
194 # so that linkage can be modified at compile-time.
195 if {[regexp {^sqlite3_} $funcname]} {
196 puts $out "SQLITE_API $line"
197 } else {
198 puts $out "SQLITE_PRIVATE $line"
200 } elseif {[regexp $varpattern $line all varname]} {
201 # Add the SQLITE_PRIVATE before variable declarations or
202 # definitions for internal use
203 if {![regexp {^sqlite3_} $varname]} {
204 regsub {^extern } $line {} line
205 puts $out "SQLITE_PRIVATE $line"
206 } else {
207 if {[regexp {const char sqlite3_version\[\];} $line]} {
208 set line {const char sqlite3_version[] = SQLITE_VERSION;}
210 regsub {^SQLITE_EXTERN } $line {} line
211 puts $out "SQLITE_API $line"
213 } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
214 regsub {^SQLITE_EXTERN } $line {} line
215 puts $out "SQLITE_PRIVATE $line"
216 } elseif {[regexp {^void \(\*sqlite3Os} $line]} {
217 puts $out "SQLITE_PRIVATE $line"
218 } else {
219 puts $out $line
221 } else {
222 puts $out $line
225 close $in
226 section_comment "End of $tail"
230 # Process the source files. Process files containing commonly
231 # used subroutines first in order to help the compiler find
232 # inlining opportunities.
234 foreach file {
235 sqliteInt.h
237 global.c
238 ctime.c
239 status.c
240 date.c
241 os.c
243 fault.c
244 mem0.c
245 mem1.c
246 mem2.c
247 mem3.c
248 mem5.c
249 mutex.c
250 mutex_noop.c
251 mutex_unix.c
252 mutex_w32.c
253 malloc.c
254 printf.c
255 random.c
256 threads.c
257 utf.c
258 util.c
259 hash.c
260 opcodes.c
262 os_unix.c
263 os_win.c
265 bitvec.c
266 pcache.c
267 pcache1.c
268 rowset.c
269 pager.c
270 wal.c
272 btmutex.c
273 btree.c
274 backup.c
276 vdbemem.c
277 vdbeaux.c
278 vdbeapi.c
279 vdbetrace.c
280 vdbe.c
281 vdbeblob.c
282 vdbesort.c
283 journal.c
284 memjournal.c
286 walker.c
287 resolve.c
288 expr.c
289 alter.c
290 analyze.c
291 attach.c
292 auth.c
293 build.c
294 callback.c
295 delete.c
296 func.c
297 fkey.c
298 insert.c
299 legacy.c
300 loadext.c
301 pragma.c
302 prepare.c
303 select.c
304 table.c
305 trigger.c
306 update.c
307 vacuum.c
308 vtab.c
309 where.c
311 parse.c
313 tokenize.c
314 complete.c
316 main.c
317 notify.c
319 fts3.c
320 fts3_aux.c
321 fts3_expr.c
322 fts3_hash.c
323 fts3_porter.c
324 fts3_tokenizer.c
325 fts3_tokenizer1.c
326 fts3_tokenize_vtab.c
327 fts3_write.c
328 fts3_snippet.c
329 fts3_unicode.c
330 fts3_unicode2.c
332 rtree.c
333 icu.c
334 fts3_icu.c
336 copy_file tsrc/$file
339 close $out