drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 1 | #!/usr/bin/tclsh |
| 2 | # |
| 3 | # To build a single huge source file holding all of SQLite (or at |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 4 | # least the core components - the test harness, shell, and TCL |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 5 | # interface are omitted.) first do |
| 6 | # |
| 7 | # make target_source |
| 8 | # |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 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 |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 14 | # the parser are derived from "parse.y" using lemon. And the |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 15 | # "keywordhash.h" files is generated by a program named "mkkeywordhash". |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 16 | # |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 17 | # After the "tsrc" directory has been created and populated, run |
| 18 | # this script: |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 19 | # |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 20 | # tclsh mksqlite3c.tcl |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 21 | # |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 22 | # The amalgamated SQLite code will be written into sqlite3.c |
| 23 | # |
| 24 | |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 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. |
mistachkin | 696555d | 2021-07-13 21:59:22 +0000 | [diff] [blame] | 28 | --linemacros=? => Emit #line directives into output or not. (? = 1 or 0) |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 29 | --useapicall => Prepend functions with SQLITE_APICALL or SQLITE_CDECL. |
| 30 | --srcdir $SRC => Specify the directory containing constituent sources. |
| 31 | --help => See this. |
mistachkin | 696555d | 2021-07-13 21:59:22 +0000 | [diff] [blame] | 32 | The value setting options default to --linemacros=1 and '--srcdir tsrc' . |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 33 | } |
| 34 | |
drh | 8de5a17 | 2009-07-20 12:25:44 +0000 | [diff] [blame] | 35 | # Begin by reading the "sqlite3.h" header file. Extract the version number |
drh | e191e2c | 2013-03-19 15:23:18 +0000 | [diff] [blame] | 36 | # from in this file. The version number is needed to generate the header |
drh | 8de5a17 | 2009-07-20 12:25:44 +0000 | [diff] [blame] | 37 | # comment of the amalgamation. |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 38 | # |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 39 | |
drh | 84ab953 | 2015-05-04 17:06:39 +0000 | [diff] [blame] | 40 | set addstatic 1 |
mistachkin | e13dfe4 | 2021-07-15 23:34:14 +0000 | [diff] [blame] | 41 | set linemacros 0 |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 42 | set useapicall 0 |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 43 | set srcdir tsrc |
| 44 | |
drh | 84ab953 | 2015-05-04 17:06:39 +0000 | [diff] [blame] | 45 | for {set i 0} {$i<[llength $argv]} {incr i} { |
| 46 | set x [lindex $argv $i] |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 47 | if {[regexp {^-?-nostatic$} $x]} { |
drh | 84ab953 | 2015-05-04 17:06:39 +0000 | [diff] [blame] | 48 | set addstatic 0 |
mistachkin | 696555d | 2021-07-13 21:59:22 +0000 | [diff] [blame] | 49 | } elseif {[regexp {^-?-linemacros(?:=([01]))?$} $x ma ulm]} { |
| 50 | if {$ulm == ""} {set ulm 1} |
| 51 | set linemacros $ulm |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 52 | } elseif {[regexp {^-?-useapicall$} $x]} { |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 53 | set useapicall 1 |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 54 | } elseif {[regexp {^-?-srcdir$} $x]} { |
| 55 | incr i |
| 56 | if {$i==[llength $argv]} { |
| 57 | error "No argument following $x" |
| 58 | } |
| 59 | set srcdir [lindex $argv $i] |
| 60 | } elseif {[regexp {^-?-((help)|\?)$} $x]} { |
| 61 | puts $help |
| 62 | exit 0 |
drh | 84ab953 | 2015-05-04 17:06:39 +0000 | [diff] [blame] | 63 | } else { |
| 64 | error "unknown command-line option: $x" |
| 65 | } |
drh | 96e5088 | 2011-08-15 15:27:20 +0000 | [diff] [blame] | 66 | } |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 67 | set in [open $srcdir/sqlite3.h] |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 68 | set cnt 0 |
| 69 | set VERSION ????? |
| 70 | while {![eof $in]} { |
| 71 | set line [gets $in] |
| 72 | if {$line=="" && [eof $in]} break |
| 73 | incr cnt |
| 74 | regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION |
| 75 | } |
| 76 | close $in |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 77 | |
| 78 | # Open the output file and write a header comment at the beginning |
| 79 | # of the file. |
| 80 | # |
| 81 | set out [open sqlite3.c w] |
shaneh | 5e0fb2c | 2011-06-17 15:54:59 +0000 | [diff] [blame] | 82 | # Force the output to use unix line endings, even on Windows. |
drh | ced174b | 2011-06-20 15:24:22 +0000 | [diff] [blame] | 83 | fconfigure $out -translation lf |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 84 | set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1] |
| 85 | puts $out [subst \ |
| 86 | {/****************************************************************************** |
drh | 19df335 | 2007-04-01 01:57:41 +0000 | [diff] [blame] | 87 | ** This file is an amalgamation of many separate C source files from SQLite |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 88 | ** version $VERSION. By combining all the individual C code files into this |
drh | 1d21021 | 2011-04-01 18:12:58 +0000 | [diff] [blame] | 89 | ** single large file, the entire code can be compiled as a single translation |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 90 | ** unit. This allows many compilers to do optimizations that would not be |
| 91 | ** possible if the files were compiled separately. Performance improvements |
drh | 0ee6862 | 2010-10-31 22:42:27 +0000 | [diff] [blame] | 92 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 93 | ** translation unit. |
| 94 | ** |
| 95 | ** This file is all you need to compile SQLite. To use SQLite in other |
| 96 | ** programs, you need this file and the "sqlite3.h" header file that defines |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 97 | ** the programming interface to the SQLite library. (If you do not have |
drh | 8de5a17 | 2009-07-20 12:25:44 +0000 | [diff] [blame] | 98 | ** the "sqlite3.h" header file at hand, you will find a copy embedded within |
| 99 | ** the text of this file. Search for "Begin file sqlite3.h" to find the start |
| 100 | ** of the embedded sqlite3.h header file.) Additional code files may be needed |
| 101 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 102 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 103 | ** separate file. This file contains only code for the core SQLite library. |
drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame] | 104 | */ |
danielk1977 | 7c9aaa7 | 2008-01-01 05:49:07 +0000 | [diff] [blame] | 105 | #define SQLITE_CORE 1 |
drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame] | 106 | #define SQLITE_AMALGAMATION 1}] |
drh | b6a9ece | 2007-06-26 00:37:27 +0000 | [diff] [blame] | 107 | if {$addstatic} { |
| 108 | puts $out \ |
| 109 | {#ifndef SQLITE_PRIVATE |
| 110 | # define SQLITE_PRIVATE static |
| 111 | #endif} |
| 112 | } |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 113 | |
drh | 786142a | 2020-09-10 12:41:46 +0000 | [diff] [blame] | 114 | # Examine the parse.c file. If it contains lines of the form: |
| 115 | # |
| 116 | # "#ifndef SQLITE_ENABLE_UPDATE_LIMIT |
| 117 | # |
| 118 | # then set the SQLITE_UDL_CAPABLE_PARSER flag in the amalgamation. |
| 119 | # |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 120 | set in [open $srcdir/parse.c] |
drh | 786142a | 2020-09-10 12:41:46 +0000 | [diff] [blame] | 121 | if {[regexp {ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT} [read $in]]} { |
| 122 | puts $out "#define SQLITE_UDL_CAPABLE_PARSER 1" |
| 123 | } |
| 124 | close $in |
| 125 | |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 126 | # These are the header files used by SQLite. The first time any of these |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 127 | # files are seen in a #include statement in the C code, include the complete |
| 128 | # text of the file in-line. The file only needs to be included once. |
| 129 | # |
| 130 | foreach hdr { |
| 131 | btree.h |
drh | a315289 | 2007-05-05 11:48:52 +0000 | [diff] [blame] | 132 | btreeInt.h |
drh | 820a906 | 2008-01-31 13:35:48 +0000 | [diff] [blame] | 133 | fts3.h |
drh | f7829ad | 2009-11-25 22:42:22 +0000 | [diff] [blame] | 134 | fts3Int.h |
drh | 820a906 | 2008-01-31 13:35:48 +0000 | [diff] [blame] | 135 | fts3_hash.h |
| 136 | fts3_tokenizer.h |
drh | 748b8fd | 2018-05-25 19:22:47 +0000 | [diff] [blame] | 137 | geopoly.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 138 | hash.h |
shane | 9bcbdad | 2008-05-29 20:22:37 +0000 | [diff] [blame] | 139 | hwtime.h |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 140 | keywordhash.h |
mistachkin | 2318d33 | 2015-01-12 18:02:52 +0000 | [diff] [blame] | 141 | msvc.h |
drh | 428e282 | 2007-08-30 16:23:19 +0000 | [diff] [blame] | 142 | mutex.h |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 143 | opcodes.h |
| 144 | os_common.h |
mistachkin | f74b9e0 | 2013-11-26 01:00:31 +0000 | [diff] [blame] | 145 | os_setup.h |
mistachkin | 8bc5262 | 2013-11-25 09:36:07 +0000 | [diff] [blame] | 146 | os_win.h |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 147 | os.h |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 148 | pager.h |
| 149 | parse.h |
danielk1977 | 8c0a791 | 2008-08-20 14:49:23 +0000 | [diff] [blame] | 150 | pcache.h |
drh | 67e65e5 | 2015-02-02 21:34:54 +0000 | [diff] [blame] | 151 | pragma.h |
drh | 58f1c8b | 2008-05-26 20:19:25 +0000 | [diff] [blame] | 152 | rtree.h |
drh | 498dcae | 2013-03-13 11:42:00 +0000 | [diff] [blame] | 153 | sqlite3session.h |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 154 | sqlite3.h |
dan | cd73244 | 2015-02-10 20:00:38 +0000 | [diff] [blame] | 155 | sqlite3ext.h |
drh | cfb8f8d | 2015-07-23 20:44:49 +0000 | [diff] [blame] | 156 | sqlite3rbu.h |
danielk1977 | 1c82665 | 2008-09-08 08:08:09 +0000 | [diff] [blame] | 157 | sqliteicu.h |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 158 | sqliteInt.h |
drh | c551dd8 | 2007-06-19 15:23:48 +0000 | [diff] [blame] | 159 | sqliteLimit.h |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 160 | vdbe.h |
| 161 | vdbeInt.h |
drh | 8cd5b25 | 2015-03-02 22:06:43 +0000 | [diff] [blame] | 162 | vxworks.h |
drh | c438efd | 2010-04-26 00:19:45 +0000 | [diff] [blame] | 163 | wal.h |
drh | e54df42 | 2013-11-12 18:37:25 +0000 | [diff] [blame] | 164 | whereInt.h |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 165 | } { |
| 166 | set available_hdr($hdr) 1 |
| 167 | } |
drh | 71674ce | 2007-10-23 15:51:26 +0000 | [diff] [blame] | 168 | set available_hdr(sqliteInt.h) 0 |
drh | 15482bc | 2021-08-06 15:26:01 +0000 | [diff] [blame] | 169 | set available_hdr(os_common.h) 0 |
drh | e191e2c | 2013-03-19 15:23:18 +0000 | [diff] [blame] | 170 | set available_hdr(sqlite3session.h) 0 |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 171 | |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 172 | # These headers should be copied into the amalgamation without modifying any |
| 173 | # of their function declarations or definitions. |
| 174 | set varonly_hdr(sqlite3.h) 1 |
| 175 | |
| 176 | # These are the functions that accept a variable number of arguments. They |
| 177 | # always need to use the "cdecl" calling convention even when another calling |
| 178 | # convention (e.g. "stcall") is being used for the rest of the library. |
| 179 | set cdecllist { |
| 180 | sqlite3_config |
| 181 | sqlite3_db_config |
| 182 | sqlite3_log |
| 183 | sqlite3_mprintf |
| 184 | sqlite3_snprintf |
| 185 | sqlite3_test_control |
| 186 | sqlite3_vtab_config |
| 187 | } |
| 188 | |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 189 | # 78 stars used for comment formatting. |
| 190 | set s78 \ |
| 191 | {*****************************************************************************} |
| 192 | |
| 193 | # Insert a comment into the code |
| 194 | # |
| 195 | proc section_comment {text} { |
| 196 | global out s78 |
| 197 | set n [string length $text] |
| 198 | set nstar [expr {60 - $n}] |
| 199 | set stars [string range $s78 0 $nstar] |
| 200 | puts $out "/************** $text $stars/" |
| 201 | } |
| 202 | |
| 203 | # Read the source file named $filename and write it into the |
| 204 | # sqlite3.c output file. If any #include statements are seen, |
mistachkin | 2a43c28 | 2013-08-31 05:46:42 +0000 | [diff] [blame] | 205 | # process them appropriately. |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 206 | # |
| 207 | proc copy_file {filename} { |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 208 | global seen_hdr available_hdr varonly_hdr cdecllist out |
mistachkin | 696555d | 2021-07-13 21:59:22 +0000 | [diff] [blame] | 209 | global addstatic linemacros useapicall srcdir |
drh | 96e5088 | 2011-08-15 15:27:20 +0000 | [diff] [blame] | 210 | set ln 0 |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 211 | set tail [file tail $filename] |
| 212 | section_comment "Begin file $tail" |
mistachkin | 696555d | 2021-07-13 21:59:22 +0000 | [diff] [blame] | 213 | if {$linemacros} {puts $out "#line 1 \"$filename\""} |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 214 | set in [open $filename r] |
drh | 73be501 | 2007-08-08 12:11:21 +0000 | [diff] [blame] | 215 | set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 216 | set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)} |
drh | ee85813 | 2007-05-08 20:37:38 +0000 | [diff] [blame] | 217 | if {[file extension $filename]==".h"} { |
drh | f7083bf | 2007-08-08 01:04:52 +0000 | [diff] [blame] | 218 | set declpattern " *$declpattern" |
drh | ee85813 | 2007-05-08 20:37:38 +0000 | [diff] [blame] | 219 | } |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 220 | set declpattern ^$declpattern\$ |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 221 | while {![eof $in]} { |
drh | 24aee8a | 2020-06-23 17:57:08 +0000 | [diff] [blame] | 222 | set line [string trimright [gets $in]] |
drh | 96e5088 | 2011-08-15 15:27:20 +0000 | [diff] [blame] | 223 | incr ln |
drh | 9965a04 | 2008-10-14 18:21:11 +0000 | [diff] [blame] | 224 | if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 225 | if {[info exists available_hdr($hdr)]} { |
| 226 | if {$available_hdr($hdr)} { |
drh | 15482bc | 2021-08-06 15:26:01 +0000 | [diff] [blame] | 227 | set available_hdr($hdr) 0 |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 228 | section_comment "Include $hdr in the middle of $tail" |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 229 | copy_file $srcdir/$hdr |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 230 | section_comment "Continuing where we left off in $tail" |
mistachkin | 696555d | 2021-07-13 21:59:22 +0000 | [diff] [blame] | 231 | if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} |
mistachkin | 3a2a686 | 2015-07-15 21:00:33 +0000 | [diff] [blame] | 232 | } else { |
| 233 | # Comment out the entire line, replacing any nested comment |
| 234 | # begin/end markers with the harmless substring "**". |
| 235 | puts $out "/* [string map [list /* ** */ **] $line] */" |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 236 | } |
| 237 | } elseif {![info exists seen_hdr($hdr)]} { |
drh | 1a8a0d3 | 2014-05-05 20:21:52 +0000 | [diff] [blame] | 238 | if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} { |
| 239 | set seen_hdr($hdr) 1 |
| 240 | } |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 241 | puts $out $line |
mistachkin | 1a88b14 | 2013-08-31 18:06:52 +0000 | [diff] [blame] | 242 | } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} { |
| 243 | # This include file must be kept because there was a "keep" |
| 244 | # directive inside of a line comment. |
| 245 | puts $out $line |
drh | 96e5088 | 2011-08-15 15:27:20 +0000 | [diff] [blame] | 246 | } else { |
mistachkin | 1a88b14 | 2013-08-31 18:06:52 +0000 | [diff] [blame] | 247 | # Comment out the entire line, replacing any nested comment |
| 248 | # begin/end markers with the harmless substring "**". |
| 249 | puts $out "/* [string map [list /* ** */ **] $line] */" |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 250 | } |
| 251 | } elseif {[regexp {^#ifdef __cplusplus} $line]} { |
| 252 | puts $out "#if 0" |
mistachkin | 696555d | 2021-07-13 21:59:22 +0000 | [diff] [blame] | 253 | } elseif {!$linemacros && [regexp {^#line} $line]} { |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 254 | # Skip #line directives. |
drh | 45fac88 | 2015-10-09 01:42:49 +0000 | [diff] [blame] | 255 | } elseif {$addstatic |
| 256 | && ![regexp {^(static|typedef|SQLITE_PRIVATE)} $line]} { |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 257 | # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before |
| 258 | # functions if this header file does not need it. |
| 259 | if {![info exists varonly_hdr($tail)] |
| 260 | && [regexp $declpattern $line all rettype funcname rest]} { |
| 261 | regsub {^SQLITE_API } $line {} line |
dan | f5f0e43 | 2017-08-04 08:23:33 +0000 | [diff] [blame] | 262 | regsub {^SQLITE_API } $rettype {} rettype |
| 263 | |
drh | 0a0e131 | 2007-08-07 17:04:59 +0000 | [diff] [blame] | 264 | # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. |
| 265 | # so that linkage can be modified at compile-time. |
drh | 1ffe7c7 | 2013-03-19 17:10:10 +0000 | [diff] [blame] | 266 | if {[regexp {^sqlite3[a-z]*_} $funcname]} { |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 267 | set line SQLITE_API |
| 268 | append line " " [string trim $rettype] |
| 269 | if {[string index $rettype end] ne "*"} { |
| 270 | append line " " |
| 271 | } |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 272 | if {$useapicall} { |
| 273 | if {[lsearch -exact $cdecllist $funcname] >= 0} { |
mistachkin | 0e4125a | 2016-09-08 23:16:02 +0000 | [diff] [blame] | 274 | append line SQLITE_CDECL " " |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 275 | } else { |
mistachkin | 0e4125a | 2016-09-08 23:16:02 +0000 | [diff] [blame] | 276 | append line SQLITE_APICALL " " |
mistachkin | 4ef916e | 2016-08-24 19:58:46 +0000 | [diff] [blame] | 277 | } |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 278 | } |
mistachkin | 0e4125a | 2016-09-08 23:16:02 +0000 | [diff] [blame] | 279 | append line $funcname $rest |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 280 | if {$funcname=="sqlite3_sourceid"} { |
drh | 0a02c72 | 2017-08-22 21:07:03 +0000 | [diff] [blame] | 281 | # The sqlite3_sourceid() routine is synthesized at the end of |
| 282 | # the amalgamation |
| 283 | puts $out "/* $line */" |
| 284 | } else { |
| 285 | puts $out $line |
| 286 | } |
drh | 0a0e131 | 2007-08-07 17:04:59 +0000 | [diff] [blame] | 287 | } else { |
| 288 | puts $out "SQLITE_PRIVATE $line" |
| 289 | } |
| 290 | } elseif {[regexp $varpattern $line all varname]} { |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 291 | # Add the SQLITE_PRIVATE before variable declarations or |
| 292 | # definitions for internal use |
| 293 | regsub {^SQLITE_API } $line {} line |
| 294 | if {![regexp {^sqlite3_} $varname]} { |
| 295 | regsub {^extern } $line {} line |
| 296 | puts $out "SQLITE_PRIVATE $line" |
| 297 | } else { |
| 298 | if {[regexp {const char sqlite3_version\[\];} $line]} { |
| 299 | set line {const char sqlite3_version[] = SQLITE_VERSION;} |
| 300 | } |
| 301 | regsub {^SQLITE_EXTERN } $line {} line |
| 302 | puts $out "SQLITE_API $line" |
drh | b3190c1 | 2008-12-08 21:37:14 +0000 | [diff] [blame] | 303 | } |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 304 | } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 305 | regsub {^SQLITE_API } $line {} line |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 306 | regsub {^SQLITE_EXTERN } $line {} line |
dan | 8038953 | 2014-12-24 17:17:30 +0000 | [diff] [blame] | 307 | puts $out $line |
drh | f158162 | 2009-02-03 13:51:17 +0000 | [diff] [blame] | 308 | } elseif {[regexp {^void \(\*sqlite3Os} $line]} { |
mistachkin | 59b9b02 | 2015-03-24 21:27:27 +0000 | [diff] [blame] | 309 | regsub {^SQLITE_API } $line {} line |
drh | f158162 | 2009-02-03 13:51:17 +0000 | [diff] [blame] | 310 | puts $out "SQLITE_PRIVATE $line" |
drh | 26b0fc0 | 2007-06-26 00:52:39 +0000 | [diff] [blame] | 311 | } else { |
drh | 0a0e131 | 2007-08-07 17:04:59 +0000 | [diff] [blame] | 312 | puts $out $line |
drh | 26b0fc0 | 2007-06-26 00:52:39 +0000 | [diff] [blame] | 313 | } |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 314 | } else { |
| 315 | puts $out $line |
| 316 | } |
| 317 | } |
| 318 | close $in |
| 319 | section_comment "End of $tail" |
| 320 | } |
| 321 | |
| 322 | |
| 323 | # Process the source files. Process files containing commonly |
| 324 | # used subroutines first in order to help the compiler find |
| 325 | # inlining opportunities. |
| 326 | # |
| 327 | foreach file { |
drh | 71674ce | 2007-10-23 15:51:26 +0000 | [diff] [blame] | 328 | sqliteInt.h |
drh | 15482bc | 2021-08-06 15:26:01 +0000 | [diff] [blame] | 329 | os_common.h |
drh | a612c1c | 2021-07-05 18:37:37 +0000 | [diff] [blame] | 330 | ctime.c |
drh | 98495b4 | 2007-03-31 22:29:05 +0000 | [diff] [blame] | 331 | |
drh | 40257ff | 2008-06-13 18:24:27 +0000 | [diff] [blame] | 332 | global.c |
drh | f714199 | 2008-06-19 00:16:08 +0000 | [diff] [blame] | 333 | status.c |
drh | a55ca9e | 2007-04-02 12:22:44 +0000 | [diff] [blame] | 334 | date.c |
drh | 970f724 | 2007-03-31 16:29:06 +0000 | [diff] [blame] | 335 | os.c |
| 336 | |
drh | 643167f | 2008-01-22 21:30:53 +0000 | [diff] [blame] | 337 | fault.c |
drh | d1370b6 | 2008-10-28 18:58:20 +0000 | [diff] [blame] | 338 | mem0.c |
drh | 97c8ec3 | 2007-08-27 21:49:34 +0000 | [diff] [blame] | 339 | mem1.c |
| 340 | mem2.c |
danielk1977 | 6b39c2e | 2008-06-25 14:57:53 +0000 | [diff] [blame] | 341 | mem3.c |
| 342 | mem5.c |
drh | 97c8ec3 | 2007-08-27 21:49:34 +0000 | [diff] [blame] | 343 | mutex.c |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 344 | mutex_noop.c |
drh | 61f6dc6 | 2007-08-30 17:15:37 +0000 | [diff] [blame] | 345 | mutex_unix.c |
| 346 | mutex_w32.c |
drh | a315289 | 2007-05-05 11:48:52 +0000 | [diff] [blame] | 347 | malloc.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 348 | printf.c |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 349 | treeview.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 350 | random.c |
drh | f51446a | 2012-07-21 19:40:42 +0000 | [diff] [blame] | 351 | threads.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 352 | utf.c |
| 353 | util.c |
| 354 | hash.c |
| 355 | opcodes.c |
| 356 | |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 357 | os_unix.c |
| 358 | os_win.c |
drh | ac442f4 | 2018-01-03 01:28:46 +0000 | [diff] [blame] | 359 | memdb.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 360 | |
drh | f5e7bb5 | 2008-02-18 14:47:33 +0000 | [diff] [blame] | 361 | bitvec.c |
danielk1977 | 8c0a791 | 2008-08-20 14:49:23 +0000 | [diff] [blame] | 362 | pcache.c |
danielk1977 | d17e71c | 2008-11-13 14:42:18 +0000 | [diff] [blame] | 363 | pcache1.c |
drh | 3d4501e | 2008-12-04 20:40:10 +0000 | [diff] [blame] | 364 | rowset.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 365 | pager.c |
shaneh | fd06863 | 2010-05-06 19:20:29 +0000 | [diff] [blame] | 366 | wal.c |
drh | 61f6dc6 | 2007-08-30 17:15:37 +0000 | [diff] [blame] | 367 | |
shane | 9bcbdad | 2008-05-29 20:22:37 +0000 | [diff] [blame] | 368 | btmutex.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 369 | btree.c |
danielk1977 | 0410302 | 2009-02-03 16:51:24 +0000 | [diff] [blame] | 370 | backup.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 371 | |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 372 | vdbemem.c |
| 373 | vdbeaux.c |
| 374 | vdbeapi.c |
drh | c7bc4fd | 2009-11-25 18:03:42 +0000 | [diff] [blame] | 375 | vdbetrace.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 376 | vdbe.c |
drh | 3f75584 | 2007-05-03 16:55:32 +0000 | [diff] [blame] | 377 | vdbeblob.c |
dan | 7fe6270 | 2011-08-02 10:56:22 +0000 | [diff] [blame] | 378 | vdbesort.c |
drh | 691b5c5 | 2020-03-23 15:49:22 +0000 | [diff] [blame] | 379 | vdbevtab.c |
danielk1977 | b317538 | 2008-10-17 18:51:52 +0000 | [diff] [blame] | 380 | memjournal.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 381 | |
drh | 7d10d5a | 2008-08-20 16:35:10 +0000 | [diff] [blame] | 382 | walker.c |
| 383 | resolve.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 384 | expr.c |
| 385 | alter.c |
| 386 | analyze.c |
| 387 | attach.c |
| 388 | auth.c |
| 389 | build.c |
| 390 | callback.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 391 | delete.c |
drh | 70a8ca3 | 2008-08-21 18:49:27 +0000 | [diff] [blame] | 392 | func.c |
dan | 3be7d6e | 2009-09-19 17:59:59 +0000 | [diff] [blame] | 393 | fkey.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 394 | insert.c |
| 395 | legacy.c |
| 396 | loadext.c |
| 397 | pragma.c |
| 398 | prepare.c |
| 399 | select.c |
| 400 | table.c |
| 401 | trigger.c |
| 402 | update.c |
drh | fcfd756 | 2018-04-12 21:42:51 +0000 | [diff] [blame] | 403 | upsert.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 404 | vacuum.c |
| 405 | vtab.c |
drh | 6f82e85 | 2015-06-06 20:12:09 +0000 | [diff] [blame] | 406 | wherecode.c |
drh | 6c1f4ef | 2015-06-08 14:23:15 +0000 | [diff] [blame] | 407 | whereexpr.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 408 | where.c |
dan | d31e7ad | 2018-06-09 17:58:51 +0000 | [diff] [blame] | 409 | window.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 410 | |
| 411 | parse.c |
| 412 | |
| 413 | tokenize.c |
drh | 46c99e0 | 2007-08-27 23:26:59 +0000 | [diff] [blame] | 414 | complete.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 415 | |
| 416 | main.c |
danielk1977 | 404ca07 | 2009-03-16 13:19:36 +0000 | [diff] [blame] | 417 | notify.c |
drh | 820a906 | 2008-01-31 13:35:48 +0000 | [diff] [blame] | 418 | |
| 419 | fts3.c |
dan | 290c939 | 2011-02-01 18:59:34 +0000 | [diff] [blame] | 420 | fts3_aux.c |
drh | aeba020 | 2008-12-31 16:01:04 +0000 | [diff] [blame] | 421 | fts3_expr.c |
drh | 820a906 | 2008-01-31 13:35:48 +0000 | [diff] [blame] | 422 | fts3_hash.c |
| 423 | fts3_porter.c |
| 424 | fts3_tokenizer.c |
| 425 | fts3_tokenizer1.c |
dan | d7a959c | 2013-04-22 15:30:37 +0000 | [diff] [blame] | 426 | fts3_tokenize_vtab.c |
dan | 16708c4 | 2009-11-19 15:25:25 +0000 | [diff] [blame] | 427 | fts3_write.c |
| 428 | fts3_snippet.c |
dan | 3d403c7 | 2012-05-25 17:50:19 +0000 | [diff] [blame] | 429 | fts3_unicode.c |
| 430 | fts3_unicode2.c |
drh | 58f1c8b | 2008-05-26 20:19:25 +0000 | [diff] [blame] | 431 | |
drh | 748b8fd | 2018-05-25 19:22:47 +0000 | [diff] [blame] | 432 | json1.c |
drh | 58f1c8b | 2008-05-26 20:19:25 +0000 | [diff] [blame] | 433 | rtree.c |
danielk1977 | 0c8a5d0 | 2008-08-04 11:49:20 +0000 | [diff] [blame] | 434 | icu.c |
danielk1977 | f9449d0 | 2008-09-24 09:58:00 +0000 | [diff] [blame] | 435 | fts3_icu.c |
drh | cfb8f8d | 2015-07-23 20:44:49 +0000 | [diff] [blame] | 436 | sqlite3rbu.c |
drh | 1a4a680 | 2015-05-04 18:31:09 +0000 | [diff] [blame] | 437 | dbstat.c |
drh | a43c8c8 | 2017-10-11 13:48:11 +0000 | [diff] [blame] | 438 | dbpage.c |
drh | 498dcae | 2013-03-13 11:42:00 +0000 | [diff] [blame] | 439 | sqlite3session.c |
drh | 5006565 | 2015-10-08 19:29:18 +0000 | [diff] [blame] | 440 | fts5.c |
drh | c6603af | 2017-06-29 14:33:51 +0000 | [diff] [blame] | 441 | stmt.c |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 442 | } { |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 443 | copy_file $srcdir/$file |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 444 | } |
| 445 | |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 446 | puts $out \ |
| 447 | "/* Return the source-id for this library */ |
drh | 0a02c72 | 2017-08-22 21:07:03 +0000 | [diff] [blame] | 448 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }" |
larrybr | 4b1c3eb | 2021-07-13 01:45:04 +0000 | [diff] [blame] | 449 | |
drh | 0a02c72 | 2017-08-22 21:07:03 +0000 | [diff] [blame] | 450 | puts $out \ |
| 451 | "/************************** End of sqlite3.c ******************************/" |
| 452 | |
drh | 91c58e2 | 2007-03-27 12:04:04 +0000 | [diff] [blame] | 453 | close $out |