mkfts3amal.tcl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/tclsh
  2. #
  3. # This script builds a single C code file holding all of FTS3 code.
  4. # The name of the output file is fts3amal.c. To build this file,
  5. # 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.)
  12. #
  13. # After the "tsrc" directory has been created and populated, run
  14. # this script:
  15. #
  16. # tclsh mkfts3amal.tcl
  17. #
  18. # The amalgamated FTS3 code will be written into fts3amal.c
  19. #
  20. # Open the output file and write a header comment at the beginning
  21. # of the file.
  22. #
  23. set out [open fts3amal.c w]
  24. set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
  25. puts $out [subst \
  26. {/******************************************************************************
  27. ** This file is an amalgamation of separate C source files from the SQLite
  28. ** Full Text Search extension 2 (fts3). By combining all the individual C
  29. ** code files into this single large file, the entire code can be compiled
  30. ** as a one translation unit. This allows many compilers to do optimizations
  31. ** that would not be possible if the files were compiled separately. It also
  32. ** makes the code easier to import into other projects.
  33. **
  34. ** This amalgamation was generated on $today.
  35. */}]
  36. # These are the header files used by FTS3. The first time any of these
  37. # files are seen in a #include statement in the C code, include the complete
  38. # text of the file in-line. The file only needs to be included once.
  39. #
  40. foreach hdr {
  41. fts3.h
  42. fts3_hash.h
  43. fts3_tokenizer.h
  44. sqlite3.h
  45. sqlite3ext.h
  46. } {
  47. set available_hdr($hdr) 1
  48. }
  49. # 78 stars used for comment formatting.
  50. set s78 \
  51. {*****************************************************************************}
  52. # Insert a comment into the code
  53. #
  54. proc section_comment {text} {
  55. global out s78
  56. set n [string length $text]
  57. set nstar [expr {60 - $n}]
  58. set stars [string range $s78 0 $nstar]
  59. puts $out "/************** $text $stars/"
  60. }
  61. # Read the source file named $filename and write it into the
  62. # sqlite3.c output file. If any #include statements are seen,
  63. # process them approprately.
  64. #
  65. proc copy_file {filename} {
  66. global seen_hdr available_hdr out
  67. set tail [file tail $filename]
  68. section_comment "Begin file $tail"
  69. set in [open $filename r]
  70. while {![eof $in]} {
  71. set line [gets $in]
  72. if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
  73. if {[info exists available_hdr($hdr)]} {
  74. if {$available_hdr($hdr)} {
  75. section_comment "Include $hdr in the middle of $tail"
  76. copy_file tsrc/$hdr
  77. section_comment "Continuing where we left off in $tail"
  78. }
  79. } elseif {![info exists seen_hdr($hdr)]} {
  80. set seen_hdr($hdr) 1
  81. puts $out $line
  82. }
  83. } elseif {[regexp {^#ifdef __cplusplus} $line]} {
  84. puts $out "#if 0"
  85. } elseif {[regexp {^#line} $line]} {
  86. # Skip #line directives.
  87. } else {
  88. puts $out $line
  89. }
  90. }
  91. close $in
  92. section_comment "End of $tail"
  93. }
  94. # Process the source files. Process files containing commonly
  95. # used subroutines first in order to help the compiler find
  96. # inlining opportunities.
  97. #
  98. foreach file {
  99. fts3.c
  100. fts3_hash.c
  101. fts3_porter.c
  102. fts3_tokenizer.c
  103. fts3_tokenizer1.c
  104. } {
  105. copy_file tsrc/$file
  106. }
  107. close $out