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
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".
17 # After the "tsrc" directory has been created and populated, run
20 # tclsh mksqlite3c.tcl
22 # The amalgamated SQLite code will be written into sqlite3.c
25 set help
{Usage
: tclsh mksqlite3c.tcl
<options>
26 where
<options> is zero or more of the following with these effects
:
27 --nostatic => Do not generate with compile-time modifiable linkage.
28 --linemacros=?
=> Emit
#line directives into output or not. (? = 1 or 0)
29 --useapicall => Prepend functions with SQLITE_APICALL or SQLITE_CDECL.
30 --srcdir $SRC => Specify the directory containing constituent sources.
32 The value setting
options default to
--linemacros=1 and '
--srcdir tsrc' .
35 # Begin by reading the "sqlite3.h" header file. Extract the version number
36 # from in this file. The version number is needed to generate the header
37 # comment of the amalgamation.
46 for {set i
0} {$i<[llength $argv]} {incr i
} {
47 set x
[lindex $argv $i]
48 if {[regexp {^
-?
-enable-recover
$} $x]} {
50 } elseif
{[regexp {^
-?
-nostatic$} $x]} {
52 } elseif
{[regexp {^
-?
-linemacros(?
:=([01]))?
$} $x ma ulm
]} {
53 if {$ulm == ""} {set ulm
1}
55 } elseif
{[regexp {^
-?
-useapicall$} $x]} {
57 } elseif
{[regexp {^
-?
-srcdir$} $x]} {
59 if {$i==[llength $argv]} {
60 error "No argument following $x"
62 set srcdir
[lindex $argv $i]
63 } elseif
{[regexp {^
-?
-((help
)|
\?)$} $x]} {
67 error "unknown command-line option: $x"
70 set in
[open $srcdir/sqlite3.h
]
75 if {$line=="" && [eof $in]} break
77 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
81 # Open the output file and write a header comment at the beginning
85 if {$enable_recover} { set fname sqlite3r.c
}
86 set out
[open $fname w
]
87 # Force the output to use unix line endings, even on Windows.
88 fconfigure $out -translation lf
89 set today
[clock format [clock seconds
] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
91 {/******************************************************************************
92 ** This
file is an amalgamation of many separate C
source files from SQLite
93 ** version
$VERSION. By combining all the individual C code files into this
94 ** single large
file, the entire code can be compiled as a single translation
95 ** unit. This allows many compilers to do optimizations that would not be
96 ** possible
if the files were compiled separately. Performance improvements
97 ** of
5% or more are commonly seen when SQLite is compiled as a single
100 ** This
file is all you need to compile SQLite. To use SQLite in other
101 ** programs
, you need this
file and the
"sqlite3.h" header
file that defines
102 ** the programming interface to the SQLite library.
(If you do not have
103 ** the
"sqlite3.h" header
file at hand
, you will find a copy embedded within
104 ** the
text of this
file. Search
for "Begin file sqlite3.h" to find the start
105 ** of the embedded sqlite3.h header
file.
) Additional code files may be needed
106 ** if you want a wrapper to interface SQLite with your choice of programming
107 ** language. The code
for the
"sqlite3" command-line shell is also in a
108 ** separate
file. This
file contains only code
for the core SQLite library.
110 set srcroot
[file dirname
[file dirname
[info script
]]]
111 if {$tcl_platform(platform
)=="windows"} {
112 set vsrcprog src-verify.exe
114 set vsrcprog .
/src-verify
116 if {[file executable
$vsrcprog] && [file readable
$srcroot/manifest
]} {
117 set res
[string trim
[split [exec $vsrcprog -x $srcroot]] \n]
118 puts $out "** The content in this amalgamation comes from Fossil check-in"
119 puts -nonewline $out "** [string range [lindex $res 0] 0 35]"
120 if {[llength $res]==1} {
123 puts $out " with changes in files:\n**"
124 foreach f
[lrange $res 1 end
] {
129 puts $out "** The origin of the sources used to build this amalgamation"
130 puts $out "** is unknown."
133 #define SQLITE_CORE 1
134 #define SQLITE_AMALGAMATION 1}]
137 {#ifndef SQLITE_PRIVATE
138 # define SQLITE_PRIVATE static
142 # Examine the parse.c file. If it contains lines of the form:
144 # "#ifndef SQLITE_ENABLE_UPDATE_LIMIT
146 # then set the SQLITE_UDL_CAPABLE_PARSER flag in the amalgamation.
148 set in
[open $srcdir/parse.c
]
149 if {[regexp {ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
} [read $in]]} {
150 puts $out "#define SQLITE_UDL_CAPABLE_PARSER 1"
154 # These are the header files used by SQLite. The first time any of these
155 # files are seen in a #include statement in the C code, include the complete
156 # text of the file in-line. The file only needs to be included once.
195 set available_hdr
($hdr) 1
197 set available_hdr
(sqliteInt.h
) 0
198 set available_hdr
(os_common.h
) 0
199 set available_hdr
(sqlite3session.h
) 0
201 # These headers should be copied into the amalgamation without modifying any
202 # of their function declarations or definitions.
203 set varonly_hdr
(sqlite3.h
) 1
205 # These are the functions that accept a variable number of arguments. They
206 # always need to use the "cdecl" calling convention even when another calling
207 # convention (e.g. "stcall") is being used for the rest of the library.
218 # 78 stars used for comment formatting.
220 {*****************************************************************************}
222 # Insert a comment into the code
224 proc section_comment
{text} {
226 set n
[string length
$text]
227 set nstar
[expr {60 - $n}]
228 set stars
[string range
$s78 0 $nstar]
229 puts $out "/************** $text $stars/"
232 # Read the source file named $filename and write it into the
233 # sqlite3.c output file. If any #include statements are seen,
234 # process them appropriately.
236 proc copy_file
{filename} {
237 global seen_hdr available_hdr varonly_hdr cdecllist out
238 global addstatic linemacros useapicall srcdir
240 set tail
[file tail
$filename]
241 section_comment
"Begin file $tail"
242 if {$linemacros} {puts $out "#line 1 \"$filename\""}
243 set in
[open $filename r
]
244 set varpattern
{^
[a-zA-Z
][a-zA-Z_0-9
*]+(sqlite3
[_a-zA-Z0-9
]+)(\[|
;|
=)}
245 set declpattern
{([a-zA-Z
][a-zA-Z_0-9
]+ \**)(sqlite3
[_a-zA-Z0-9
]+)(\(.
*)}
246 if {[file extension
$filename]==".h"} {
247 set declpattern
" *$declpattern"
249 set declpattern ^
$declpattern\$
251 set line
[string trimright
[gets $in]]
253 if {[regexp {^
\s
*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
254 if {[info exists available_hdr
($hdr)]} {
255 if {$available_hdr($hdr)} {
256 set available_hdr
($hdr) 0
257 section_comment
"Include $hdr in the middle of $tail"
258 copy_file
$srcdir/$hdr
259 section_comment
"Continuing where we left off in $tail"
260 if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
262 # Comment out the entire line, replacing any nested comment
263 # begin/end markers with the harmless substring "**".
264 puts $out "/* [string map [list /* ** */ **] $line] */"
266 } elseif
{![info exists seen_hdr
($hdr)]} {
267 if {![regexp {/\*\s
+amalgamator
:\s
+dontcache
\s
+\*/} $line]} {
271 } elseif
{[regexp {/\*\s
+amalgamator
:\s
+keep
\s
+\*/} $line]} {
272 # This include file must be kept because there was a "keep"
273 # directive inside of a line comment.
276 # Comment out the entire line, replacing any nested comment
277 # begin/end markers with the harmless substring "**".
278 puts $out "/* [string map [list /* ** */ **] $line] */"
280 } elseif
{[regexp {^
#ifdef __cplusplus} $line]} {
282 } elseif
{!$linemacros && [regexp {^
#line} $line]} {
283 # Skip #line directives.
285 && ![regexp {^
(static|typedef|SQLITE_PRIVATE
)} $line]} {
286 # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before
287 # functions if this header file does not need it.
288 if {![info exists varonly_hdr
($tail)]
289 && [regexp $declpattern $line all rettype funcname rest
]} {
290 regsub {^SQLITE_API
} $line {} line
291 regsub {^SQLITE_API
} $rettype {} rettype
293 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions.
294 # so that linkage can be modified at compile-time.
295 if {[regexp {^sqlite3
[a-z
]*_
} $funcname]} {
297 append line
" " [string trim
$rettype]
298 if {[string index
$rettype end
] ne
"*"} {
302 if {[lsearch -exact $cdecllist $funcname] >= 0} {
303 append line SQLITE_CDECL
" "
305 append line SQLITE_APICALL
" "
308 append line
$funcname $rest
309 if {$funcname=="sqlite3_sourceid"} {
310 # The sqlite3_sourceid() routine is synthesized at the end of
312 puts $out "/* $line */"
317 puts $out "SQLITE_PRIVATE $line"
319 } elseif
{[regexp $varpattern $line all varname
]} {
320 # Add the SQLITE_PRIVATE before variable declarations or
321 # definitions for internal use
322 regsub {^SQLITE_API
} $line {} line
323 if {![regexp {^sqlite3_
} $varname]
324 && ![regexp {^sqlite3Show
[A-Z
]} $varname]} {
325 regsub {^extern
} $line {} line
326 puts $out "SQLITE_PRIVATE $line"
328 if {[regexp {const char sqlite3_version
\[\];} $line]} {
329 set line
{const char sqlite3_version
[] = SQLITE_VERSION
;}
331 regsub {^SQLITE_EXTERN
} $line {} line
332 puts $out "SQLITE_API $line"
334 } elseif
{[regexp {^
(SQLITE_EXTERN
)?void
\(\*sqlite3IoTrace
\)} $line]} {
335 regsub {^SQLITE_API
} $line {} line
336 regsub {^SQLITE_EXTERN
} $line {} line
338 } elseif
{[regexp {^void
\(\*sqlite3Os
} $line]} {
339 regsub {^SQLITE_API
} $line {} line
340 puts $out "SQLITE_PRIVATE $line"
349 section_comment
"End of $tail"
353 # Process the source files. Process files containing commonly
354 # used subroutines first in order to help the compiler find
355 # inlining opportunities.
474 if {$enable_recover} {
475 lappend flist sqlite3recover.c dbdata.c
477 foreach file $flist {
478 copy_file
$srcdir/$file
482 "/* Return the source-id for this library */
483 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }"
486 "/************************** End of sqlite3.c ******************************/"