~ubuntu-branches/ubuntu/hardy/sqlite3/hardy

« back to all changes in this revision

Viewing changes to tool/mksqlite3c.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2007-05-17 02:01:42 UTC
  • mfrom: (1.1.8 upstream) (3.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20070517020142-o79d5uduuhfbtknv
Tags: 3.3.17-1
* New upstream release.
* Use minor version as well in sqlite3.pc (closes: #424235).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 sqlite3.c 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 separate C source files from SQLite
 
48
** version $VERSION.  By combining all the individual C code files into this 
 
49
** single large file, the entire code can be compiled as a one translation
 
50
** unit.  This allows many compilers to do optimizations that would not be
 
51
** possible if the files were compiled separately.  Performance improvements
 
52
** of 5% are more are commonly seen when SQLite is compiled as a single
 
53
** translation unit.
 
54
**
 
55
** This file is all you need to compile SQLite.  To use SQLite in other
 
56
** programs, you need this file and the "sqlite3.h" header file that defines
 
57
** the programming interface to the SQLite library.  (If you do not have 
 
58
** the "sqlite3.h" header file at hand, you will find a copy in the first
 
59
** $cnt lines past this header comment.)  Additional code files may be
 
60
** needed if you want a wrapper to interface SQLite with your choice of
 
61
** programming language.  The code for the "sqlite3" command-line shell
 
62
** is also in a separate file.  This file contains only code for the core
 
63
** SQLite library.
 
64
**
 
65
** This amalgamation was generated on $today.
 
66
*/
 
67
#define SQLITE_AMALGAMATION 1}]
 
68
 
 
69
# These are the header files used by SQLite.  The first time any of these 
 
70
# files are seen in a #include statement in the C code, include the complete
 
71
# text of the file in-line.  The file only needs to be included once.
 
72
#
 
73
foreach hdr {
 
74
   btree.h
 
75
   hash.h
 
76
   keywordhash.h
 
77
   opcodes.h
 
78
   os_common.h
 
79
   os.h
 
80
   os_os2.h
 
81
   pager.h
 
82
   parse.h
 
83
   sqlite3ext.h
 
84
   sqlite3.h
 
85
   sqliteInt.h
 
86
   vdbe.h
 
87
   vdbeInt.h
 
88
} {
 
89
  set available_hdr($hdr) 1
 
90
}
 
91
set available_hdr(sqlite3.h) 0
 
92
 
 
93
# 78 stars used for comment formatting.
 
94
set s78 \
 
95
{*****************************************************************************}
 
96
 
 
97
# Insert a comment into the code
 
98
#
 
99
proc section_comment {text} {
 
100
  global out s78
 
101
  set n [string length $text]
 
102
  set nstar [expr {60 - $n}]
 
103
  set stars [string range $s78 0 $nstar]
 
104
  puts $out "/************** $text $stars/"
 
105
}
 
106
 
 
107
# Read the source file named $filename and write it into the
 
108
# sqlite3.c output file.  If any #include statements are seen,
 
109
# process them approprately.
 
110
#
 
111
proc copy_file {filename} {
 
112
  global seen_hdr available_hdr out
 
113
  set tail [file tail $filename]
 
114
  section_comment "Begin file $tail"
 
115
  set in [open $filename r]
 
116
  while {![eof $in]} {
 
117
    set line [gets $in]
 
118
    if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
 
119
      if {[info exists available_hdr($hdr)]} {
 
120
        if {$available_hdr($hdr)} {
 
121
          if {$hdr!="os_common.h"} {
 
122
            set available_hdr($hdr) 0
 
123
          }
 
124
          section_comment "Include $hdr in the middle of $tail"
 
125
          copy_file tsrc/$hdr
 
126
          section_comment "Continuing where we left off in $tail"
 
127
        }
 
128
      } elseif {![info exists seen_hdr($hdr)]} {
 
129
        set seen_hdr($hdr) 1
 
130
        puts $out $line
 
131
      }
 
132
    } elseif {[regexp {^#ifdef __cplusplus} $line]} {
 
133
      puts $out "#if 0"
 
134
    } elseif {[regexp {^#line} $line]} {
 
135
      # Skip #line directives.
 
136
    } else {
 
137
      puts $out $line
 
138
    }
 
139
  }
 
140
  close $in
 
141
  section_comment "End of $tail"
 
142
}
 
143
 
 
144
 
 
145
# Process the source files.  Process files containing commonly
 
146
# used subroutines first in order to help the compiler find
 
147
# inlining opportunities.
 
148
#
 
149
foreach file {
 
150
   sqlite3.h
 
151
 
 
152
   date.c
 
153
   os.c
 
154
 
 
155
   printf.c
 
156
   random.c
 
157
   utf.c
 
158
   util.c
 
159
   hash.c
 
160
   opcodes.c
 
161
 
 
162
   os_os2.c
 
163
   os_unix.c
 
164
   os_win.c
 
165
 
 
166
   pager.c
 
167
   
 
168
   btree.c
 
169
 
 
170
   vdbefifo.c
 
171
   vdbemem.c
 
172
   vdbeaux.c
 
173
   vdbeapi.c
 
174
   vdbe.c
 
175
 
 
176
   expr.c
 
177
   alter.c
 
178
   analyze.c
 
179
   attach.c
 
180
   auth.c
 
181
   build.c
 
182
   callback.c
 
183
   complete.c
 
184
   delete.c
 
185
   func.c
 
186
   insert.c
 
187
   legacy.c
 
188
   loadext.c
 
189
   pragma.c
 
190
   prepare.c
 
191
   select.c
 
192
   table.c
 
193
   trigger.c
 
194
   update.c
 
195
   vacuum.c
 
196
   vtab.c
 
197
   where.c
 
198
 
 
199
   parse.c
 
200
 
 
201
   tokenize.c
 
202
 
 
203
   main.c
 
204
} {
 
205
  copy_file tsrc/$file
 
206
}
 
207
 
 
208
if 0 {
 
209
puts $out "#ifdef SQLITE_TEST"
 
210
foreach file {
 
211
   test1.c
 
212
   test2.c
 
213
   test3.c
 
214
   test4.c
 
215
   test5.c
 
216
   test6.c
 
217
   test7.c
 
218
   test8.c
 
219
   test_async.c
 
220
   test_autoext.c
 
221
   test_loadext.c
 
222
   test_md5.c
 
223
   test_schema.c
 
224
   test_server.c
 
225
   test_tclvar.c
 
226
} {
 
227
  copy_file ../sqlite/src/$file
 
228
}
 
229
puts $out "#endif /* SQLITE_TEST */"
 
230
puts $out "#ifdef SQLITE_TCL"
 
231
copy_file ../sqlite/src/tclsqlite.c
 
232
puts $out "#endif /* SQLITE_TCL */"
 
233
}
 
234
 
 
235
close $out