3 # This script reads the regular MSVC makefile (../Makefile.msc) and outputs
4 # a revised version of that Makefile that is "minimal" in the sense that
5 # it uses the sqlite3.c amalgamation as input and does not require tclsh.
6 # The resulting "../Makefile.min.msc" is suitable for use in the amalgamation
10 set basedir
[file dir
[file dir
[file normalize
$argv0]]]
11 set fromFileName
[file join $basedir Makefile.msc
]
12 set toFileName
[file join $basedir autoconf Makefile.msc
]
14 set fromFileName
[lindex $argv 0]
15 if {![file exists
$fromFileName]} {
16 error "input file \"$fromFileName\" does not exist"
18 set toFileName
[lindex $argv 1]
19 if {[file exists
$toFileName]} {
20 error "output file \"$toFileName\" already exists"
24 proc readFile
{ fileName
} {
25 set file_id
[open $fileName RDONLY
]
26 fconfigure $file_id -encoding binary -translation binary
27 set result
[read $file_id]
32 proc writeFile
{ fileName data
} {
33 set file_id
[open $fileName {WRONLY CREAT TRUNC
}]
34 fconfigure $file_id -encoding binary -translation binary
35 puts -nonewline $file_id $data
40 proc escapeSubSpec
{ data
} {
41 regsub -all -- {&} $data {\\\&} data
42 regsub -all -- {\\(\d
+)} $data {\\\\\1} data
46 proc substVars
{ data
} {
47 return [uplevel 1 [list subst -nocommands -nobackslashes $data]]
51 # NOTE: This block is used to replace the section marked <<block1>> in
52 # the Makefile, if it exists.
54 set blocks
(1) [string trimleft
[string map
[list \\\\ \\] {
56 !IF
![echo
!IFNDEF VERSION
> rcver.vc
] && \\
57 ![for /F
"delims=" %V in
('type
"$(SQLITE3H)" ^|
"%SystemRoot%\System32\find.exe" "$(_HASHCHAR)define SQLITE_VERSION "'
) do
(echo VERSION
= ^^
%V
>> rcver.vc
)] && \\
58 ![echo
!ENDIF
>> rcver.vc
]
62 RESOURCE_VERSION
= $(VERSION
:^
#=)
63 RESOURCE_VERSION
= $(RESOURCE_VERSION
:define
=)
64 RESOURCE_VERSION
= $(RESOURCE_VERSION
:SQLITE_VERSION
=)
65 RESOURCE_VERSION
= $(RESOURCE_VERSION
:"=)
66 RESOURCE_VERSION = $(RESOURCE_VERSION:.=,)
68 $(LIBRESOBJS): $(TOP)\sqlite3.rc rcver.vc $(SQLITE3H)
69 echo #ifndef SQLITE_RESOURCE_VERSION > sqlite3rc.h
70 echo #define SQLITE_RESOURCE_VERSION $(RESOURCE_VERSION) >> sqlite3rc.h
71 echo #endif >> sqlite3rc.h
72 $(LTRCOMPILE) -fo $(LIBRESOBJS) -DRC_VERONLY $(TOP)\sqlite3.rc
76 # NOTE: This block is used to replace the section marked <<block2>> in
77 # the Makefile, if it exists.
79 set blocks(2) [string trimleft [string map [list \\\\ \\] {
81 $(CSC) /target:exe $(TOP)\Replace.cs
83 sqlite3.def: Replace.exe $(LIBOBJ)
84 echo EXPORTS > sqlite3.def
85 dumpbin /all $(LIBOBJ) \\
86 | .\Replace.exe "^
\s
+/EXPORT
:_?
(sqlite3
(?
:session|changeset|changegroup|rebaser|rbu
)?_
[^
@,]*)(?
:@\d
+|
,DATA
)?
$$" $$1 true \\
90 set data "#### DO NOT EDIT ####\n"
91 append data
"# This makefile is automatically "
92 append data
"generated from the [file tail $fromFileName] at\n"
93 append data
"# the root of the canonical SQLite source tree (not the\n"
94 append data
"# amalgamation tarball) using the tool/[file tail $argv0]\n"
95 append data
"# script.\n#\n\n"
96 append data
[readFile
$fromFileName]
98 regsub -all -- {# <<mark>>\n.*?# <</mark>>\n} \
101 foreach i
[lsort -integer [array names blocks
]] {
102 regsub -all -- [substVars
\
103 {# <<block${i}>>\n.*?# <</block${i}>>\n}] \
104 $data [escapeSubSpec
$blocks($i)] data
107 set data
[string map
[list " -I\$(TOP)\\src" ""] $data]
108 set data
[string map
[list " libsqlite3.lib" ""] $data]
109 set data
[string map
[list " \$(ALL_TCL_TARGETS)" ""] $data]
110 set data
[string map
[list "\$(TOP)\\src\\" "\$(TOP)\\"] $data]
112 writeFile
$toFileName $data
113 puts "generated $toFileName from $fromFileName"