OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/tclsh |
| 2 # |
| 3 # This script constructs the "sqlite3.h" header file from the following |
| 4 # sources: |
| 5 # |
| 6 # 1) The src/sqlite.h.in source file. This is the template for sqlite3.h. |
| 7 # 2) The VERSION file containing the current SQLite version number. |
| 8 # 3) The manifest file from the fossil SCM. This gives use the date. |
| 9 # 4) The manifest.uuid file from the fossil SCM. This gives the SHA1 hash. |
| 10 # |
| 11 # Run this script by specifying the root directory of the source tree |
| 12 # on the command-line. |
| 13 # |
| 14 # This script performs processing on src/sqlite.h.in. It: |
| 15 # |
| 16 # 1) Adds SQLITE_EXTERN in front of the declaration of global variables, |
| 17 # 2) Adds SQLITE_API in front of the declaration of API functions, |
| 18 # 3) Replaces the string --VERS-- with the current library version, |
| 19 # formatted as a string (e.g. "3.6.17"), and |
| 20 # 4) Replaces the string --VERSION-NUMBER-- with current library version, |
| 21 # formatted as an integer (e.g. "3006017"). |
| 22 # 5) Replaces the string --SOURCE-ID-- with the date and time and sha1 |
| 23 # hash of the fossil-scm manifest for the source tree. |
| 24 # 6) Adds the SQLITE_CALLBACK calling convention macro in front of all |
| 25 # callback declarations. |
| 26 # |
| 27 # This script outputs to stdout. |
| 28 # |
| 29 # Example usage: |
| 30 # |
| 31 # tclsh mksqlite3h.tcl ../sqlite >sqlite3.h |
| 32 # |
| 33 |
| 34 |
| 35 # Get the source tree root directory from the command-line |
| 36 # |
| 37 set TOP [lindex $argv 0] |
| 38 |
| 39 # Enable use of SQLITE_APICALL macros at the right points? |
| 40 # |
| 41 set useapicall 0 |
| 42 |
| 43 if {[lsearch -regexp [lrange $argv 1 end] {^-+useapicall}] != -1} { |
| 44 set useapicall 1 |
| 45 } |
| 46 |
| 47 # Get the SQLite version number (ex: 3.6.18) from the $TOP/VERSION file. |
| 48 # |
| 49 set in [open $TOP/VERSION] |
| 50 set zVersion [string trim [read $in]] |
| 51 close $in |
| 52 set nVersion [eval format "%d%03d%03d" [split $zVersion .]] |
| 53 |
| 54 # Get the fossil-scm version number from $TOP/manifest.uuid. |
| 55 # |
| 56 set in [open $TOP/manifest.uuid] |
| 57 set zUuid [string trim [read $in]] |
| 58 close $in |
| 59 |
| 60 # Get the fossil-scm check-in date from the "D" card of $TOP/manifest. |
| 61 # |
| 62 set in [open $TOP/manifest] |
| 63 set zDate {} |
| 64 while {![eof $in]} { |
| 65 set line [gets $in] |
| 66 if {[regexp {^D (2[-0-9T:]+)} $line all date]} { |
| 67 set zDate [string map {T { }} $date] |
| 68 break |
| 69 } |
| 70 } |
| 71 close $in |
| 72 |
| 73 # Set up patterns for recognizing API declarations. |
| 74 # |
| 75 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)} |
| 76 set declpattern1 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3_[_a-zA-Z0-9]+)(\(.*)$} |
| 77 |
| 78 set declpattern2 \ |
| 79 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3session_[_a-zA-Z0-9]+)(\(.*)$} |
| 80 |
| 81 set declpattern3 \ |
| 82 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3changeset_[_a-zA-Z0-9]+)(\(.*)$} |
| 83 |
| 84 # Force the output to use unix line endings, even on Windows. |
| 85 fconfigure stdout -translation lf |
| 86 |
| 87 set filelist [subst { |
| 88 $TOP/src/sqlite.h.in |
| 89 $TOP/ext/rtree/sqlite3rtree.h |
| 90 $TOP/ext/session/sqlite3session.h |
| 91 $TOP/ext/fts5/fts5.h |
| 92 }] |
| 93 |
| 94 # These are the functions that accept a variable number of arguments. They |
| 95 # always need to use the "cdecl" calling convention even when another calling |
| 96 # convention (e.g. "stcall") is being used for the rest of the library. |
| 97 set cdecllist { |
| 98 sqlite3_config |
| 99 sqlite3_db_config |
| 100 sqlite3_log |
| 101 sqlite3_mprintf |
| 102 sqlite3_snprintf |
| 103 sqlite3_test_control |
| 104 sqlite3_vtab_config |
| 105 } |
| 106 |
| 107 # Process the source files. |
| 108 # |
| 109 foreach file $filelist { |
| 110 set in [open $file] |
| 111 if {![regexp {sqlite\.h\.in} $file]} { |
| 112 puts "/******** Begin file [file tail $file] *********/" |
| 113 } |
| 114 while {![eof $in]} { |
| 115 |
| 116 set line [gets $in] |
| 117 |
| 118 # File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this |
| 119 # line when copying sqlite3rtree.h into sqlite3.h. |
| 120 # |
| 121 if {[string match {*#include*[<"]sqlite3.h[>"]*} $line]} continue |
| 122 |
| 123 regsub -- --VERS-- $line $zVersion line |
| 124 regsub -- --VERSION-NUMBER-- $line $nVersion line |
| 125 regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line |
| 126 |
| 127 if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} { |
| 128 set line "SQLITE_API $line" |
| 129 } else { |
| 130 if {[regexp $declpattern1 $line all rettype funcname rest] || \ |
| 131 [regexp $declpattern2 $line all rettype funcname rest] || \ |
| 132 [regexp $declpattern3 $line all rettype funcname rest]} { |
| 133 set line SQLITE_API |
| 134 append line " " [string trim $rettype] |
| 135 if {[string index $rettype end] ne "*"} { |
| 136 append line " " |
| 137 } |
| 138 if {$useapicall} { |
| 139 if {[lsearch -exact $cdecllist $funcname] >= 0} { |
| 140 append line SQLITE_CDECL " " |
| 141 } else { |
| 142 append line SQLITE_APICALL " " |
| 143 } |
| 144 } |
| 145 append line $funcname $rest |
| 146 } |
| 147 } |
| 148 if {$useapicall} { |
| 149 set line [string map [list (*sqlite3_syscall_ptr) \ |
| 150 "(SQLITE_SYSAPI *sqlite3_syscall_ptr)"] $line] |
| 151 regsub {\(\*} $line {(SQLITE_CALLBACK *} line |
| 152 } |
| 153 puts $line |
| 154 } |
| 155 close $in |
| 156 if {![regexp {sqlite\.h\.in} $file]} { |
| 157 puts "/******** End of [file tail $file] *********/" |
| 158 } |
| 159 } |
OLD | NEW |