[sql] Import reference version of SQLite 3.7.6.3.
[chromium-blink-merge.git] / third_party / sqlite / sqlite-src-3070603 / tool / mksqlite3h.tcl
blob554069c32398ce78ef236cc8aad23b0e48406b56
1 #!/usr/bin/tclsh
3 # This script constructs the "sqlite3.h" header file from the following
4 # sources:
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.
11 # Run this script by specifying the root directory of the source tree
12 # on the command-line.
14 # This script performs processing on src/sqlite.h.in. It:
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.
25 # This script outputs to stdout.
27 # Example usage:
29 # tclsh mksqlite3h.tcl ../sqlite >sqlite3.h
33 # Get the source tree root directory from the command-line
35 set TOP [lindex $argv 0]
37 # Get the SQLite version number (ex: 3.6.18) from the $TOP/VERSION file.
39 set in [open $TOP/VERSION]
40 set zVersion [string trim [read $in]]
41 close $in
42 set nVersion [eval format "%d%03d%03d" [split $zVersion .]]
44 # Get the fossil-scm version number from $TOP/manifest.uuid.
46 set in [open $TOP/manifest.uuid]
47 set zUuid [string trim [read $in]]
48 close $in
50 # Get the fossil-scm check-in date from the "D" card of $TOP/manifest.
52 set in [open $TOP/manifest]
53 set zDate {}
54 while {![eof $in]} {
55 set line [gets $in]
56 if {[regexp {^D (2[-0-9T:]+)} $line all date]} {
57 set zDate [string map {T { }} $date]
58 break
61 close $in
63 # Set up patterns for recognizing API declarations.
65 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)}
66 set declpattern {^ *[a-zA-Z][a-zA-Z_0-9 ]+ \**sqlite3_[_a-zA-Z0-9]+\(}
68 # Process the src/sqlite.h.in ext/rtree/sqlite3rtree.h files.
70 foreach file [list $TOP/src/sqlite.h.in $TOP/ext/rtree/sqlite3rtree.h] {
71 set in [open $file]
72 while {![eof $in]} {
74 set line [gets $in]
76 # File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this
77 # line when copying sqlite3rtree.h into sqlite3.h.
79 if {[string match {*#include*<sqlite3.h>*} $line]} continue
81 regsub -- --VERS-- $line $zVersion line
82 regsub -- --VERSION-NUMBER-- $line $nVersion line
83 regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line
85 if {[regexp {define SQLITE_EXTERN extern} $line]} {
86 puts $line
87 puts [gets $in]
88 puts ""
89 puts "#ifndef SQLITE_API"
90 puts "# define SQLITE_API"
91 puts "#endif"
92 set line ""
95 if {([regexp $varpattern $line] && ![regexp {^ *typedef} $line])
96 || ([regexp $declpattern $line])
97 } {
98 set line "SQLITE_API $line"
100 puts $line
102 close $in