2009-08-11 09:50:36 +04:00
|
|
|
#!/usr/bin/tclsh
|
|
|
|
#
|
2009-08-14 20:01:24 +04: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.
|
2016-08-24 22:58:46 +03:00
|
|
|
#
|
2009-08-11 09:50:36 +04: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,
|
2016-08-24 22:58:46 +03:00
|
|
|
# 3) Replaces the string --VERS-- with the current library version,
|
2009-08-11 09:50:36 +04:00
|
|
|
# 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").
|
2016-08-24 22:58:46 +03:00
|
|
|
# 5) Replaces the string --SOURCE-ID-- with the date and time and sha1
|
2009-08-14 20:01:24 +04:00
|
|
|
# hash of the fossil-scm manifest for the source tree.
|
2016-07-28 18:09:02 +03:00
|
|
|
# 6) Adds the SQLITE_CALLBACK calling convention macro in front of all
|
|
|
|
# callback declarations.
|
2009-08-14 20:01:24 +04:00
|
|
|
#
|
|
|
|
# This script outputs to stdout.
|
2009-08-11 09:50:36 +04:00
|
|
|
#
|
2009-08-14 20:01:24 +04:00
|
|
|
# Example usage:
|
2009-08-11 09:50:36 +04:00
|
|
|
#
|
2009-08-14 20:01:24 +04:00
|
|
|
# tclsh mksqlite3h.tcl ../sqlite >sqlite3.h
|
2009-08-11 09:50:36 +04:00
|
|
|
#
|
|
|
|
|
2009-08-14 20:01:24 +04:00
|
|
|
|
|
|
|
# Get the source tree root directory from the command-line
|
|
|
|
#
|
|
|
|
set TOP [lindex $argv 0]
|
|
|
|
|
2016-08-24 22:58:46 +03:00
|
|
|
# Enable use of SQLITE_APICALL macros at the right points?
|
|
|
|
#
|
|
|
|
set useapicall 0
|
|
|
|
|
2022-11-22 19:12:53 +03:00
|
|
|
# Include sqlite3recover.h?
|
|
|
|
#
|
|
|
|
set enable_recover 0
|
|
|
|
|
2016-08-24 22:58:46 +03:00
|
|
|
if {[lsearch -regexp [lrange $argv 1 end] {^-+useapicall}] != -1} {
|
|
|
|
set useapicall 1
|
|
|
|
}
|
2022-11-22 19:12:53 +03:00
|
|
|
if {[lsearch -regexp [lrange $argv 1 end] {^-+enable-recover}] != -1} {
|
|
|
|
set enable_recover 1
|
|
|
|
}
|
2016-08-24 22:58:46 +03:00
|
|
|
|
2009-08-14 20:01:24 +04:00
|
|
|
# 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 09:50:36 +04:00
|
|
|
set nVersion [eval format "%d%03d%03d" [split $zVersion .]]
|
|
|
|
|
2017-08-22 22:19:00 +03:00
|
|
|
# Get the source-id
|
2009-08-14 20:01:24 +04:00
|
|
|
#
|
2017-08-22 22:43:41 +03:00
|
|
|
set PWD [pwd]
|
|
|
|
cd $TOP
|
2017-08-22 22:49:34 +03:00
|
|
|
set zSourceId [exec $PWD/mksourceid manifest]
|
2017-08-22 22:43:41 +03:00
|
|
|
cd $PWD
|
2009-08-14 20:01:24 +04:00
|
|
|
|
|
|
|
# Set up patterns for recognizing API declarations.
|
|
|
|
#
|
|
|
|
set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)}
|
2017-02-08 00:09:34 +03:00
|
|
|
set declpattern1 {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3_[_a-zA-Z0-9]+)(\(.*)$}
|
|
|
|
|
|
|
|
set declpattern2 \
|
|
|
|
{^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3session_[_a-zA-Z0-9]+)(\(.*)$}
|
|
|
|
|
|
|
|
set declpattern3 \
|
|
|
|
{^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3changeset_[_a-zA-Z0-9]+)(\(.*)$}
|
2009-08-14 20:01:24 +04:00
|
|
|
|
2017-05-12 17:05:11 +03:00
|
|
|
set declpattern4 \
|
|
|
|
{^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3changegroup_[_a-zA-Z0-9]+)(\(.*)$}
|
|
|
|
|
2018-03-24 03:19:18 +03:00
|
|
|
set declpattern5 \
|
|
|
|
{^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3rebaser_[_a-zA-Z0-9]+)(\(.*)$}
|
|
|
|
|
2011-06-17 19:54:59 +04:00
|
|
|
# Force the output to use unix line endings, even on Windows.
|
|
|
|
fconfigure stdout -translation lf
|
|
|
|
|
2013-03-19 19:23:18 +04:00
|
|
|
set filelist [subst {
|
|
|
|
$TOP/src/sqlite.h.in
|
|
|
|
$TOP/ext/rtree/sqlite3rtree.h
|
|
|
|
$TOP/ext/session/sqlite3session.h
|
2015-10-08 22:29:18 +03:00
|
|
|
$TOP/ext/fts5/fts5.h
|
2013-03-19 19:23:18 +04:00
|
|
|
}]
|
2022-11-22 19:12:53 +03:00
|
|
|
if {$enable_recover} {
|
|
|
|
lappend filelist "$TOP/ext/recover/sqlite3recover.h"
|
|
|
|
}
|
2013-03-19 19:23:18 +04:00
|
|
|
|
2015-03-25 00:27:27 +03:00
|
|
|
# These are the functions that accept a variable number of arguments. They
|
|
|
|
# always need to use the "cdecl" calling convention even when another calling
|
|
|
|
# convention (e.g. "stcall") is being used for the rest of the library.
|
|
|
|
set cdecllist {
|
|
|
|
sqlite3_config
|
|
|
|
sqlite3_db_config
|
|
|
|
sqlite3_log
|
|
|
|
sqlite3_mprintf
|
|
|
|
sqlite3_snprintf
|
|
|
|
sqlite3_test_control
|
|
|
|
sqlite3_vtab_config
|
|
|
|
}
|
|
|
|
|
2013-03-19 19:23:18 +04:00
|
|
|
# Process the source files.
|
2009-08-14 20:01:24 +04:00
|
|
|
#
|
2013-03-19 19:23:18 +04:00
|
|
|
foreach file $filelist {
|
2010-08-30 22:39:49 +04:00
|
|
|
set in [open $file]
|
2013-04-11 04:45:28 +04:00
|
|
|
if {![regexp {sqlite\.h\.in} $file]} {
|
2013-04-10 19:01:36 +04:00
|
|
|
puts "/******** Begin file [file tail $file] *********/"
|
|
|
|
}
|
2010-08-30 22:39:49 +04:00
|
|
|
while {![eof $in]} {
|
2016-08-24 22:58:46 +03:00
|
|
|
|
2020-06-23 20:57:08 +03:00
|
|
|
set line [string trimright [gets $in]]
|
2009-08-11 09:50:36 +04:00
|
|
|
|
2010-08-30 22:39:49 +04:00
|
|
|
# File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this
|
|
|
|
# line when copying sqlite3rtree.h into sqlite3.h.
|
|
|
|
#
|
2015-10-16 18:56:27 +03:00
|
|
|
if {[string match {*#include*[<"]sqlite3.h[>"]*} $line]} continue
|
2016-08-24 22:58:46 +03:00
|
|
|
|
2010-08-30 22:39:49 +04:00
|
|
|
regsub -- --VERS-- $line $zVersion line
|
|
|
|
regsub -- --VERSION-NUMBER-- $line $nVersion line
|
2017-08-22 22:19:00 +03:00
|
|
|
regsub -- --SOURCE-ID-- $line "$zSourceId" line
|
2015-03-25 00:54:42 +03:00
|
|
|
|
2015-03-25 00:27:27 +03:00
|
|
|
if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} {
|
2010-08-30 22:39:49 +04:00
|
|
|
set line "SQLITE_API $line"
|
2015-03-25 00:27:27 +03:00
|
|
|
} else {
|
2017-02-08 00:09:34 +03:00
|
|
|
if {[regexp $declpattern1 $line all rettype funcname rest] || \
|
|
|
|
[regexp $declpattern2 $line all rettype funcname rest] || \
|
2017-05-12 17:05:11 +03:00
|
|
|
[regexp $declpattern3 $line all rettype funcname rest] || \
|
2018-03-24 03:19:18 +03:00
|
|
|
[regexp $declpattern4 $line all rettype funcname rest] || \
|
|
|
|
[regexp $declpattern5 $line all rettype funcname rest]} {
|
2015-03-25 00:27:27 +03:00
|
|
|
set line SQLITE_API
|
|
|
|
append line " " [string trim $rettype]
|
|
|
|
if {[string index $rettype end] ne "*"} {
|
|
|
|
append line " "
|
|
|
|
}
|
2016-08-24 22:58:46 +03:00
|
|
|
if {$useapicall} {
|
|
|
|
if {[lsearch -exact $cdecllist $funcname] >= 0} {
|
2016-09-09 02:16:02 +03:00
|
|
|
append line SQLITE_CDECL " "
|
2016-08-24 22:58:46 +03:00
|
|
|
} else {
|
2016-09-09 02:16:02 +03:00
|
|
|
append line SQLITE_APICALL " "
|
2016-08-24 22:58:46 +03:00
|
|
|
}
|
2015-03-25 00:27:27 +03:00
|
|
|
}
|
2016-09-09 02:16:02 +03:00
|
|
|
append line $funcname $rest
|
2015-03-25 00:27:27 +03:00
|
|
|
}
|
2010-08-30 22:39:49 +04:00
|
|
|
}
|
2016-08-24 22:58:46 +03:00
|
|
|
if {$useapicall} {
|
|
|
|
set line [string map [list (*sqlite3_syscall_ptr) \
|
|
|
|
"(SQLITE_SYSAPI *sqlite3_syscall_ptr)"] $line]
|
|
|
|
regsub {\(\*} $line {(SQLITE_CALLBACK *} line
|
|
|
|
}
|
2009-08-11 09:50:36 +04:00
|
|
|
puts $line
|
|
|
|
}
|
2010-08-30 22:39:49 +04:00
|
|
|
close $in
|
2013-04-11 04:45:28 +04:00
|
|
|
if {![regexp {sqlite\.h\.in} $file]} {
|
2013-04-10 19:01:36 +04:00
|
|
|
puts "/******** End of [file tail $file] *********/"
|
|
|
|
}
|
2009-08-11 09:50:36 +04:00
|
|
|
}
|