danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 1 | #!/usr/bin/tclsh |
| 2 | # |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 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 | # |
danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 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"). |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 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. |
danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 24 | # |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 25 | # This script outputs to stdout. |
danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 26 | # |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 27 | # Example usage: |
| 28 | # |
| 29 | # tclsh mksqlite3h.tcl ../sqlite >sqlite3.h |
danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 30 | # |
| 31 | |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 32 | |
| 33 | # Get the source tree root directory from the command-line |
| 34 | # |
| 35 | set TOP [lindex $argv 0] |
| 36 | |
| 37 | # Get the SQLite version number (ex: 3.6.18) from the $TOP/VERSION file. |
| 38 | # |
| 39 | set in [open $TOP/VERSION] |
| 40 | set zVersion [string trim [read $in]] |
| 41 | close $in |
danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 42 | set nVersion [eval format "%d%03d%03d" [split $zVersion .]] |
| 43 | |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 44 | # Get the fossil-scm version number from $TOP/manifest.uuid. |
| 45 | # |
| 46 | set in [open $TOP/manifest.uuid] |
| 47 | set zUuid [string trim [read $in]] |
| 48 | close $in |
danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 49 | |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 50 | # Get the fossil-scm check-in date from the "D" card of $TOP/manifest. |
| 51 | # |
| 52 | set in [open $TOP/manifest] |
| 53 | set zDate {} |
| 54 | while {![eof $in]} { |
| 55 | set line [gets $in] |
drh | bbd9194 | 2011-01-11 12:46:05 +0000 | [diff] [blame] | 56 | if {[regexp {^D (2[-0-9T:]+)} $line all date]} { |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 57 | set zDate [string map {T { }} $date] |
| 58 | break |
| 59 | } |
| 60 | } |
| 61 | close $in |
| 62 | |
| 63 | # Set up patterns for recognizing API declarations. |
| 64 | # |
| 65 | set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)} |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 66 | set declpattern {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3_[_a-zA-Z0-9]+)(\(.*)$} |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 67 | |
shaneh | 5e0fb2c | 2011-06-17 15:54:59 +0000 | [diff] [blame] | 68 | # Force the output to use unix line endings, even on Windows. |
| 69 | fconfigure stdout -translation lf |
| 70 | |
drh | 339d6c6 | 2013-03-19 16:12:40 +0000 | [diff] [blame] | 71 | set filelist [subst { |
| 72 | $TOP/src/sqlite.h.in |
| 73 | $TOP/ext/rtree/sqlite3rtree.h |
drh | 5006565 | 2015-10-08 19:29:18 +0000 | [diff] [blame] | 74 | $TOP/ext/fts5/fts5.h |
drh | 339d6c6 | 2013-03-19 16:12:40 +0000 | [diff] [blame] | 75 | }] |
| 76 | |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 77 | # These are the functions that accept a variable number of arguments. They |
| 78 | # always need to use the "cdecl" calling convention even when another calling |
| 79 | # convention (e.g. "stcall") is being used for the rest of the library. |
| 80 | set cdecllist { |
| 81 | sqlite3_config |
| 82 | sqlite3_db_config |
| 83 | sqlite3_log |
| 84 | sqlite3_mprintf |
| 85 | sqlite3_snprintf |
| 86 | sqlite3_test_control |
| 87 | sqlite3_vtab_config |
| 88 | } |
| 89 | |
drh | 339d6c6 | 2013-03-19 16:12:40 +0000 | [diff] [blame] | 90 | # Process the source files. |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 91 | # |
drh | 339d6c6 | 2013-03-19 16:12:40 +0000 | [diff] [blame] | 92 | foreach file $filelist { |
dan | c223b8f | 2010-08-30 18:39:49 +0000 | [diff] [blame] | 93 | set in [open $file] |
| 94 | while {![eof $in]} { |
| 95 | |
| 96 | set line [gets $in] |
drh | 47baebc | 2009-08-14 16:01:24 +0000 | [diff] [blame] | 97 | |
dan | c223b8f | 2010-08-30 18:39:49 +0000 | [diff] [blame] | 98 | # File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this |
| 99 | # line when copying sqlite3rtree.h into sqlite3.h. |
| 100 | # |
drh | 9676c48 | 2015-10-15 12:06:11 +0000 | [diff] [blame] | 101 | if {[string match {*#include*[<"]sqlite3.h[>"]*} $line]} continue |
dan | c223b8f | 2010-08-30 18:39:49 +0000 | [diff] [blame] | 102 | |
| 103 | regsub -- --VERS-- $line $zVersion line |
| 104 | regsub -- --VERSION-NUMBER-- $line $nVersion line |
| 105 | regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line |
drh | 790fa6e | 2015-03-24 21:54:42 +0000 | [diff] [blame] | 106 | |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 107 | if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} { |
dan | c223b8f | 2010-08-30 18:39:49 +0000 | [diff] [blame] | 108 | set line "SQLITE_API $line" |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 109 | } else { |
| 110 | if {[regexp $declpattern $line all rettype funcname rest]} { |
| 111 | set line SQLITE_API |
| 112 | append line " " [string trim $rettype] |
| 113 | if {[string index $rettype end] ne "*"} { |
| 114 | append line " " |
| 115 | } |
| 116 | if {[lsearch -exact $cdecllist $funcname] >= 0} { |
| 117 | append line SQLITE_CDECL |
| 118 | } else { |
| 119 | append line SQLITE_STDCALL |
| 120 | } |
| 121 | append line " " $funcname $rest |
| 122 | } |
dan | c223b8f | 2010-08-30 18:39:49 +0000 | [diff] [blame] | 123 | } |
danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 124 | puts $line |
danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 125 | } |
dan | c223b8f | 2010-08-30 18:39:49 +0000 | [diff] [blame] | 126 | close $in |
danielk1977 | 2d04deb | 2009-08-11 05:50:36 +0000 | [diff] [blame] | 127 | } |