drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame] | 1 | #!/usr/bin/tclsh |
| 2 | # |
| 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 |
| 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.) 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". |
| 16 | # |
| 17 | # After the "tsrc" directory has been created and populated, run |
| 18 | # this script: |
| 19 | # |
| 20 | # tclsh mksqlite3c.tcl |
| 21 | # |
| 22 | # The amalgamated SQLite code will be written into sqlite3.c |
| 23 | # |
| 24 | |
| 25 | # Begin by reading the "sqlite3.h" header file. Count the number of lines |
| 26 | # in this file and extract the version number. That information will be |
| 27 | # needed in order to generate the header of the amalgamation. |
| 28 | # |
| 29 | set in [open tsrc/sqlite3.h] |
| 30 | set cnt 0 |
| 31 | set VERSION ????? |
| 32 | while {![eof $in]} { |
| 33 | set line [gets $in] |
| 34 | if {$line=="" && [eof $in]} break |
| 35 | incr cnt |
| 36 | regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION |
| 37 | } |
| 38 | close $in |
| 39 | |
| 40 | # Open the output file and write a header comment at the beginning |
| 41 | # of the file. |
| 42 | # |
| 43 | set out [open sqlite3internal.h w] |
| 44 | set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1] |
| 45 | puts $out [subst \ |
| 46 | {/****************************************************************************** |
| 47 | ** This file is an amalgamation of many private header files from SQLite |
| 48 | ** version $VERSION. |
| 49 | */}] |
| 50 | |
| 51 | # These are the header files used by SQLite. The first time any of these |
| 52 | # files are seen in a #include statement in the C code, include the complete |
| 53 | # text of the file in-line. The file only needs to be included once. |
| 54 | # |
| 55 | foreach hdr { |
| 56 | btree.h |
drh | 84708bc | 2007-05-08 17:59:42 +0000 | [diff] [blame] | 57 | btreeInt.h |
drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame] | 58 | hash.h |
shane | 9bcbdad | 2008-05-29 20:22:37 +0000 | [diff] [blame] | 59 | hwtime.h |
drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame] | 60 | keywordhash.h |
mistachkin | 2318d33 | 2015-01-12 18:02:52 +0000 | [diff] [blame] | 61 | msvc.h |
drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame] | 62 | opcodes.h |
| 63 | os_common.h |
mistachkin | f74b9e0 | 2013-11-26 01:00:31 +0000 | [diff] [blame] | 64 | os_setup.h |
mistachkin | 8bc5262 | 2013-11-25 09:36:07 +0000 | [diff] [blame] | 65 | os_win.h |
drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame] | 66 | os.h |
drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame] | 67 | pager.h |
| 68 | parse.h |
| 69 | sqlite3ext.h |
| 70 | sqlite3.h |
| 71 | sqliteInt.h |
drh | c551dd8 | 2007-06-19 15:23:48 +0000 | [diff] [blame] | 72 | sqliteLimit.h |
drh | bd08af4 | 2007-04-05 21:58:33 +0000 | [diff] [blame] | 73 | vdbe.h |
| 74 | vdbeInt.h |
| 75 | } { |
| 76 | set available_hdr($hdr) 1 |
| 77 | } |
| 78 | |
| 79 | # 78 stars used for comment formatting. |
| 80 | set s78 \ |
| 81 | {*****************************************************************************} |
| 82 | |
| 83 | # Insert a comment into the code |
| 84 | # |
| 85 | proc section_comment {text} { |
| 86 | global out s78 |
| 87 | set n [string length $text] |
| 88 | set nstar [expr {60 - $n}] |
| 89 | set stars [string range $s78 0 $nstar] |
| 90 | puts $out "/************** $text $stars/" |
| 91 | } |
| 92 | |
| 93 | # Read the source file named $filename and write it into the |
| 94 | # sqlite3.c output file. If any #include statements are seen, |
| 95 | # process them approprately. |
| 96 | # |
| 97 | proc copy_file {filename} { |
| 98 | global seen_hdr available_hdr out |
| 99 | set tail [file tail $filename] |
| 100 | section_comment "Begin file $tail" |
| 101 | set in [open $filename r] |
| 102 | while {![eof $in]} { |
| 103 | set line [gets $in] |
| 104 | if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { |
| 105 | if {[info exists available_hdr($hdr)]} { |
| 106 | if {$available_hdr($hdr)} { |
| 107 | section_comment "Include $hdr in the middle of $tail" |
| 108 | copy_file tsrc/$hdr |
| 109 | section_comment "Continuing where we left off in $tail" |
| 110 | } |
| 111 | } elseif {![info exists seen_hdr($hdr)]} { |
| 112 | set seen_hdr($hdr) 1 |
| 113 | puts $out $line |
| 114 | } |
| 115 | } elseif {[regexp {^#ifdef __cplusplus} $line]} { |
| 116 | puts $out "#if 0" |
| 117 | } elseif {[regexp {^#line} $line]} { |
| 118 | # Skip #line directives. |
| 119 | } else { |
| 120 | puts $out $line |
| 121 | } |
| 122 | } |
| 123 | close $in |
| 124 | section_comment "End of $tail" |
| 125 | } |
| 126 | |
| 127 | |
| 128 | # Process the source files. Process files containing commonly |
| 129 | # used subroutines first in order to help the compiler find |
| 130 | # inlining opportunities. |
| 131 | # |
| 132 | foreach file { |
| 133 | sqliteInt.h |
| 134 | sqlite3.h |
| 135 | btree.h |
| 136 | hash.h |
| 137 | os.h |
| 138 | pager.h |
| 139 | parse.h |
| 140 | sqlite3ext.h |
| 141 | vdbe.h |
| 142 | } { |
| 143 | if {$available_hdr($file)} { |
| 144 | copy_file tsrc/$file |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | close $out |