blob: 7e92b3ad7dd02e8db09764f2d09c16e27439b2af [file] [log] [blame]
drhbd08af42007-04-05 21:58:33 +00001#!/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#
29set in [open tsrc/sqlite3.h]
30set cnt 0
31set VERSION ?????
32while {![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}
38close $in
39
40# Open the output file and write a header comment at the beginning
41# of the file.
42#
43set out [open sqlite3internal.h w]
44set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
45puts $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#
55foreach hdr {
56 btree.h
drh84708bc2007-05-08 17:59:42 +000057 btreeInt.h
drhbd08af42007-04-05 21:58:33 +000058 hash.h
shane9bcbdad2008-05-29 20:22:37 +000059 hwtime.h
drhbd08af42007-04-05 21:58:33 +000060 keywordhash.h
drhbd08af42007-04-05 21:58:33 +000061 opcodes.h
62 os_common.h
mistachkinf74b9e02013-11-26 01:00:31 +000063 os_setup.h
mistachkin8bc52622013-11-25 09:36:07 +000064 os_win.h
drhbd08af42007-04-05 21:58:33 +000065 os.h
drhbd08af42007-04-05 21:58:33 +000066 pager.h
67 parse.h
68 sqlite3ext.h
69 sqlite3.h
70 sqliteInt.h
drhc551dd82007-06-19 15:23:48 +000071 sqliteLimit.h
drhbd08af42007-04-05 21:58:33 +000072 vdbe.h
73 vdbeInt.h
74} {
75 set available_hdr($hdr) 1
76}
77
78# 78 stars used for comment formatting.
79set s78 \
80{*****************************************************************************}
81
82# Insert a comment into the code
83#
84proc section_comment {text} {
85 global out s78
86 set n [string length $text]
87 set nstar [expr {60 - $n}]
88 set stars [string range $s78 0 $nstar]
89 puts $out "/************** $text $stars/"
90}
91
92# Read the source file named $filename and write it into the
93# sqlite3.c output file. If any #include statements are seen,
94# process them approprately.
95#
96proc copy_file {filename} {
97 global seen_hdr available_hdr out
98 set tail [file tail $filename]
99 section_comment "Begin file $tail"
100 set in [open $filename r]
101 while {![eof $in]} {
102 set line [gets $in]
103 if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
104 if {[info exists available_hdr($hdr)]} {
105 if {$available_hdr($hdr)} {
106 section_comment "Include $hdr in the middle of $tail"
107 copy_file tsrc/$hdr
108 section_comment "Continuing where we left off in $tail"
109 }
110 } elseif {![info exists seen_hdr($hdr)]} {
111 set seen_hdr($hdr) 1
112 puts $out $line
113 }
114 } elseif {[regexp {^#ifdef __cplusplus} $line]} {
115 puts $out "#if 0"
116 } elseif {[regexp {^#line} $line]} {
117 # Skip #line directives.
118 } else {
119 puts $out $line
120 }
121 }
122 close $in
123 section_comment "End of $tail"
124}
125
126
127# Process the source files. Process files containing commonly
128# used subroutines first in order to help the compiler find
129# inlining opportunities.
130#
131foreach file {
132 sqliteInt.h
133 sqlite3.h
134 btree.h
135 hash.h
136 os.h
137 pager.h
138 parse.h
139 sqlite3ext.h
140 vdbe.h
141} {
142 if {$available_hdr($file)} {
143 copy_file tsrc/$file
144 }
145}
146
147close $out