| 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 set in [open tsrc/sqlite3.h] | |
| 35 set cnt 0 | |
| 36 set VERSION ????? | |
| 37 while {![eof $in]} { | |
| 38 set line [gets $in] | |
| 39 if {$line=="" && [eof $in]} break | |
| 40 incr cnt | |
| 41 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION | |
| 42 } | |
| 43 close $in | |
| 44 | |
| 45 # Open the output file and write a header comment at the beginning | |
| 46 # of the file. | |
| 47 # | |
| 48 set out [open sqlite3.c w] | |
| 49 set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1] | |
| 50 puts $out [subst \ | |
| 51 {/****************************************************************************** | |
| 52 ** 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 | |
| 54 ** single large file, the entire code can be compiled as a one translation | |
| 55 ** unit. This allows many compilers to do optimizations that would not be | |
| 56 ** possible if the files were compiled separately. Performance improvements | |
| 57 ** of 5% are more are commonly seen when SQLite is compiled as a single | |
| 58 ** translation unit. | |
| 59 ** | |
| 60 ** This file is all you need to compile SQLite. To use SQLite in other | |
| 61 ** programs, you need this file and the "sqlite3.h" header file that defines | |
| 62 ** the programming interface to the SQLite library. (If you do not have | |
| 63 ** the "sqlite3.h" header file at hand, you will find a copy embedded within | |
| 64 ** the text of this file. Search for "Begin file sqlite3.h" to find the start | |
| 65 ** of the embedded sqlite3.h header file.) Additional code files may be needed | |
| 66 ** if you want a wrapper to interface SQLite with your choice of programming | |
| 67 ** language. The code for the "sqlite3" command-line shell is also in a | |
| 68 ** separate file. This file contains only code for the core SQLite library. | |
| 69 ** | |
| 70 ** This amalgamation was generated on $today. | |
| 71 */ | |
| 72 #define SQLITE_CORE 1 | |
| 73 #define SQLITE_AMALGAMATION 1}] | |
| 74 if {$addstatic} { | |
| 75 puts $out \ | |
| 76 {#ifndef SQLITE_PRIVATE | |
| 77 # define SQLITE_PRIVATE static | |
| 78 #endif | |
| 79 #ifndef SQLITE_API | |
| 80 # define SQLITE_API | |
| 81 #endif} | |
| 82 } | |
| 83 | |
| 84 # These are the header files used by SQLite. The first time any of these | |
| 85 # files are seen in a #include statement in the C code, include the complete | |
| 86 # text of the file in-line. The file only needs to be included once. | |
| 87 # | |
| 88 foreach hdr { | |
| 89 btree.h | |
| 90 btreeInt.h | |
| 91 fts3.h | |
| 92 fts3_expr.h | |
| 93 fts3_hash.h | |
| 94 fts3_tokenizer.h | |
| 95 hash.h | |
| 96 hwtime.h | |
| 97 keywordhash.h | |
| 98 mutex.h | |
| 99 opcodes.h | |
| 100 os_common.h | |
| 101 os.h | |
| 102 os_os2.h | |
| 103 pager.h | |
| 104 parse.h | |
| 105 pcache.h | |
| 106 rtree.h | |
| 107 sqlite3ext.h | |
| 108 sqlite3.h | |
| 109 sqliteicu.h | |
| 110 sqliteInt.h | |
| 111 sqliteLimit.h | |
| 112 vdbe.h | |
| 113 vdbeInt.h | |
| 114 } { | |
| 115 set available_hdr($hdr) 1 | |
| 116 } | |
| 117 set available_hdr(sqliteInt.h) 0 | |
| 118 | |
| 119 # 78 stars used for comment formatting. | |
| 120 set s78 \ | |
| 121 {*****************************************************************************} | |
| 122 | |
| 123 # Insert a comment into the code | |
| 124 # | |
| 125 proc section_comment {text} { | |
| 126 global out s78 | |
| 127 set n [string length $text] | |
| 128 set nstar [expr {60 - $n}] | |
| 129 set stars [string range $s78 0 $nstar] | |
| 130 puts $out "/************** $text $stars/" | |
| 131 } | |
| 132 | |
| 133 # Read the source file named $filename and write it into the | |
| 134 # sqlite3.c output file. If any #include statements are seen, | |
| 135 # process them approprately. | |
| 136 # | |
| 137 proc copy_file {filename} { | |
| 138 global seen_hdr available_hdr out addstatic | |
| 139 set tail [file tail $filename] | |
| 140 section_comment "Begin file $tail" | |
| 141 set in [open $filename r] | |
| 142 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} | |
| 143 set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} | |
| 144 if {[file extension $filename]==".h"} { | |
| 145 set declpattern " *$declpattern" | |
| 146 } | |
| 147 set declpattern ^$declpattern | |
| 148 while {![eof $in]} { | |
| 149 set line [gets $in] | |
| 150 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { | |
| 151 if {[info exists available_hdr($hdr)]} { | |
| 152 if {$available_hdr($hdr)} { | |
| 153 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} { | |
| 154 set available_hdr($hdr) 0 | |
| 155 } | |
| 156 section_comment "Include $hdr in the middle of $tail" | |
| 157 copy_file tsrc/$hdr | |
| 158 section_comment "Continuing where we left off in $tail" | |
| 159 } | |
| 160 } elseif {![info exists seen_hdr($hdr)]} { | |
| 161 set seen_hdr($hdr) 1 | |
| 162 puts $out $line | |
| 163 } | |
| 164 } elseif {[regexp {^#ifdef __cplusplus} $line]} { | |
| 165 puts $out "#if 0" | |
| 166 } elseif {[regexp {^#line} $line]} { | |
| 167 # Skip #line directives. | |
| 168 } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { | |
| 169 regsub {^SQLITE_API } $line {} line | |
| 170 if {[regexp $declpattern $line all funcname]} { | |
| 171 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. | |
| 172 # so that linkage can be modified at compile-time. | |
| 173 if {[regexp {^sqlite3_} $funcname]} { | |
| 174 puts $out "SQLITE_API $line" | |
| 175 } else { | |
| 176 puts $out "SQLITE_PRIVATE $line" | |
| 177 } | |
| 178 } elseif {[regexp $varpattern $line all varname]} { | |
| 179 # Add the SQLITE_PRIVATE before variable declarations or | |
| 180 # definitions for internal use | |
| 181 if {![regexp {^sqlite3_} $varname]} { | |
| 182 regsub {^extern } $line {} line | |
| 183 puts $out "SQLITE_PRIVATE $line" | |
| 184 } else { | |
| 185 if {[regexp {const char sqlite3_version\[\];} $line]} { | |
| 186 set line {const char sqlite3_version[] = SQLITE_VERSION;} | |
| 187 } | |
| 188 regsub {^SQLITE_EXTERN } $line {} line | |
| 189 puts $out "SQLITE_API $line" | |
| 190 } | |
| 191 } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { | |
| 192 regsub {^SQLITE_EXTERN } $line {} line | |
| 193 puts $out "SQLITE_PRIVATE $line" | |
| 194 } elseif {[regexp {^void \(\*sqlite3Os} $line]} { | |
| 195 puts $out "SQLITE_PRIVATE $line" | |
| 196 } else { | |
| 197 puts $out $line | |
| 198 } | |
| 199 } else { | |
| 200 puts $out $line | |
| 201 } | |
| 202 } | |
| 203 close $in | |
| 204 section_comment "End of $tail" | |
| 205 } | |
| 206 | |
| 207 | |
| 208 # Process the source files. Process files containing commonly | |
| 209 # used subroutines first in order to help the compiler find | |
| 210 # inlining opportunities. | |
| 211 # | |
| 212 foreach file { | |
| 213 sqliteInt.h | |
| 214 | |
| 215 global.c | |
| 216 status.c | |
| 217 date.c | |
| 218 os.c | |
| 219 | |
| 220 fault.c | |
| 221 mem0.c | |
| 222 mem1.c | |
| 223 mem2.c | |
| 224 mem3.c | |
| 225 mem5.c | |
| 226 mutex.c | |
| 227 mutex_noop.c | |
| 228 mutex_os2.c | |
| 229 mutex_unix.c | |
| 230 mutex_w32.c | |
| 231 malloc.c | |
| 232 printf.c | |
| 233 random.c | |
| 234 utf.c | |
| 235 util.c | |
| 236 hash.c | |
| 237 opcodes.c | |
| 238 | |
| 239 os_os2.c | |
| 240 os_unix.c | |
| 241 os_win.c | |
| 242 | |
| 243 bitvec.c | |
| 244 pcache.c | |
| 245 pcache1.c | |
| 246 rowset.c | |
| 247 pager.c | |
| 248 | |
| 249 btmutex.c | |
| 250 btree.c | |
| 251 backup.c | |
| 252 | |
| 253 vdbemem.c | |
| 254 vdbeaux.c | |
| 255 vdbeapi.c | |
| 256 vdbe.c | |
| 257 vdbeblob.c | |
| 258 journal.c | |
| 259 memjournal.c | |
| 260 | |
| 261 walker.c | |
| 262 resolve.c | |
| 263 expr.c | |
| 264 alter.c | |
| 265 analyze.c | |
| 266 attach.c | |
| 267 auth.c | |
| 268 build.c | |
| 269 callback.c | |
| 270 delete.c | |
| 271 func.c | |
| 272 insert.c | |
| 273 legacy.c | |
| 274 loadext.c | |
| 275 pragma.c | |
| 276 prepare.c | |
| 277 select.c | |
| 278 table.c | |
| 279 trigger.c | |
| 280 update.c | |
| 281 vacuum.c | |
| 282 vtab.c | |
| 283 where.c | |
| 284 | |
| 285 parse.c | |
| 286 | |
| 287 tokenize.c | |
| 288 complete.c | |
| 289 | |
| 290 main.c | |
| 291 notify.c | |
| 292 | |
| 293 fts3.c | |
| 294 fts3_expr.c | |
| 295 fts3_hash.c | |
| 296 fts3_porter.c | |
| 297 fts3_tokenizer.c | |
| 298 fts3_tokenizer1.c | |
| 299 | |
| 300 rtree.c | |
| 301 icu.c | |
| 302 fts3_icu.c | |
| 303 } { | |
| 304 copy_file tsrc/$file | |
| 305 } | |
| 306 | |
| 307 close $out | |
| OLD | NEW |