blob: a89b9f9beb0df39ff4123108212e1072786b763f [file] [log] [blame]
danielk19772d04deb2009-08-11 05:50:36 +00001#!/usr/bin/tclsh
2#
drh47baebc2009-08-14 16:01:24 +00003# 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#
danielk19772d04deb2009-08-11 05:50:36 +000014# 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").
drh47baebc2009-08-14 16:01:24 +000022# 5) Replaces the string --SOURCE-ID-- with the date and time and sha1
23# hash of the fossil-scm manifest for the source tree.
danielk19772d04deb2009-08-11 05:50:36 +000024#
drh47baebc2009-08-14 16:01:24 +000025# This script outputs to stdout.
danielk19772d04deb2009-08-11 05:50:36 +000026#
drh47baebc2009-08-14 16:01:24 +000027# Example usage:
28#
29# tclsh mksqlite3h.tcl ../sqlite >sqlite3.h
danielk19772d04deb2009-08-11 05:50:36 +000030#
31
drh47baebc2009-08-14 16:01:24 +000032
33# Get the source tree root directory from the command-line
34#
35set TOP [lindex $argv 0]
36
37# Get the SQLite version number (ex: 3.6.18) from the $TOP/VERSION file.
38#
39set in [open $TOP/VERSION]
40set zVersion [string trim [read $in]]
41close $in
danielk19772d04deb2009-08-11 05:50:36 +000042set nVersion [eval format "%d%03d%03d" [split $zVersion .]]
43
drh47baebc2009-08-14 16:01:24 +000044# Get the fossil-scm version number from $TOP/manifest.uuid.
45#
46set in [open $TOP/manifest.uuid]
47set zUuid [string trim [read $in]]
48close $in
danielk19772d04deb2009-08-11 05:50:36 +000049
drh47baebc2009-08-14 16:01:24 +000050# Get the fossil-scm check-in date from the "D" card of $TOP/manifest.
51#
52set in [open $TOP/manifest]
53set zDate {}
54while {![eof $in]} {
55 set line [gets $in]
drhbbd91942011-01-11 12:46:05 +000056 if {[regexp {^D (2[-0-9T:]+)} $line all date]} {
drh47baebc2009-08-14 16:01:24 +000057 set zDate [string map {T { }} $date]
58 break
59 }
60}
61close $in
62
63# Set up patterns for recognizing API declarations.
64#
65set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)}
66set declpattern {^ *[a-zA-Z][a-zA-Z_0-9 ]+ \**sqlite3_[_a-zA-Z0-9]+\(}
67
shaneh5e0fb2c2011-06-17 15:54:59 +000068# Force the output to use unix line endings, even on Windows.
69fconfigure stdout -translation lf
70
drh339d6c62013-03-19 16:12:40 +000071set filelist [subst {
72 $TOP/src/sqlite.h.in
73 $TOP/ext/rtree/sqlite3rtree.h
74}]
75
76# Process the source files.
drh47baebc2009-08-14 16:01:24 +000077#
drh339d6c62013-03-19 16:12:40 +000078foreach file $filelist {
danc223b8f2010-08-30 18:39:49 +000079 set in [open $file]
80 while {![eof $in]} {
81
82 set line [gets $in]
drh47baebc2009-08-14 16:01:24 +000083
danc223b8f2010-08-30 18:39:49 +000084 # File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this
85 # line when copying sqlite3rtree.h into sqlite3.h.
86 #
87 if {[string match {*#include*<sqlite3.h>*} $line]} continue
88
89 regsub -- --VERS-- $line $zVersion line
90 regsub -- --VERSION-NUMBER-- $line $nVersion line
91 regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line
92
93 if {[regexp {define SQLITE_EXTERN extern} $line]} {
94 puts $line
95 puts [gets $in]
96 puts ""
97 puts "#ifndef SQLITE_API"
98 puts "# define SQLITE_API"
99 puts "#endif"
100 set line ""
101 }
102
103 if {([regexp $varpattern $line] && ![regexp {^ *typedef} $line])
104 || ([regexp $declpattern $line])
105 } {
106 set line "SQLITE_API $line"
107 }
danielk19772d04deb2009-08-11 05:50:36 +0000108 puts $line
danielk19772d04deb2009-08-11 05:50:36 +0000109 }
danc223b8f2010-08-30 18:39:49 +0000110 close $in
danielk19772d04deb2009-08-11 05:50:36 +0000111}