mksqlite3internalh.tcl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. Count the number of lines
  25. # in this file and extract the version number. That information will be
  26. # needed in order to generate the header of the amalgamation.
  27. #
  28. set in [open tsrc/sqlite3.h]
  29. set cnt 0
  30. set VERSION ?????
  31. while {![eof $in]} {
  32. set line [gets $in]
  33. if {$line=="" && [eof $in]} break
  34. incr cnt
  35. regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
  36. }
  37. close $in
  38. # Open the output file and write a header comment at the beginning
  39. # of the file.
  40. #
  41. set out [open sqlite3internal.h w]
  42. set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
  43. puts $out [subst \
  44. {/******************************************************************************
  45. ** This file is an amalgamation of many private header files from SQLite
  46. ** version $VERSION.
  47. */}]
  48. # These are the header files used by SQLite. The first time any of these
  49. # files are seen in a #include statement in the C code, include the complete
  50. # text of the file in-line. The file only needs to be included once.
  51. #
  52. foreach hdr {
  53. btree.h
  54. btreeInt.h
  55. hash.h
  56. hwtime.h
  57. keywordhash.h
  58. msvc.h
  59. opcodes.h
  60. os_common.h
  61. os_setup.h
  62. os_win.h
  63. os.h
  64. pager.h
  65. parse.h
  66. sqlite3ext.h
  67. sqlite3.h
  68. sqliteInt.h
  69. sqliteLimit.h
  70. vdbe.h
  71. vdbeInt.h
  72. } {
  73. set available_hdr($hdr) 1
  74. }
  75. # 78 stars used for comment formatting.
  76. set s78 \
  77. {*****************************************************************************}
  78. # Insert a comment into the code
  79. #
  80. proc section_comment {text} {
  81. global out s78
  82. set n [string length $text]
  83. set nstar [expr {60 - $n}]
  84. set stars [string range $s78 0 $nstar]
  85. puts $out "/************** $text $stars/"
  86. }
  87. # Read the source file named $filename and write it into the
  88. # sqlite3.c output file. If any #include statements are seen,
  89. # process them approprately.
  90. #
  91. proc copy_file {filename} {
  92. global seen_hdr available_hdr out
  93. set tail [file tail $filename]
  94. section_comment "Begin file $tail"
  95. set in [open $filename r]
  96. while {![eof $in]} {
  97. set line [gets $in]
  98. if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
  99. if {[info exists available_hdr($hdr)]} {
  100. if {$available_hdr($hdr)} {
  101. section_comment "Include $hdr in the middle of $tail"
  102. copy_file tsrc/$hdr
  103. section_comment "Continuing where we left off in $tail"
  104. }
  105. } elseif {![info exists seen_hdr($hdr)]} {
  106. set seen_hdr($hdr) 1
  107. puts $out $line
  108. }
  109. } elseif {[regexp {^#ifdef __cplusplus} $line]} {
  110. puts $out "#if 0"
  111. } elseif {[regexp {^#line} $line]} {
  112. # Skip #line directives.
  113. } else {
  114. puts $out $line
  115. }
  116. }
  117. close $in
  118. section_comment "End of $tail"
  119. }
  120. # Process the source files. Process files containing commonly
  121. # used subroutines first in order to help the compiler find
  122. # inlining opportunities.
  123. #
  124. foreach file {
  125. sqliteInt.h
  126. sqlite3.h
  127. btree.h
  128. hash.h
  129. os.h
  130. pager.h
  131. parse.h
  132. sqlite3ext.h
  133. vdbe.h
  134. } {
  135. if {$available_hdr($file)} {
  136. copy_file tsrc/$file
  137. }
  138. }
  139. close $out