Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/tool/mksqlite3c-noext.tcl # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / tool / mksqlite3c-noext.tcl` 368 lines ยท 10491 bytes Raw Blame History 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-noext.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 version number is needed to generate the header 27 # comment of the amalgamation. 28 # 29 set addstatic 1 30 set linemacros 0 31 set useapicall 0 32 for {set i 0} {$i<[llength $argv]} {incr i} { 33 set x [lindex $argv $i] 34 if {[regexp {^-+nostatic$} $x]} { 35 set addstatic 0 36 } elseif {[regexp {^-+linemacros} $x]} { 37 set linemacros 1 38 } elseif {[regexp {^-+useapicall} $x]} { 39 set useapicall 1 40 } else { 41 error "unknown command-line option: $x" 42 } 43 } 44 set in [open tsrc/sqlite3.h] 45 set cnt 0 46 set VERSION ????? 47 while {![eof $in]} { 48 set line [gets $in] 49 if {$line=="" && [eof $in]} break 50 incr cnt 51 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION 52 } 53 close $in 54 55 # Open the output file and write a header comment at the beginning 56 # of the file. 57 # 58 set out [open sqlite3.c w] 59 # Force the output to use unix line endings, even on Windows. 60 fconfigure $out -translation binary 61 set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1] 62 puts $out [subst \ 63 {/****************************************************************************** 64 ** This file is an amalgamation of many separate C source files from SQLite 65 ** version $VERSION. By combining all the individual C code files into this 66 ** single large file, the entire code can be compiled as a single translation 67 ** unit. This allows many compilers to do optimizations that would not be 68 ** possible if the files were compiled separately. Performance improvements 69 ** of 5% or more are commonly seen when SQLite is compiled as a single 70 ** translation unit. 71 ** 72 ** This file is all you need to compile SQLite. To use SQLite in other 73 ** programs, you need this file and the "sqlite3.h" header file that defines 74 ** the programming interface to the SQLite library. (If you do not have 75 ** the "sqlite3.h" header file at hand, you will find a copy embedded within 76 ** the text of this file. Search for "Begin file sqlite3.h" to find the start 77 ** of the embedded sqlite3.h header file.) Additional code files may be needed 78 ** if you want a wrapper to interface SQLite with your choice of programming 79 ** language. The code for the "sqlite3" command-line shell is also in a 80 ** separate file. This file contains only code for the core SQLite library. 81 */ 82 #define SQLITE_CORE 1 83 #define SQLITE_AMALGAMATION 1}] 84 if {$addstatic} { 85 puts $out \ 86 {#ifndef SQLITE_PRIVATE 87 # define SQLITE_PRIVATE static 88 #endif} 89 } 90 91 # These are the header files used by SQLite. The first time any of these 92 # files are seen in a #include statement in the C code, include the complete 93 # text of the file in-line. The file only needs to be included once. 94 # 95 foreach hdr { 96 btree.h 97 btreeInt.h 98 hash.h 99 hwtime.h 100 keywordhash.h 101 msvc.h 102 mutex.h 103 opcodes.h 104 os_common.h 105 os_setup.h 106 os_win.h 107 os.h 108 pager.h 109 parse.h 110 pcache.h 111 pragma.h 112 sqlite3.h 113 sqlite3ext.h 114 sqliteicu.h 115 sqliteInt.h 116 sqliteLimit.h 117 vdbe.h 118 vdbeInt.h 119 vxworks.h 120 wal.h 121 whereInt.h 122 } { 123 set available_hdr($hdr) 1 124 } 125 set available_hdr(sqliteInt.h) 0 126 127 # These headers should be copied into the amalgamation without modifying any 128 # of their function declarations or definitions. 129 set varonly_hdr(sqlite3.h) 1 130 131 # These are the functions that accept a variable number of arguments. They 132 # always need to use the "cdecl" calling convention even when another calling 133 # convention (e.g. "stcall") is being used for the rest of the library. 134 set cdecllist { 135 sqlite3_config 136 sqlite3_db_config 137 sqlite3_log 138 sqlite3_mprintf 139 sqlite3_snprintf 140 sqlite3_str_appendf 141 sqlite3_test_control 142 sqlite3_vtab_config 143 } 144 145 # 78 stars used for comment formatting. 146 set s78 \ 147 {*****************************************************************************} 148 149 # Insert a comment into the code 150 # 151 proc section_comment {text} { 152 global out s78 153 set n [string length $text] 154 set nstar [expr {60 - $n}] 155 set stars [string range $s78 0 $nstar] 156 puts $out "/************** $text $stars/" 157 } 158 159 # Read the source file named $filename and write it into the 160 # sqlite3.c output file. If any #include statements are seen, 161 # process them appropriately. 162 # 163 proc copy_file {filename} { 164 global seen_hdr available_hdr varonly_hdr cdecllist out 165 global addstatic linemacros useapicall 166 set ln 0 167 set tail [file tail $filename] 168 section_comment "Begin file $tail" 169 if {$linemacros} {puts $out "#line 1 \"$filename\""} 170 set in [open $filename r] 171 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} 172 set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)} 173 if {[file extension $filename]==".h"} { 174 set declpattern " *$declpattern" 175 } 176 set declpattern ^$declpattern\$ 177 while {![eof $in]} { 178 set line [gets $in] 179 incr ln 180 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { 181 if {[info exists available_hdr($hdr)]} { 182 if {$available_hdr($hdr)} { 183 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} { 184 set available_hdr($hdr) 0 185 } 186 section_comment "Include $hdr in the middle of $tail" 187 copy_file tsrc/$hdr 188 section_comment "Continuing where we left off in $tail" 189 if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} 190 } else { 191 # Comment out the entire line, replacing any nested comment 192 # begin/end markers with the harmless substring "**". 193 puts $out "/* [string map [list /* ** */ **] $line] */" 194 } 195 } elseif {![info exists seen_hdr($hdr)]} { 196 if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} { 197 set seen_hdr($hdr) 1 198 } 199 puts $out $line 200 } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} { 201 # This include file must be kept because there was a "keep" 202 # directive inside of a line comment. 203 puts $out $line 204 } else { 205 # Comment out the entire line, replacing any nested comment 206 # begin/end markers with the harmless substring "**". 207 puts $out "/* [string map [list /* ** */ **] $line] */" 208 } 209 } elseif {[regexp {^#ifdef __cplusplus} $line]} { 210 puts $out "#if 0" 211 } elseif {!$linemacros && [regexp {^#line} $line]} { 212 # Skip #line directives. 213 } elseif {$addstatic 214 && ![regexp {^(static|typedef|SQLITE_PRIVATE)} $line]} { 215 # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before 216 # functions if this header file does not need it. 217 if {![info exists varonly_hdr($tail)] 218 && [regexp $declpattern $line all rettype funcname rest]} { 219 regsub {^SQLITE_API } $line {} line 220 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. 221 # so that linkage can be modified at compile-time. 222 if {[regexp {^sqlite3[a-z]*_} $funcname]} { 223 set line SQLITE_API 224 append line " " [string trim $rettype] 225 if {[string index $rettype end] ne "*"} { 226 append line " " 227 } 228 if {$useapicall} { 229 if {[lsearch -exact $cdecllist $funcname] >= 0} { 230 append line SQLITE_CDECL " " 231 } else { 232 append line SQLITE_APICALL " " 233 } 234 } 235 append line $funcname $rest 236 puts $out $line 237 } else { 238 puts $out "SQLITE_PRIVATE $line" 239 } 240 } elseif {[regexp $varpattern $line all varname]} { 241 # Add the SQLITE_PRIVATE before variable declarations or 242 # definitions for internal use 243 regsub {^SQLITE_API } $line {} line 244 if {![regexp {^sqlite3_} $varname]} { 245 regsub {^extern } $line {} line 246 puts $out "SQLITE_PRIVATE $line" 247 } else { 248 if {[regexp {const char sqlite3_version\[\];} $line]} { 249 set line {const char sqlite3_version[] = SQLITE_VERSION;} 250 } 251 regsub {^SQLITE_EXTERN } $line {} line 252 puts $out "SQLITE_API $line" 253 } 254 } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { 255 regsub {^SQLITE_API } $line {} line 256 regsub {^SQLITE_EXTERN } $line {} line 257 puts $out $line 258 } elseif {[regexp {^void \(\*sqlite3Os} $line]} { 259 regsub {^SQLITE_API } $line {} line 260 puts $out "SQLITE_PRIVATE $line" 261 } else { 262 puts $out $line 263 } 264 } else { 265 puts $out $line 266 } 267 } 268 close $in 269 section_comment "End of $tail" 270 } 271 272 273 # Process the source files. Process files containing commonly 274 # used subroutines first in order to help the compiler find 275 # inlining opportunities. 276 # 277 foreach file { 278 sqliteInt.h 279 280 global.c 281 ctime.c 282 status.c 283 date.c 284 os.c 285 286 fault.c 287 mem0.c 288 mem1.c 289 mem2.c 290 mem3.c 291 mem5.c 292 mutex.c 293 mutex_noop.c 294 mutex_unix.c 295 mutex_w32.c 296 malloc.c 297 printf.c 298 treeview.c 299 random.c 300 threads.c 301 utf.c 302 util.c 303 hash.c 304 opcodes.c 305 306 os_unix.c 307 os_win.c 308 309 bitvec.c 310 pcache.c 311 pcache1.c 312 rowset.c 313 pager.c 314 wal.c 315 316 btmutex.c 317 btree.c 318 backup.c 319 320 vdbemem.c 321 vdbeaux.c 322 vdbeapi.c 323 vdbetrace.c 324 vdbe.c 325 vdbeblob.c 326 vdbesort.c 327 memjournal.c 328 329 walker.c 330 resolve.c 331 expr.c 332 alter.c 333 analyze.c 334 attach.c 335 auth.c 336 build.c 337 callback.c 338 delete.c 339 func.c 340 fkey.c 341 insert.c 342 legacy.c 343 loadext.c 344 pragma.c 345 prepare.c 346 select.c 347 table.c 348 trigger.c 349 update.c 350 vacuum.c 351 vtab.c 352 wherecode.c 353 whereexpr.c 354 where.c 355 window.c 356 357 parse.c 358 359 tokenize.c 360 complete.c 361 362 main.c 363 notify.c 364 } { 365 copy_file tsrc/$file 366 } 367 368 close $out