mksqlite3internalh.tcl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. opcodes.h
  59. os_common.h
  60. os.h
  61. pager.h
  62. parse.h
  63. sqlite3ext.h
  64. sqlite3.h
  65. sqliteInt.h
  66. sqliteLimit.h
  67. vdbe.h
  68. vdbeInt.h
  69. } {
  70. set available_hdr($hdr) 1
  71. }
  72. # 78 stars used for comment formatting.
  73. set s78 \
  74. {*****************************************************************************}
  75. # Insert a comment into the code
  76. #
  77. proc section_comment {text} {
  78. global out s78
  79. set n [string length $text]
  80. set nstar [expr {60 - $n}]
  81. set stars [string range $s78 0 $nstar]
  82. puts $out "/************** $text $stars/"
  83. }
  84. # Read the source file named $filename and write it into the
  85. # sqlite3.c output file. If any #include statements are seen,
  86. # process them approprately.
  87. #
  88. proc copy_file {filename} {
  89. global seen_hdr available_hdr out
  90. set tail [file tail $filename]
  91. section_comment "Begin file $tail"
  92. set in [open $filename r]
  93. while {![eof $in]} {
  94. set line [gets $in]
  95. if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
  96. if {[info exists available_hdr($hdr)]} {
  97. if {$available_hdr($hdr)} {
  98. section_comment "Include $hdr in the middle of $tail"
  99. copy_file tsrc/$hdr
  100. section_comment "Continuing where we left off in $tail"
  101. }
  102. } elseif {![info exists seen_hdr($hdr)]} {
  103. set seen_hdr($hdr) 1
  104. puts $out $line
  105. }
  106. } elseif {[regexp {^#ifdef __cplusplus} $line]} {
  107. puts $out "#if 0"
  108. } elseif {[regexp {^#line} $line]} {
  109. # Skip #line directives.
  110. } else {
  111. puts $out $line
  112. }
  113. }
  114. close $in
  115. section_comment "End of $tail"
  116. }
  117. # Process the source files. Process files containing commonly
  118. # used subroutines first in order to help the compiler find
  119. # inlining opportunities.
  120. #
  121. foreach file {
  122. sqliteInt.h
  123. sqlite3.h
  124. btree.h
  125. hash.h
  126. os.h
  127. pager.h
  128. parse.h
  129. sqlite3ext.h
  130. vdbe.h
  131. } {
  132. if {$available_hdr($file)} {
  133. copy_file tsrc/$file
  134. }
  135. }
  136. close $out