mksqlite3c-noext.tcl 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #!/usr/bin/tclsh
  2. #
  3. # To build a single huge source file holding all of SQLite (or at
  4. # least the core components - the test harness, shell, and TCL
  5. # interface are omitted.) first do
  6. #
  7. # make target_source
  8. #
  9. # The make target above moves all of the source code files into
  10. # a subdirectory named "tsrc". (This script expects to find the files
  11. # there and will not work if they are not found.) There are a few
  12. # generated C code files that are also added to the tsrc directory.
  13. # For example, the "parse.c" and "parse.h" files to implement the
  14. # the parser are derived from "parse.y" using lemon. And the
  15. # "keywordhash.h" files is generated by a program named "mkkeywordhash".
  16. #
  17. # After the "tsrc" directory has been created and populated, run
  18. # this script:
  19. #
  20. # tclsh mksqlite3c.tcl
  21. #
  22. # The amalgamated SQLite code will be written into sqlite3.c
  23. #
  24. # Begin by reading the "sqlite3.h" header file. Extract the version number
  25. # from in this file. The versioon number is needed to generate the header
  26. # comment of the amalgamation.
  27. #
  28. if {[lsearch $argv --nostatic]>=0} {
  29. set addstatic 0
  30. } else {
  31. set addstatic 1
  32. }
  33. if {[lsearch $argv --linemacros]>=0} {
  34. set linemacros 1
  35. } else {
  36. set linemacros 0
  37. }
  38. set in [open tsrc/sqlite3.h]
  39. set cnt 0
  40. set VERSION ?????
  41. while {![eof $in]} {
  42. set line [gets $in]
  43. if {$line=="" && [eof $in]} break
  44. incr cnt
  45. regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
  46. }
  47. close $in
  48. # Open the output file and write a header comment at the beginning
  49. # of the file.
  50. #
  51. set out [open sqlite3.c w]
  52. # Force the output to use unix line endings, even on Windows.
  53. fconfigure $out -translation lf
  54. set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
  55. puts $out [subst \
  56. {/******************************************************************************
  57. ** This file is an amalgamation of many separate C source files from SQLite
  58. ** version $VERSION. By combining all the individual C code files into this
  59. ** single large file, the entire code can be compiled as a single translation
  60. ** unit. This allows many compilers to do optimizations that would not be
  61. ** possible if the files were compiled separately. Performance improvements
  62. ** of 5% or more are commonly seen when SQLite is compiled as a single
  63. ** translation unit.
  64. **
  65. ** This file is all you need to compile SQLite. To use SQLite in other
  66. ** programs, you need this file and the "sqlite3.h" header file that defines
  67. ** the programming interface to the SQLite library. (If you do not have
  68. ** the "sqlite3.h" header file at hand, you will find a copy embedded within
  69. ** the text of this file. Search for "Begin file sqlite3.h" to find the start
  70. ** of the embedded sqlite3.h header file.) Additional code files may be needed
  71. ** if you want a wrapper to interface SQLite with your choice of programming
  72. ** language. The code for the "sqlite3" command-line shell is also in a
  73. ** separate file. This file contains only code for the core SQLite library.
  74. */
  75. #define SQLITE_CORE 1
  76. #define SQLITE_AMALGAMATION 1}]
  77. if {$addstatic} {
  78. puts $out \
  79. {#ifndef SQLITE_PRIVATE
  80. # define SQLITE_PRIVATE static
  81. #endif
  82. #ifndef SQLITE_API
  83. # define SQLITE_API
  84. #endif}
  85. }
  86. # These are the header files used by SQLite. The first time any of these
  87. # files are seen in a #include statement in the C code, include the complete
  88. # text of the file in-line. The file only needs to be included once.
  89. #
  90. foreach hdr {
  91. btree.h
  92. btreeInt.h
  93. hash.h
  94. hwtime.h
  95. keywordhash.h
  96. mutex.h
  97. opcodes.h
  98. os_common.h
  99. os.h
  100. pager.h
  101. parse.h
  102. pcache.h
  103. sqlite3ext.h
  104. sqlite3.h
  105. sqliteicu.h
  106. sqliteInt.h
  107. sqliteLimit.h
  108. vdbe.h
  109. vdbeInt.h
  110. wal.h
  111. } {
  112. set available_hdr($hdr) 1
  113. }
  114. set available_hdr(sqliteInt.h) 0
  115. # 78 stars used for comment formatting.
  116. set s78 \
  117. {*****************************************************************************}
  118. # Insert a comment into the code
  119. #
  120. proc section_comment {text} {
  121. global out s78
  122. set n [string length $text]
  123. set nstar [expr {60 - $n}]
  124. set stars [string range $s78 0 $nstar]
  125. puts $out "/************** $text $stars/"
  126. }
  127. # Read the source file named $filename and write it into the
  128. # sqlite3.c output file. If any #include statements are seen,
  129. # process them approprately.
  130. #
  131. proc copy_file {filename} {
  132. global seen_hdr available_hdr out addstatic linemacros
  133. set ln 0
  134. set tail [file tail $filename]
  135. section_comment "Begin file $tail"
  136. if {$linemacros} {puts $out "#line 1 \"$filename\""}
  137. set in [open $filename r]
  138. set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)}
  139. set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(}
  140. if {[file extension $filename]==".h"} {
  141. set declpattern " *$declpattern"
  142. }
  143. set declpattern ^$declpattern
  144. while {![eof $in]} {
  145. set line [gets $in]
  146. incr ln
  147. if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
  148. if {[info exists available_hdr($hdr)]} {
  149. if {$available_hdr($hdr)} {
  150. if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
  151. set available_hdr($hdr) 0
  152. }
  153. section_comment "Include $hdr in the middle of $tail"
  154. copy_file tsrc/$hdr
  155. section_comment "Continuing where we left off in $tail"
  156. if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
  157. }
  158. } elseif {![info exists seen_hdr($hdr)]} {
  159. set seen_hdr($hdr) 1
  160. puts $out $line
  161. } else {
  162. puts $out "/* $line */"
  163. }
  164. } elseif {[regexp {^#ifdef __cplusplus} $line]} {
  165. puts $out "#if 0"
  166. } elseif {!$linemacros && [regexp {^#line} $line]} {
  167. # Skip #line directives.
  168. } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} {
  169. regsub {^SQLITE_API } $line {} line
  170. if {[regexp $declpattern $line all funcname]} {
  171. # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions.
  172. # so that linkage can be modified at compile-time.
  173. if {[regexp {^sqlite3_} $funcname]} {
  174. puts $out "SQLITE_API $line"
  175. } else {
  176. puts $out "SQLITE_PRIVATE $line"
  177. }
  178. } elseif {[regexp $varpattern $line all varname]} {
  179. # Add the SQLITE_PRIVATE before variable declarations or
  180. # definitions for internal use
  181. if {![regexp {^sqlite3_} $varname]} {
  182. regsub {^extern } $line {} line
  183. puts $out "SQLITE_PRIVATE $line"
  184. } else {
  185. if {[regexp {const char sqlite3_version\[\];} $line]} {
  186. set line {const char sqlite3_version[] = SQLITE_VERSION;}
  187. }
  188. regsub {^SQLITE_EXTERN } $line {} line
  189. puts $out "SQLITE_API $line"
  190. }
  191. } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
  192. regsub {^SQLITE_EXTERN } $line {} line
  193. puts $out "SQLITE_PRIVATE $line"
  194. } elseif {[regexp {^void \(\*sqlite3Os} $line]} {
  195. puts $out "SQLITE_PRIVATE $line"
  196. } else {
  197. puts $out $line
  198. }
  199. } else {
  200. puts $out $line
  201. }
  202. }
  203. close $in
  204. section_comment "End of $tail"
  205. }
  206. # Process the source files. Process files containing commonly
  207. # used subroutines first in order to help the compiler find
  208. # inlining opportunities.
  209. #
  210. foreach file {
  211. sqliteInt.h
  212. global.c
  213. ctime.c
  214. status.c
  215. date.c
  216. os.c
  217. fault.c
  218. mem0.c
  219. mem1.c
  220. mem2.c
  221. mem3.c
  222. mem5.c
  223. mutex.c
  224. mutex_noop.c
  225. mutex_unix.c
  226. mutex_w32.c
  227. malloc.c
  228. printf.c
  229. random.c
  230. utf.c
  231. util.c
  232. hash.c
  233. opcodes.c
  234. os_unix.c
  235. os_win.c
  236. bitvec.c
  237. pcache.c
  238. pcache1.c
  239. rowset.c
  240. pager.c
  241. wal.c
  242. btmutex.c
  243. btree.c
  244. backup.c
  245. vdbemem.c
  246. vdbeaux.c
  247. vdbeapi.c
  248. vdbetrace.c
  249. vdbe.c
  250. vdbeblob.c
  251. vdbesort.c
  252. journal.c
  253. memjournal.c
  254. walker.c
  255. resolve.c
  256. expr.c
  257. alter.c
  258. analyze.c
  259. attach.c
  260. auth.c
  261. build.c
  262. callback.c
  263. delete.c
  264. func.c
  265. fkey.c
  266. insert.c
  267. legacy.c
  268. loadext.c
  269. pragma.c
  270. prepare.c
  271. select.c
  272. table.c
  273. trigger.c
  274. update.c
  275. vacuum.c
  276. vtab.c
  277. where.c
  278. parse.c
  279. tokenize.c
  280. complete.c
  281. main.c
  282. notify.c
  283. } {
  284. copy_file tsrc/$file
  285. }
  286. close $out