2009-08-11 07:50:36 +02:00
|
|
|
#!/usr/bin/tclsh
|
|
|
|
#
|
2009-08-14 18:01:24 +02:00
|
|
|
# This script constructs the "sqlite3.h" header file from the following
|
|
|
|
# sources:
|
|
|
|
#
|
|
|
|
# 1) The src/sqlite.h.in source file. This is the template for sqlite3.h.
|
|
|
|
# 2) The VERSION file containing the current SQLite version number.
|
|
|
|
# 3) The manifest file from the fossil SCM. This gives use the date.
|
|
|
|
# 4) The manifest.uuid file from the fossil SCM. This gives the SHA1 hash.
|
|
|
|
#
|
|
|
|
# Run this script by specifying the root directory of the source tree
|
|
|
|
# on the command-line.
|
|
|
|
#
|
2009-08-11 07:50:36 +02:00
|
|
|
# This script performs processing on src/sqlite.h.in. It:
|
|
|
|
#
|
|
|
|
# 1) Adds SQLITE_EXTERN in front of the declaration of global variables,
|
|
|
|
# 2) Adds SQLITE_API in front of the declaration of API functions,
|
|
|
|
# 3) Replaces the string --VERS-- with the current library version,
|
|
|
|
# formatted as a string (e.g. "3.6.17"), and
|
|
|
|
# 4) Replaces the string --VERSION-NUMBER-- with current library version,
|
|
|
|
# formatted as an integer (e.g. "3006017").
|
2009-08-14 18:01:24 +02:00
|
|
|
# 5) Replaces the string --SOURCE-ID-- with the date and time and sha1
|
|
|
|
# hash of the fossil-scm manifest for the source tree.
|
|
|
|
#
|
|
|
|
# This script outputs to stdout.
|
2009-08-11 07:50:36 +02:00
|
|
|
#
|
2009-08-14 18:01:24 +02:00
|
|
|
# Example usage:
|
2009-08-11 07:50:36 +02:00
|
|
|
#
|
2009-08-14 18:01:24 +02:00
|
|
|
# tclsh mksqlite3h.tcl ../sqlite >sqlite3.h
|
2009-08-11 07:50:36 +02:00
|
|
|
#
|
|
|
|
|
2009-08-14 18:01:24 +02:00
|
|
|
|
|
|
|
# Get the source tree root directory from the command-line
|
|
|
|
#
|
|
|
|
set TOP [lindex $argv 0]
|
|
|
|
|
|
|
|
# Get the SQLite version number (ex: 3.6.18) from the $TOP/VERSION file.
|
|
|
|
#
|
|
|
|
set in [open $TOP/VERSION]
|
|
|
|
set zVersion [string trim [read $in]]
|
|
|
|
close $in
|
2009-08-11 07:50:36 +02:00
|
|
|
set nVersion [eval format "%d%03d%03d" [split $zVersion .]]
|
|
|
|
|
2009-08-14 18:01:24 +02:00
|
|
|
# Get the fossil-scm version number from $TOP/manifest.uuid.
|
|
|
|
#
|
|
|
|
set in [open $TOP/manifest.uuid]
|
|
|
|
set zUuid [string trim [read $in]]
|
|
|
|
close $in
|
2009-08-11 07:50:36 +02:00
|
|
|
|
2009-08-14 18:01:24 +02:00
|
|
|
# Get the fossil-scm check-in date from the "D" card of $TOP/manifest.
|
|
|
|
#
|
|
|
|
set in [open $TOP/manifest]
|
|
|
|
set zDate {}
|
|
|
|
while {![eof $in]} {
|
|
|
|
set line [gets $in]
|
2011-01-11 13:46:05 +01:00
|
|
|
if {[regexp {^D (2[-0-9T:]+)} $line all date]} {
|
2009-08-14 18:01:24 +02:00
|
|
|
set zDate [string map {T { }} $date]
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $in
|
|
|
|
|
|
|
|
# Set up patterns for recognizing API declarations.
|
|
|
|
#
|
|
|
|
set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)}
|
|
|
|
set declpattern {^ *[a-zA-Z][a-zA-Z_0-9 ]+ \**sqlite3_[_a-zA-Z0-9]+\(}
|
|
|
|
|
2011-06-17 17:54:59 +02:00
|
|
|
# Force the output to use unix line endings, even on Windows.
|
|
|
|
fconfigure stdout -translation lf
|
|
|
|
|
2010-08-30 20:39:49 +02:00
|
|
|
# Process the src/sqlite.h.in ext/rtree/sqlite3rtree.h files.
|
2009-08-14 18:01:24 +02:00
|
|
|
#
|
2010-08-30 20:39:49 +02:00
|
|
|
foreach file [list $TOP/src/sqlite.h.in $TOP/ext/rtree/sqlite3rtree.h] {
|
|
|
|
set in [open $file]
|
|
|
|
while {![eof $in]} {
|
|
|
|
|
|
|
|
set line [gets $in]
|
2009-08-11 07:50:36 +02:00
|
|
|
|
2010-08-30 20:39:49 +02:00
|
|
|
# File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this
|
|
|
|
# line when copying sqlite3rtree.h into sqlite3.h.
|
|
|
|
#
|
|
|
|
if {[string match {*#include*<sqlite3.h>*} $line]} continue
|
|
|
|
|
|
|
|
regsub -- --VERS-- $line $zVersion line
|
|
|
|
regsub -- --VERSION-NUMBER-- $line $nVersion line
|
|
|
|
regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line
|
|
|
|
|
|
|
|
if {[regexp {define SQLITE_EXTERN extern} $line]} {
|
|
|
|
puts $line
|
|
|
|
puts [gets $in]
|
|
|
|
puts ""
|
|
|
|
puts "#ifndef SQLITE_API"
|
|
|
|
puts "# define SQLITE_API"
|
|
|
|
puts "#endif"
|
|
|
|
set line ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if {([regexp $varpattern $line] && ![regexp {^ *typedef} $line])
|
|
|
|
|| ([regexp $declpattern $line])
|
|
|
|
} {
|
|
|
|
set line "SQLITE_API $line"
|
|
|
|
}
|
2009-08-11 07:50:36 +02:00
|
|
|
puts $line
|
|
|
|
}
|
2010-08-30 20:39:49 +02:00
|
|
|
close $in
|
2009-08-11 07:50:36 +02:00
|
|
|
}
|