Annotation of embedaddon/sqlite3/tool/mksqlite3internalh.tcl, revision 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.  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
        !            57:    btreeInt.h
        !            58:    hash.h
        !            59:    hwtime.h
        !            60:    keywordhash.h
        !            61:    opcodes.h
        !            62:    os_common.h
        !            63:    os.h
        !            64:    os_os2.h
        !            65:    pager.h
        !            66:    parse.h
        !            67:    sqlite3ext.h
        !            68:    sqlite3.h
        !            69:    sqliteInt.h
        !            70:    sqliteLimit.h
        !            71:    vdbe.h
        !            72:    vdbeInt.h
        !            73: } {
        !            74:   set available_hdr($hdr) 1
        !            75: }
        !            76: 
        !            77: # 78 stars used for comment formatting.
        !            78: set s78 \
        !            79: {*****************************************************************************}
        !            80: 
        !            81: # Insert a comment into the code
        !            82: #
        !            83: proc section_comment {text} {
        !            84:   global out s78
        !            85:   set n [string length $text]
        !            86:   set nstar [expr {60 - $n}]
        !            87:   set stars [string range $s78 0 $nstar]
        !            88:   puts $out "/************** $text $stars/"
        !            89: }
        !            90: 
        !            91: # Read the source file named $filename and write it into the
        !            92: # sqlite3.c output file.  If any #include statements are seen,
        !            93: # process them approprately.
        !            94: #
        !            95: proc copy_file {filename} {
        !            96:   global seen_hdr available_hdr out
        !            97:   set tail [file tail $filename]
        !            98:   section_comment "Begin file $tail"
        !            99:   set in [open $filename r]
        !           100:   while {![eof $in]} {
        !           101:     set line [gets $in]
        !           102:     if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
        !           103:       if {[info exists available_hdr($hdr)]} {
        !           104:         if {$available_hdr($hdr)} {
        !           105:           section_comment "Include $hdr in the middle of $tail"
        !           106:           copy_file tsrc/$hdr
        !           107:           section_comment "Continuing where we left off in $tail"
        !           108:         }
        !           109:       } elseif {![info exists seen_hdr($hdr)]} {
        !           110:         set seen_hdr($hdr) 1
        !           111:         puts $out $line
        !           112:       }
        !           113:     } elseif {[regexp {^#ifdef __cplusplus} $line]} {
        !           114:       puts $out "#if 0"
        !           115:     } elseif {[regexp {^#line} $line]} {
        !           116:       # Skip #line directives.
        !           117:     } else {
        !           118:       puts $out $line
        !           119:     }
        !           120:   }
        !           121:   close $in
        !           122:   section_comment "End of $tail"
        !           123: }
        !           124: 
        !           125: 
        !           126: # Process the source files.  Process files containing commonly
        !           127: # used subroutines first in order to help the compiler find
        !           128: # inlining opportunities.
        !           129: #
        !           130: foreach file {
        !           131:    sqliteInt.h
        !           132:    sqlite3.h
        !           133:    btree.h
        !           134:    hash.h
        !           135:    os.h
        !           136:    pager.h
        !           137:    parse.h
        !           138:    sqlite3ext.h
        !           139:    vdbe.h
        !           140: } {
        !           141:   if {$available_hdr($file)} {
        !           142:     copy_file tsrc/$file
        !           143:   }
        !           144: }
        !           145: 
        !           146: close $out

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