| OLD | NEW |
| (Empty) |
| 1 #!/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 # | |
| 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". | |
| 16 # | |
| 17 # After the "tsrc" directory has been created and populated, run | |
| 18 # this script: | |
| 19 # | |
| 20 # tclsh mksqlite3c.tcl | |
| 21 # | |
| 22 # The amalgamated SQLite code will be written into sqlite3.c | |
| 23 # | |
| 24 | |
| 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 | |
| 27 # comment of the amalgamation. | |
| 28 # | |
| 29 if {[lsearch $argv --nostatic]>=0} { | |
| 30 set addstatic 0 | |
| 31 } else { | |
| 32 set addstatic 1 | |
| 33 } | |
| 34 if {[lsearch $argv --linemacros]>=0} { | |
| 35 set linemacros 1 | |
| 36 } else { | |
| 37 set linemacros 0 | |
| 38 } | |
| 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 | |
| 47 } | |
| 48 close $in | |
| 49 | |
| 50 # Open the output file and write a header comment at the beginning | |
| 51 # of the file. | |
| 52 # | |
| 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. | |
| 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 | |
| 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. | |
| 76 */ | |
| 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} | |
| 87 } | |
| 88 | |
| 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 # | |
| 93 foreach hdr { | |
| 94 btree.h | |
| 95 btreeInt.h | |
| 96 hash.h | |
| 97 hwtime.h | |
| 98 keywordhash.h | |
| 99 mutex.h | |
| 100 opcodes.h | |
| 101 os_common.h | |
| 102 os_setup.h | |
| 103 os_win.h | |
| 104 os.h | |
| 105 pager.h | |
| 106 parse.h | |
| 107 pcache.h | |
| 108 sqlite3ext.h | |
| 109 sqlite3.h | |
| 110 sqliteicu.h | |
| 111 sqliteInt.h | |
| 112 sqliteLimit.h | |
| 113 vdbe.h | |
| 114 vdbeInt.h | |
| 115 wal.h | |
| 116 } { | |
| 117 set available_hdr($hdr) 1 | |
| 118 } | |
| 119 set available_hdr(sqliteInt.h) 0 | |
| 120 | |
| 121 # 78 stars used for comment formatting. | |
| 122 set s78 \ | |
| 123 {*****************************************************************************} | |
| 124 | |
| 125 # Insert a comment into the code | |
| 126 # | |
| 127 proc section_comment {text} { | |
| 128 global out s78 | |
| 129 set n [string length $text] | |
| 130 set nstar [expr {60 - $n}] | |
| 131 set stars [string range $s78 0 $nstar] | |
| 132 puts $out "/************** $text $stars/" | |
| 133 } | |
| 134 | |
| 135 # Read the source file named $filename and write it into the | |
| 136 # sqlite3.c output file. If any #include statements are seen, | |
| 137 # process them approprately. | |
| 138 # | |
| 139 proc copy_file {filename} { | |
| 140 global seen_hdr available_hdr out addstatic linemacros | |
| 141 set ln 0 | |
| 142 set tail [file tail $filename] | |
| 143 section_comment "Begin file $tail" | |
| 144 if {$linemacros} {puts $out "#line 1 \"$filename\""} | |
| 145 set in [open $filename r] | |
| 146 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} | |
| 147 set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} | |
| 148 if {[file extension $filename]==".h"} { | |
| 149 set declpattern " *$declpattern" | |
| 150 } | |
| 151 set declpattern ^$declpattern | |
| 152 while {![eof $in]} { | |
| 153 set line [gets $in] | |
| 154 incr ln | |
| 155 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { | |
| 156 if {[info exists available_hdr($hdr)]} { | |
| 157 if {$available_hdr($hdr)} { | |
| 158 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} { | |
| 159 set available_hdr($hdr) 0 | |
| 160 } | |
| 161 section_comment "Include $hdr in the middle of $tail" | |
| 162 copy_file tsrc/$hdr | |
| 163 section_comment "Continuing where we left off in $tail" | |
| 164 if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} | |
| 165 } | |
| 166 } elseif {![info exists seen_hdr($hdr)]} { | |
| 167 set seen_hdr($hdr) 1 | |
| 168 puts $out $line | |
| 169 } else { | |
| 170 puts $out "/* $line */" | |
| 171 } | |
| 172 } elseif {[regexp {^#ifdef __cplusplus} $line]} { | |
| 173 puts $out "#if 0" | |
| 174 } elseif {!$linemacros && [regexp {^#line} $line]} { | |
| 175 # Skip #line directives. | |
| 176 } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { | |
| 177 regsub {^SQLITE_API } $line {} line | |
| 178 if {[regexp $declpattern $line all funcname]} { | |
| 179 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. | |
| 180 # so that linkage can be modified at compile-time. | |
| 181 if {[regexp {^sqlite3_} $funcname]} { | |
| 182 puts $out "SQLITE_API $line" | |
| 183 } else { | |
| 184 puts $out "SQLITE_PRIVATE $line" | |
| 185 } | |
| 186 } elseif {[regexp $varpattern $line all varname]} { | |
| 187 # Add the SQLITE_PRIVATE before variable declarations or | |
| 188 # definitions for internal use | |
| 189 if {![regexp {^sqlite3_} $varname]} { | |
| 190 regsub {^extern } $line {} line | |
| 191 puts $out "SQLITE_PRIVATE $line" | |
| 192 } else { | |
| 193 if {[regexp {const char sqlite3_version\[\];} $line]} { | |
| 194 set line {const char sqlite3_version[] = SQLITE_VERSION;} | |
| 195 } | |
| 196 regsub {^SQLITE_EXTERN } $line {} line | |
| 197 puts $out "SQLITE_API $line" | |
| 198 } | |
| 199 } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { | |
| 200 regsub {^SQLITE_EXTERN } $line {} line | |
| 201 puts $out "SQLITE_PRIVATE $line" | |
| 202 } elseif {[regexp {^void \(\*sqlite3Os} $line]} { | |
| 203 puts $out "SQLITE_PRIVATE $line" | |
| 204 } else { | |
| 205 puts $out $line | |
| 206 } | |
| 207 } else { | |
| 208 puts $out $line | |
| 209 } | |
| 210 } | |
| 211 close $in | |
| 212 section_comment "End of $tail" | |
| 213 } | |
| 214 | |
| 215 | |
| 216 # Process the source files. Process files containing commonly | |
| 217 # used subroutines first in order to help the compiler find | |
| 218 # inlining opportunities. | |
| 219 # | |
| 220 foreach file { | |
| 221 sqliteInt.h | |
| 222 | |
| 223 global.c | |
| 224 ctime.c | |
| 225 status.c | |
| 226 date.c | |
| 227 os.c | |
| 228 | |
| 229 fault.c | |
| 230 mem0.c | |
| 231 mem1.c | |
| 232 mem2.c | |
| 233 mem3.c | |
| 234 mem5.c | |
| 235 mutex.c | |
| 236 mutex_noop.c | |
| 237 mutex_unix.c | |
| 238 mutex_w32.c | |
| 239 malloc.c | |
| 240 printf.c | |
| 241 random.c | |
| 242 threads.c | |
| 243 utf.c | |
| 244 util.c | |
| 245 hash.c | |
| 246 opcodes.c | |
| 247 | |
| 248 os_unix.c | |
| 249 os_win.c | |
| 250 | |
| 251 bitvec.c | |
| 252 pcache.c | |
| 253 pcache1.c | |
| 254 rowset.c | |
| 255 pager.c | |
| 256 wal.c | |
| 257 | |
| 258 btmutex.c | |
| 259 btree.c | |
| 260 backup.c | |
| 261 | |
| 262 vdbemem.c | |
| 263 vdbeaux.c | |
| 264 vdbeapi.c | |
| 265 vdbetrace.c | |
| 266 vdbe.c | |
| 267 vdbeblob.c | |
| 268 vdbesort.c | |
| 269 journal.c | |
| 270 memjournal.c | |
| 271 | |
| 272 walker.c | |
| 273 resolve.c | |
| 274 expr.c | |
| 275 alter.c | |
| 276 analyze.c | |
| 277 attach.c | |
| 278 auth.c | |
| 279 build.c | |
| 280 callback.c | |
| 281 delete.c | |
| 282 func.c | |
| 283 fkey.c | |
| 284 insert.c | |
| 285 legacy.c | |
| 286 loadext.c | |
| 287 pragma.c | |
| 288 prepare.c | |
| 289 select.c | |
| 290 table.c | |
| 291 trigger.c | |
| 292 update.c | |
| 293 vacuum.c | |
| 294 vtab.c | |
| 295 where.c | |
| 296 | |
| 297 parse.c | |
| 298 | |
| 299 tokenize.c | |
| 300 complete.c | |
| 301 | |
| 302 main.c | |
| 303 notify.c | |
| 304 } { | |
| 305 copy_file tsrc/$file | |
| 306 } | |
| 307 | |
| 308 close $out | |
| OLD | NEW |