mksqlite3h.tcl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/tclsh
  2. #
  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. #
  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").
  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.
  24. #
  25. # This script outputs to stdout.
  26. #
  27. # Example usage:
  28. #
  29. # tclsh mksqlite3h.tcl ../sqlite >sqlite3.h
  30. #
  31. # Get the source tree root directory from the command-line
  32. #
  33. set TOP [lindex $argv 0]
  34. # Get the SQLite version number (ex: 3.6.18) from the $TOP/VERSION file.
  35. #
  36. set in [open $TOP/VERSION]
  37. set zVersion [string trim [read $in]]
  38. close $in
  39. set nVersion [eval format "%d%03d%03d" [split $zVersion .]]
  40. # Get the fossil-scm version number from $TOP/manifest.uuid.
  41. #
  42. set in [open $TOP/manifest.uuid]
  43. set zUuid [string trim [read $in]]
  44. close $in
  45. # Get the fossil-scm check-in date from the "D" card of $TOP/manifest.
  46. #
  47. set in [open $TOP/manifest]
  48. set zDate {}
  49. while {![eof $in]} {
  50. set line [gets $in]
  51. if {[regexp {^D (2[-0-9T:]+)} $line all date]} {
  52. set zDate [string map {T { }} $date]
  53. break
  54. }
  55. }
  56. close $in
  57. # Set up patterns for recognizing API declarations.
  58. #
  59. set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)}
  60. set declpattern {^ *[a-zA-Z][a-zA-Z_0-9 ]+ \**sqlite3_[_a-zA-Z0-9]+\(}
  61. # Force the output to use unix line endings, even on Windows.
  62. fconfigure stdout -translation lf
  63. set filelist [subst {
  64. $TOP/src/sqlite.h.in
  65. $TOP/ext/rtree/sqlite3rtree.h
  66. }]
  67. # Process the source files.
  68. #
  69. foreach file $filelist {
  70. set in [open $file]
  71. while {![eof $in]} {
  72. set line [gets $in]
  73. # File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this
  74. # line when copying sqlite3rtree.h into sqlite3.h.
  75. #
  76. if {[string match {*#include*<sqlite3.h>*} $line]} continue
  77. regsub -- --VERS-- $line $zVersion line
  78. regsub -- --VERSION-NUMBER-- $line $nVersion line
  79. regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line
  80. if {[regexp {define SQLITE_EXTERN extern} $line]} {
  81. puts $line
  82. puts [gets $in]
  83. puts ""
  84. puts "#ifndef SQLITE_API"
  85. puts "# define SQLITE_API"
  86. puts "#endif"
  87. set line ""
  88. }
  89. if {([regexp $varpattern $line] && ![regexp {^ *typedef} $line])
  90. || ([regexp $declpattern $line])
  91. } {
  92. set line "SQLITE_API $line"
  93. }
  94. puts $line
  95. }
  96. close $in
  97. }