2011-09-17 19:29:20 +02:00
|
|
|
#!/usr/bin/tclsh
|
|
|
|
#
|
|
|
|
# To build a single huge source file holding all of SQLite (or at
|
2016-08-24 21:58:46 +02:00
|
|
|
# least the core components - the test harness, shell, and TCL
|
2011-09-17 19:29:20 +02:00
|
|
|
# interface are omitted.) first do
|
|
|
|
#
|
|
|
|
# make target_source
|
|
|
|
#
|
|
|
|
# The make target above moves all of the source code files into
|
|
|
|
# a subdirectory named "tsrc". (This script expects to find the files
|
|
|
|
# there and will not work if they are not found.) There are a few
|
|
|
|
# generated C code files that are also added to the tsrc directory.
|
|
|
|
# For example, the "parse.c" and "parse.h" files to implement the
|
2016-08-24 21:58:46 +02:00
|
|
|
# the parser are derived from "parse.y" using lemon. And the
|
2011-09-17 19:29:20 +02:00
|
|
|
# "keywordhash.h" files is generated by a program named "mkkeywordhash".
|
|
|
|
#
|
|
|
|
# After the "tsrc" directory has been created and populated, run
|
|
|
|
# this script:
|
|
|
|
#
|
2015-03-24 22:34:53 +01:00
|
|
|
# tclsh mksqlite3c-noext.tcl
|
2011-09-17 19:29:20 +02:00
|
|
|
#
|
|
|
|
# The amalgamated SQLite code will be written into sqlite3.c
|
|
|
|
#
|
|
|
|
|
|
|
|
# Begin by reading the "sqlite3.h" header file. Extract the version number
|
2015-03-24 22:34:53 +01:00
|
|
|
# from in this file. The version number is needed to generate the header
|
2011-09-17 19:29:20 +02:00
|
|
|
# comment of the amalgamation.
|
|
|
|
#
|
2016-08-24 21:58:46 +02:00
|
|
|
set addstatic 1
|
|
|
|
set linemacros 0
|
|
|
|
set useapicall 0
|
|
|
|
for {set i 0} {$i<[llength $argv]} {incr i} {
|
|
|
|
set x [lindex $argv $i]
|
|
|
|
if {[regexp {^-+nostatic$} $x]} {
|
|
|
|
set addstatic 0
|
|
|
|
} elseif {[regexp {^-+linemacros} $x]} {
|
|
|
|
set linemacros 1
|
|
|
|
} elseif {[regexp {^-+useapicall} $x]} {
|
|
|
|
set useapicall 1
|
|
|
|
} else {
|
|
|
|
error "unknown command-line option: $x"
|
|
|
|
}
|
2011-09-17 19:29:20 +02:00
|
|
|
}
|
|
|
|
set in [open tsrc/sqlite3.h]
|
|
|
|
set cnt 0
|
|
|
|
set VERSION ?????
|
|
|
|
while {![eof $in]} {
|
|
|
|
set line [gets $in]
|
|
|
|
if {$line=="" && [eof $in]} break
|
|
|
|
incr cnt
|
|
|
|
regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
|
|
|
|
}
|
|
|
|
close $in
|
|
|
|
|
|
|
|
# Open the output file and write a header comment at the beginning
|
|
|
|
# of the file.
|
|
|
|
#
|
|
|
|
set out [open sqlite3.c w]
|
|
|
|
# Force the output to use unix line endings, even on Windows.
|
|
|
|
fconfigure $out -translation lf
|
|
|
|
set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
|
|
|
|
puts $out [subst \
|
|
|
|
{/******************************************************************************
|
|
|
|
** This file is an amalgamation of many separate C source files from SQLite
|
2016-08-24 21:58:46 +02:00
|
|
|
** version $VERSION. By combining all the individual C code files into this
|
2011-09-17 19:29:20 +02:00
|
|
|
** single large file, the entire code can be compiled as a single translation
|
|
|
|
** unit. This allows many compilers to do optimizations that would not be
|
|
|
|
** possible if the files were compiled separately. Performance improvements
|
|
|
|
** of 5% or more are commonly seen when SQLite is compiled as a single
|
|
|
|
** translation unit.
|
|
|
|
**
|
|
|
|
** This file is all you need to compile SQLite. To use SQLite in other
|
|
|
|
** programs, you need this file and the "sqlite3.h" header file that defines
|
2016-08-24 21:58:46 +02:00
|
|
|
** the programming interface to the SQLite library. (If you do not have
|
2011-09-17 19:29:20 +02:00
|
|
|
** the "sqlite3.h" header file at hand, you will find a copy embedded within
|
|
|
|
** the text of this file. Search for "Begin file sqlite3.h" to find the start
|
|
|
|
** of the embedded sqlite3.h header file.) Additional code files may be needed
|
|
|
|
** if you want a wrapper to interface SQLite with your choice of programming
|
|
|
|
** language. The code for the "sqlite3" command-line shell is also in a
|
|
|
|
** separate file. This file contains only code for the core SQLite library.
|
|
|
|
*/
|
|
|
|
#define SQLITE_CORE 1
|
|
|
|
#define SQLITE_AMALGAMATION 1}]
|
|
|
|
if {$addstatic} {
|
|
|
|
puts $out \
|
|
|
|
{#ifndef SQLITE_PRIVATE
|
|
|
|
# define SQLITE_PRIVATE static
|
|
|
|
#endif}
|
|
|
|
}
|
|
|
|
|
2016-08-24 21:58:46 +02:00
|
|
|
# These are the header files used by SQLite. The first time any of these
|
2011-09-17 19:29:20 +02:00
|
|
|
# files are seen in a #include statement in the C code, include the complete
|
|
|
|
# text of the file in-line. The file only needs to be included once.
|
|
|
|
#
|
|
|
|
foreach hdr {
|
|
|
|
btree.h
|
|
|
|
btreeInt.h
|
|
|
|
hash.h
|
|
|
|
hwtime.h
|
|
|
|
keywordhash.h
|
2015-01-12 19:02:52 +01:00
|
|
|
msvc.h
|
2011-09-17 19:29:20 +02:00
|
|
|
mutex.h
|
|
|
|
opcodes.h
|
|
|
|
os_common.h
|
2013-11-26 02:00:31 +01:00
|
|
|
os_setup.h
|
2013-11-25 10:36:07 +01:00
|
|
|
os_win.h
|
2011-09-17 19:29:20 +02:00
|
|
|
os.h
|
|
|
|
pager.h
|
|
|
|
parse.h
|
|
|
|
pcache.h
|
2015-03-24 22:52:12 +01:00
|
|
|
pragma.h
|
2011-09-17 19:29:20 +02:00
|
|
|
sqlite3.h
|
2016-08-24 21:58:46 +02:00
|
|
|
sqlite3ext.h
|
2011-09-17 19:29:20 +02:00
|
|
|
sqliteicu.h
|
|
|
|
sqliteInt.h
|
|
|
|
sqliteLimit.h
|
|
|
|
vdbe.h
|
|
|
|
vdbeInt.h
|
2015-03-24 22:52:12 +01:00
|
|
|
vxworks.h
|
2011-09-17 19:29:20 +02:00
|
|
|
wal.h
|
2015-03-24 22:52:12 +01:00
|
|
|
whereInt.h
|
2011-09-17 19:29:20 +02:00
|
|
|
} {
|
|
|
|
set available_hdr($hdr) 1
|
|
|
|
}
|
|
|
|
set available_hdr(sqliteInt.h) 0
|
|
|
|
|
2015-03-24 22:52:12 +01:00
|
|
|
# These headers should be copied into the amalgamation without modifying any
|
|
|
|
# of their function declarations or definitions.
|
|
|
|
set varonly_hdr(sqlite3.h) 1
|
|
|
|
|
|
|
|
# These are the functions that accept a variable number of arguments. They
|
|
|
|
# always need to use the "cdecl" calling convention even when another calling
|
|
|
|
# convention (e.g. "stcall") is being used for the rest of the library.
|
|
|
|
set cdecllist {
|
|
|
|
sqlite3_config
|
|
|
|
sqlite3_db_config
|
|
|
|
sqlite3_log
|
|
|
|
sqlite3_mprintf
|
|
|
|
sqlite3_snprintf
|
|
|
|
sqlite3_test_control
|
|
|
|
sqlite3_vtab_config
|
|
|
|
}
|
|
|
|
|
2011-09-17 19:29:20 +02:00
|
|
|
# 78 stars used for comment formatting.
|
|
|
|
set s78 \
|
|
|
|
{*****************************************************************************}
|
|
|
|
|
|
|
|
# Insert a comment into the code
|
|
|
|
#
|
|
|
|
proc section_comment {text} {
|
|
|
|
global out s78
|
|
|
|
set n [string length $text]
|
|
|
|
set nstar [expr {60 - $n}]
|
|
|
|
set stars [string range $s78 0 $nstar]
|
|
|
|
puts $out "/************** $text $stars/"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Read the source file named $filename and write it into the
|
|
|
|
# sqlite3.c output file. If any #include statements are seen,
|
2015-03-24 22:52:12 +01:00
|
|
|
# process them appropriately.
|
2011-09-17 19:29:20 +02:00
|
|
|
#
|
|
|
|
proc copy_file {filename} {
|
2016-08-24 21:58:46 +02:00
|
|
|
global seen_hdr available_hdr varonly_hdr cdecllist out
|
|
|
|
global addstatic linemacros useapicall
|
2011-09-17 19:29:20 +02:00
|
|
|
set ln 0
|
|
|
|
set tail [file tail $filename]
|
|
|
|
section_comment "Begin file $tail"
|
|
|
|
if {$linemacros} {puts $out "#line 1 \"$filename\""}
|
|
|
|
set in [open $filename r]
|
|
|
|
set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)}
|
2015-03-24 22:52:12 +01:00
|
|
|
set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)}
|
2011-09-17 19:29:20 +02:00
|
|
|
if {[file extension $filename]==".h"} {
|
|
|
|
set declpattern " *$declpattern"
|
|
|
|
}
|
2015-03-24 22:52:12 +01:00
|
|
|
set declpattern ^$declpattern\$
|
2011-09-17 19:29:20 +02:00
|
|
|
while {![eof $in]} {
|
|
|
|
set line [gets $in]
|
|
|
|
incr ln
|
|
|
|
if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
|
|
|
|
if {[info exists available_hdr($hdr)]} {
|
|
|
|
if {$available_hdr($hdr)} {
|
|
|
|
if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
|
|
|
|
set available_hdr($hdr) 0
|
|
|
|
}
|
|
|
|
section_comment "Include $hdr in the middle of $tail"
|
|
|
|
copy_file tsrc/$hdr
|
|
|
|
section_comment "Continuing where we left off in $tail"
|
|
|
|
if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
|
2015-07-15 23:00:33 +02:00
|
|
|
} else {
|
|
|
|
# Comment out the entire line, replacing any nested comment
|
|
|
|
# begin/end markers with the harmless substring "**".
|
|
|
|
puts $out "/* [string map [list /* ** */ **] $line] */"
|
2011-09-17 19:29:20 +02:00
|
|
|
}
|
|
|
|
} elseif {![info exists seen_hdr($hdr)]} {
|
2015-03-24 22:52:12 +01:00
|
|
|
if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} {
|
|
|
|
set seen_hdr($hdr) 1
|
|
|
|
}
|
|
|
|
puts $out $line
|
|
|
|
} elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} {
|
|
|
|
# This include file must be kept because there was a "keep"
|
|
|
|
# directive inside of a line comment.
|
2011-09-17 19:29:20 +02:00
|
|
|
puts $out $line
|
|
|
|
} else {
|
2015-03-24 22:52:12 +01:00
|
|
|
# Comment out the entire line, replacing any nested comment
|
|
|
|
# begin/end markers with the harmless substring "**".
|
|
|
|
puts $out "/* [string map [list /* ** */ **] $line] */"
|
2011-09-17 19:29:20 +02:00
|
|
|
}
|
|
|
|
} elseif {[regexp {^#ifdef __cplusplus} $line]} {
|
|
|
|
puts $out "#if 0"
|
|
|
|
} elseif {!$linemacros && [regexp {^#line} $line]} {
|
|
|
|
# Skip #line directives.
|
2016-08-24 21:58:46 +02:00
|
|
|
} elseif {$addstatic
|
|
|
|
&& ![regexp {^(static|typedef|SQLITE_PRIVATE)} $line]} {
|
2015-03-24 22:52:12 +01:00
|
|
|
# Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before
|
|
|
|
# functions if this header file does not need it.
|
|
|
|
if {![info exists varonly_hdr($tail)]
|
|
|
|
&& [regexp $declpattern $line all rettype funcname rest]} {
|
|
|
|
regsub {^SQLITE_API } $line {} line
|
2011-09-17 19:29:20 +02:00
|
|
|
# Add the SQLITE_PRIVATE or SQLITE_API keyword before functions.
|
|
|
|
# so that linkage can be modified at compile-time.
|
2016-08-24 21:58:46 +02:00
|
|
|
if {[regexp {^sqlite3[a-z]*_} $funcname]} {
|
2015-03-24 22:52:12 +01:00
|
|
|
set line SQLITE_API
|
|
|
|
append line " " [string trim $rettype]
|
|
|
|
if {[string index $rettype end] ne "*"} {
|
|
|
|
append line " "
|
|
|
|
}
|
2016-08-24 21:58:46 +02:00
|
|
|
if {$useapicall} {
|
|
|
|
if {[lsearch -exact $cdecllist $funcname] >= 0} {
|
2016-09-09 01:16:02 +02:00
|
|
|
append line SQLITE_CDECL " "
|
2016-08-24 21:58:46 +02:00
|
|
|
} else {
|
2016-09-09 01:16:02 +02:00
|
|
|
append line SQLITE_APICALL " "
|
2016-08-24 21:58:46 +02:00
|
|
|
}
|
2015-03-24 22:52:12 +01:00
|
|
|
}
|
2016-09-09 01:16:02 +02:00
|
|
|
append line $funcname $rest
|
2015-03-24 22:52:12 +01:00
|
|
|
puts $out $line
|
2011-09-17 19:29:20 +02:00
|
|
|
} else {
|
|
|
|
puts $out "SQLITE_PRIVATE $line"
|
|
|
|
}
|
|
|
|
} elseif {[regexp $varpattern $line all varname]} {
|
2015-03-24 22:52:12 +01:00
|
|
|
# Add the SQLITE_PRIVATE before variable declarations or
|
|
|
|
# definitions for internal use
|
|
|
|
regsub {^SQLITE_API } $line {} line
|
|
|
|
if {![regexp {^sqlite3_} $varname]} {
|
|
|
|
regsub {^extern } $line {} line
|
|
|
|
puts $out "SQLITE_PRIVATE $line"
|
|
|
|
} else {
|
|
|
|
if {[regexp {const char sqlite3_version\[\];} $line]} {
|
|
|
|
set line {const char sqlite3_version[] = SQLITE_VERSION;}
|
|
|
|
}
|
|
|
|
regsub {^SQLITE_EXTERN } $line {} line
|
|
|
|
puts $out "SQLITE_API $line"
|
2011-09-17 19:29:20 +02:00
|
|
|
}
|
|
|
|
} elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
|
2015-03-24 22:52:12 +01:00
|
|
|
regsub {^SQLITE_API } $line {} line
|
2011-09-17 19:29:20 +02:00
|
|
|
regsub {^SQLITE_EXTERN } $line {} line
|
2015-03-24 22:52:12 +01:00
|
|
|
puts $out $line
|
2011-09-17 19:29:20 +02:00
|
|
|
} elseif {[regexp {^void \(\*sqlite3Os} $line]} {
|
2015-03-24 22:52:12 +01:00
|
|
|
regsub {^SQLITE_API } $line {} line
|
2011-09-17 19:29:20 +02:00
|
|
|
puts $out "SQLITE_PRIVATE $line"
|
|
|
|
} else {
|
|
|
|
puts $out $line
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
puts $out $line
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $in
|
|
|
|
section_comment "End of $tail"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Process the source files. Process files containing commonly
|
|
|
|
# used subroutines first in order to help the compiler find
|
|
|
|
# inlining opportunities.
|
|
|
|
#
|
|
|
|
foreach file {
|
|
|
|
sqliteInt.h
|
|
|
|
|
|
|
|
global.c
|
|
|
|
ctime.c
|
|
|
|
status.c
|
|
|
|
date.c
|
|
|
|
os.c
|
|
|
|
|
|
|
|
fault.c
|
|
|
|
mem0.c
|
|
|
|
mem1.c
|
|
|
|
mem2.c
|
|
|
|
mem3.c
|
|
|
|
mem5.c
|
|
|
|
mutex.c
|
|
|
|
mutex_noop.c
|
|
|
|
mutex_unix.c
|
|
|
|
mutex_w32.c
|
|
|
|
malloc.c
|
|
|
|
printf.c
|
2016-08-24 21:58:46 +02:00
|
|
|
treeview.c
|
2011-09-17 19:29:20 +02:00
|
|
|
random.c
|
2012-07-21 21:40:42 +02:00
|
|
|
threads.c
|
2011-09-17 19:29:20 +02:00
|
|
|
utf.c
|
|
|
|
util.c
|
|
|
|
hash.c
|
|
|
|
opcodes.c
|
|
|
|
|
|
|
|
os_unix.c
|
|
|
|
os_win.c
|
|
|
|
|
|
|
|
bitvec.c
|
|
|
|
pcache.c
|
|
|
|
pcache1.c
|
|
|
|
rowset.c
|
|
|
|
pager.c
|
|
|
|
wal.c
|
|
|
|
|
|
|
|
btmutex.c
|
|
|
|
btree.c
|
|
|
|
backup.c
|
|
|
|
|
|
|
|
vdbemem.c
|
|
|
|
vdbeaux.c
|
|
|
|
vdbeapi.c
|
|
|
|
vdbetrace.c
|
|
|
|
vdbe.c
|
|
|
|
vdbeblob.c
|
|
|
|
vdbesort.c
|
|
|
|
memjournal.c
|
|
|
|
|
|
|
|
walker.c
|
|
|
|
resolve.c
|
|
|
|
expr.c
|
|
|
|
alter.c
|
|
|
|
analyze.c
|
|
|
|
attach.c
|
|
|
|
auth.c
|
|
|
|
build.c
|
|
|
|
callback.c
|
|
|
|
delete.c
|
|
|
|
func.c
|
|
|
|
fkey.c
|
|
|
|
insert.c
|
|
|
|
legacy.c
|
|
|
|
loadext.c
|
|
|
|
pragma.c
|
|
|
|
prepare.c
|
|
|
|
select.c
|
|
|
|
table.c
|
|
|
|
trigger.c
|
|
|
|
update.c
|
|
|
|
vacuum.c
|
|
|
|
vtab.c
|
2016-08-24 21:58:46 +02:00
|
|
|
wherecode.c
|
|
|
|
whereexpr.c
|
2011-09-17 19:29:20 +02:00
|
|
|
where.c
|
2018-06-09 19:58:51 +02:00
|
|
|
window.c
|
2011-09-17 19:29:20 +02:00
|
|
|
|
|
|
|
parse.c
|
|
|
|
|
|
|
|
tokenize.c
|
|
|
|
complete.c
|
|
|
|
|
|
|
|
main.c
|
|
|
|
notify.c
|
|
|
|
} {
|
|
|
|
copy_file tsrc/$file
|
|
|
|
}
|
|
|
|
|
|
|
|
close $out
|