Skip to content

Commit

Permalink
New makefile target "sqlite3-debug.c" builds an amalgamation that inc…
Browse files Browse the repository at this point in the history
…lude

appropriate "#line" macros relating the code back to the original source
files.
  • Loading branch information
D. Richard Hipp committed Aug 15, 2011
1 parent c8874a6 commit fd11ed2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ sqlite3.c: target_source $(TOP)/tool/mksqlite3c.tcl
echo '#endif /* USE_SYSTEM_SQLITE */' >>tclsqlite3.c
cat $(TOP)/src/tclsqlite.c >>tclsqlite3.c

sqlite3-debug.c: target_source $(TOP)/tool/mksqlite3c.tcl
tclsh $(TOP)/tool/mksqlite3c.tcl --linemacros
echo '#ifndef USE_SYSTEM_SQLITE' >tclsqlite3.c
cat sqlite3.c >>tclsqlite3.c
echo '#endif /* USE_SYSTEM_SQLITE */' >>tclsqlite3.c
echo '#line 1 "tclsqlite.c"' >>tclsqlite3.c
cat $(TOP)/src/tclsqlite.c >>tclsqlite3.c

sqlite3-all.c: sqlite3.c $(TOP)/tool/split-sqlite3c.tcl
tclsh $(TOP)/tool/split-sqlite3c.tcl

Expand Down
15 changes: 13 additions & 2 deletions tool/mksqlite3c.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ if {[lsearch $argv --nostatic]>=0} {
} else {
set addstatic 1
}
if {[lsearch $argv --linemacros]>=0} {
set linemacros 1
} else {
set linemacros 0
}
set in [open tsrc/sqlite3.h]
set cnt 0
set VERSION ?????
Expand Down Expand Up @@ -136,9 +141,11 @@ proc section_comment {text} {
# process them approprately.
#
proc copy_file {filename} {
global seen_hdr available_hdr out addstatic
global seen_hdr available_hdr out addstatic linemacros
set ln 0
set tail [file tail $filename]
section_comment "Begin file $tail"
if {$linemacros} {puts $out "#line 1 \"$filename\""}
set in [open $filename r]
set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)}
set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(}
Expand All @@ -148,6 +155,7 @@ proc copy_file {filename} {
set declpattern ^$declpattern
while {![eof $in]} {
set line [gets $in]
incr ln
if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
if {[info exists available_hdr($hdr)]} {
if {$available_hdr($hdr)} {
Expand All @@ -157,14 +165,17 @@ proc copy_file {filename} {
section_comment "Include $hdr in the middle of $tail"
copy_file tsrc/$hdr
section_comment "Continuing where we left off in $tail"
if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
}
} elseif {![info exists seen_hdr($hdr)]} {
set seen_hdr($hdr) 1
puts $out $line
} else {
puts $out "/* $line */"
}
} elseif {[regexp {^#ifdef __cplusplus} $line]} {
puts $out "#if 0"
} elseif {[regexp {^#line} $line]} {
} elseif {!$linemacros && [regexp {^#line} $line]} {
# Skip #line directives.
} elseif {$addstatic && ![regexp {^(static|typedef)} $line]} {
regsub {^SQLITE_API } $line {} line
Expand Down

0 comments on commit fd11ed2

Please sign in to comment.