Annotation of embedaddon/sqlite3/tool/mksqlite3c.tcl, revision 1.1.1.1

1.1       misho       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.  Extract the version number
                     26: # from in this file.  The versioon number is needed to generate the header
                     27: # comment of the amalgamation.
                     28: #
                     29: if {[lsearch $argv --nostatic]>=0} {
                     30:   set addstatic 0
                     31: } else {
                     32:   set addstatic 1
                     33: }
                     34: if {[lsearch $argv --linemacros]>=0} {
                     35:   set linemacros 1
                     36: } else {
                     37:   set linemacros 0
                     38: }
                     39: set in [open tsrc/sqlite3.h]
                     40: set cnt 0
                     41: set VERSION ?????
                     42: while {![eof $in]} {
                     43:   set line [gets $in]
                     44:   if {$line=="" && [eof $in]} break
                     45:   incr cnt
                     46:   regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
                     47: }
                     48: close $in
                     49: 
                     50: # Open the output file and write a header comment at the beginning
                     51: # of the file.
                     52: #
                     53: set out [open sqlite3.c w]
                     54: # Force the output to use unix line endings, even on Windows.
                     55: fconfigure $out -translation lf
                     56: set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
                     57: puts $out [subst \
                     58: {/******************************************************************************
                     59: ** This file is an amalgamation of many separate C source files from SQLite
                     60: ** version $VERSION.  By combining all the individual C code files into this 
                     61: ** single large file, the entire code can be compiled as a single translation
                     62: ** unit.  This allows many compilers to do optimizations that would not be
                     63: ** possible if the files were compiled separately.  Performance improvements
                     64: ** of 5% or more are commonly seen when SQLite is compiled as a single
                     65: ** translation unit.
                     66: **
                     67: ** This file is all you need to compile SQLite.  To use SQLite in other
                     68: ** programs, you need this file and the "sqlite3.h" header file that defines
                     69: ** the programming interface to the SQLite library.  (If you do not have 
                     70: ** the "sqlite3.h" header file at hand, you will find a copy embedded within
                     71: ** the text of this file.  Search for "Begin file sqlite3.h" to find the start
                     72: ** of the embedded sqlite3.h header file.) Additional code files may be needed
                     73: ** if you want a wrapper to interface SQLite with your choice of programming
                     74: ** language. The code for the "sqlite3" command-line shell is also in a
                     75: ** separate file. This file contains only code for the core SQLite library.
                     76: */
                     77: #define SQLITE_CORE 1
                     78: #define SQLITE_AMALGAMATION 1}]
                     79: if {$addstatic} {
                     80:   puts $out \
                     81: {#ifndef SQLITE_PRIVATE
                     82: # define SQLITE_PRIVATE static
                     83: #endif
                     84: #ifndef SQLITE_API
                     85: # define SQLITE_API
                     86: #endif}
                     87: }
                     88: 
                     89: # These are the header files used by SQLite.  The first time any of these 
                     90: # files are seen in a #include statement in the C code, include the complete
                     91: # text of the file in-line.  The file only needs to be included once.
                     92: #
                     93: foreach hdr {
                     94:    btree.h
                     95:    btreeInt.h
                     96:    fts3.h
                     97:    fts3Int.h
                     98:    fts3_hash.h
                     99:    fts3_tokenizer.h
                    100:    hash.h
                    101:    hwtime.h
                    102:    keywordhash.h
                    103:    mutex.h
                    104:    opcodes.h
                    105:    os_common.h
                    106:    os.h
                    107:    os_os2.h
                    108:    pager.h
                    109:    parse.h
                    110:    pcache.h
                    111:    rtree.h
                    112:    sqlite3ext.h
                    113:    sqlite3.h
                    114:    sqliteicu.h
                    115:    sqliteInt.h
                    116:    sqliteLimit.h
                    117:    vdbe.h
                    118:    vdbeInt.h
                    119:    wal.h
                    120: } {
                    121:   set available_hdr($hdr) 1
                    122: }
                    123: set available_hdr(sqliteInt.h) 0
                    124: 
                    125: # 78 stars used for comment formatting.
                    126: set s78 \
                    127: {*****************************************************************************}
                    128: 
                    129: # Insert a comment into the code
                    130: #
                    131: proc section_comment {text} {
                    132:   global out s78
                    133:   set n [string length $text]
                    134:   set nstar [expr {60 - $n}]
                    135:   set stars [string range $s78 0 $nstar]
                    136:   puts $out "/************** $text $stars/"
                    137: }
                    138: 
                    139: # Read the source file named $filename and write it into the
                    140: # sqlite3.c output file.  If any #include statements are seen,
                    141: # process them approprately.
                    142: #
                    143: proc copy_file {filename} {
                    144:   global seen_hdr available_hdr out addstatic linemacros
                    145:   set ln 0
                    146:   set tail [file tail $filename]
                    147:   section_comment "Begin file $tail"
                    148:   if {$linemacros} {puts $out "#line 1 \"$filename\""}
                    149:   set in [open $filename r]
                    150:   set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)}
                    151:   set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(}
                    152:   if {[file extension $filename]==".h"} {
                    153:     set declpattern " *$declpattern"
                    154:   }
                    155:   set declpattern ^$declpattern
                    156:   while {![eof $in]} {
                    157:     set line [gets $in]
                    158:     incr ln
                    159:     if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
                    160:       if {[info exists available_hdr($hdr)]} {
                    161:         if {$available_hdr($hdr)} {
                    162:           if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
                    163:             set available_hdr($hdr) 0
                    164:           }
                    165:           section_comment "Include $hdr in the middle of $tail"
                    166:           copy_file tsrc/$hdr
                    167:           section_comment "Continuing where we left off in $tail"
                    168:           if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
                    169:         }
                    170:       } elseif {![info exists seen_hdr($hdr)]} {
                    171:         set seen_hdr($hdr) 1
                    172:         puts $out $line
                    173:       } else {
                    174:         puts $out "/* $line */"
                    175:       }
                    176:     } elseif {[regexp {^#ifdef __cplusplus} $line]} {
                    177:       puts $out "#if 0"
                    178:     } elseif {!$linemacros && [regexp {^#line} $line]} {
                    179:       # Skip #line directives.
                    180:     } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} {
                    181:       regsub {^SQLITE_API } $line {} line
                    182:       if {[regexp $declpattern $line all funcname]} {
                    183:         # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions.
                    184:         # so that linkage can be modified at compile-time.
                    185:         if {[regexp {^sqlite3_} $funcname]} {
                    186:           puts $out "SQLITE_API $line"
                    187:         } else {
                    188:           puts $out "SQLITE_PRIVATE $line"
                    189:         }
                    190:       } elseif {[regexp $varpattern $line all varname]} {
                    191:         # Add the SQLITE_PRIVATE before variable declarations or
                    192:         # definitions for internal use
                    193:         if {![regexp {^sqlite3_} $varname]} {
                    194:           regsub {^extern } $line {} line
                    195:           puts $out "SQLITE_PRIVATE $line"
                    196:         } else {
                    197:           if {[regexp {const char sqlite3_version\[\];} $line]} {
                    198:             set line {const char sqlite3_version[] = SQLITE_VERSION;}
                    199:           }
                    200:           regsub {^SQLITE_EXTERN } $line {} line
                    201:           puts $out "SQLITE_API $line"
                    202:         }
                    203:       } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
                    204:         regsub {^SQLITE_EXTERN } $line {} line
                    205:         puts $out "SQLITE_PRIVATE $line"
                    206:       } elseif {[regexp {^void \(\*sqlite3Os} $line]} {
                    207:         puts $out "SQLITE_PRIVATE $line"
                    208:       } else {
                    209:         puts $out $line
                    210:       }
                    211:     } else {
                    212:       puts $out $line
                    213:     }
                    214:   }
                    215:   close $in
                    216:   section_comment "End of $tail"
                    217: }
                    218: 
                    219: 
                    220: # Process the source files.  Process files containing commonly
                    221: # used subroutines first in order to help the compiler find
                    222: # inlining opportunities.
                    223: #
                    224: foreach file {
                    225:    sqliteInt.h
                    226: 
                    227:    global.c
                    228:    ctime.c
                    229:    status.c
                    230:    date.c
                    231:    os.c
                    232: 
                    233:    fault.c
                    234:    mem0.c
                    235:    mem1.c
                    236:    mem2.c
                    237:    mem3.c
                    238:    mem5.c
                    239:    mutex.c
                    240:    mutex_noop.c
                    241:    mutex_os2.c
                    242:    mutex_unix.c
                    243:    mutex_w32.c
                    244:    malloc.c
                    245:    printf.c
                    246:    random.c
                    247:    utf.c
                    248:    util.c
                    249:    hash.c
                    250:    opcodes.c
                    251: 
                    252:    os_os2.c
                    253:    os_unix.c
                    254:    os_win.c
                    255: 
                    256:    bitvec.c
                    257:    pcache.c
                    258:    pcache1.c
                    259:    rowset.c
                    260:    pager.c
                    261:    wal.c
                    262: 
                    263:    btmutex.c
                    264:    btree.c
                    265:    backup.c
                    266: 
                    267:    vdbemem.c
                    268:    vdbeaux.c
                    269:    vdbeapi.c
                    270:    vdbetrace.c
                    271:    vdbe.c
                    272:    vdbeblob.c
                    273:    vdbesort.c
                    274:    journal.c
                    275:    memjournal.c
                    276: 
                    277:    walker.c
                    278:    resolve.c
                    279:    expr.c
                    280:    alter.c
                    281:    analyze.c
                    282:    attach.c
                    283:    auth.c
                    284:    build.c
                    285:    callback.c
                    286:    delete.c
                    287:    func.c
                    288:    fkey.c
                    289:    insert.c
                    290:    legacy.c
                    291:    loadext.c
                    292:    pragma.c
                    293:    prepare.c
                    294:    select.c
                    295:    table.c
                    296:    trigger.c
                    297:    update.c
                    298:    vacuum.c
                    299:    vtab.c
                    300:    where.c
                    301: 
                    302:    parse.c
                    303: 
                    304:    tokenize.c
                    305:    complete.c
                    306: 
                    307:    main.c
                    308:    notify.c
                    309: 
                    310:    fts3.c
                    311:    fts3_aux.c
                    312:    fts3_expr.c
                    313:    fts3_hash.c
                    314:    fts3_porter.c
                    315:    fts3_tokenizer.c
                    316:    fts3_tokenizer1.c
                    317:    fts3_write.c
                    318:    fts3_snippet.c
                    319: 
                    320:    rtree.c
                    321:    icu.c
                    322:    fts3_icu.c
                    323: } {
                    324:   copy_file tsrc/$file
                    325: }
                    326: 
                    327: close $out

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>