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,
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.)
13 # After the "tsrc" directory has been created and populated, run
16 # tclsh mkfts3amal.tcl
18 # The amalgamated FTS3 code will be written into fts3amal.c
21 # Open the output file and write a header comment at the beginning
24 set out
[open fts3amal.c w
]
25 set today
[clock format [clock seconds
] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
27 {/******************************************************************************
28 ** This
file is an amalgamation of separate C
source files from the SQLite
29 ** Full Text Search extension
2 (fts3
). By combining all the individual C
30 ** code files into this single large
file, the entire code can be compiled
31 ** as a one translation unit. This allows many compilers to do optimizations
32 ** that would not be possible
if the files were compiled separately. It also
33 ** makes the code easier to import into other projects.
35 ** This amalgamation was generated on
$today.
38 # These are the header files used by FTS3. The first time any of these
39 # files are seen in a #include statement in the C code, include the complete
40 # text of the file in-line. The file only needs to be included once.
49 set available_hdr
($hdr) 1
52 # 78 stars used for comment formatting.
54 {*****************************************************************************}
56 # Insert a comment into the code
58 proc section_comment
{text} {
60 set n
[string length
$text]
61 set nstar
[expr {60 - $n}]
62 set stars
[string range
$s78 0 $nstar]
63 puts $out "/************** $text $stars/"
66 # Read the source file named $filename and write it into the
67 # sqlite3.c output file. If any #include statements are seen,
68 # process them approprately.
70 proc copy_file
{filename} {
71 global seen_hdr available_hdr out
72 set tail
[file tail
$filename]
73 section_comment
"Begin file $tail"
74 set in
[open $filename r
]
77 if {[regexp {^
#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
78 if {[info exists available_hdr
($hdr)]} {
79 if {$available_hdr($hdr)} {
80 section_comment
"Include $hdr in the middle of $tail"
82 section_comment
"Continuing where we left off in $tail"
84 } elseif
{![info exists seen_hdr
($hdr)]} {
88 } elseif
{[regexp {^
#ifdef __cplusplus} $line]} {
90 } elseif
{[regexp {^
#line} $line]} {
91 # Skip #line directives.
97 section_comment
"End of $tail"
101 # Process the source files. Process files containing commonly
102 # used subroutines first in order to help the compiler find
103 # inlining opportunities.