mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 1 | #!/usr/bin/tcl |
| 2 | # |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 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 |
| 7 | # tarballs. |
mistachkin | 4a25549 | 2016-01-23 20:16:40 +0000 | [diff] [blame] | 8 | # |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 9 | if {$argc==0} { |
| 10 | set basedir [file dir [file dir [file normalize $argv0]]] |
| 11 | set fromFileName [file join $basedir Makefile.msc] |
drh | 021f9a6 | 2016-01-23 20:34:27 +0000 | [diff] [blame] | 12 | set toFileName [file join $basedir autoconf Makefile.msc] |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 13 | } else { |
| 14 | set fromFileName [lindex $argv 0] |
mistachkin | 4a25549 | 2016-01-23 20:16:40 +0000 | [diff] [blame] | 15 | if {![file exists $fromFileName]} { |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 16 | error "input file \"$fromFileName\" does not exist" |
| 17 | } |
| 18 | set toFileName [lindex $argv 1] |
mistachkin | 4a25549 | 2016-01-23 20:16:40 +0000 | [diff] [blame] | 19 | if {[file exists $toFileName]} { |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 20 | error "output file \"$toFileName\" already exists" |
| 21 | } |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 22 | } |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 23 | |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 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] |
| 28 | close $file_id |
| 29 | return $result |
| 30 | } |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 31 | |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 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 |
| 36 | close $file_id |
| 37 | return "" |
| 38 | } |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 39 | |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 40 | proc escapeSubSpec { data } { |
| 41 | regsub -all -- {&} $data {\\\&} data |
| 42 | regsub -all -- {\\(\d+)} $data {\\\\\1} data |
| 43 | return $data |
| 44 | } |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 45 | |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 46 | proc substVars { data } { |
| 47 | return [uplevel 1 [list subst -nocommands -nobackslashes $data]] |
| 48 | } |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 49 | |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 50 | # |
| 51 | # NOTE: This block is used to replace the section marked <<block1>> in |
| 52 | # the Makefile, if it exists. |
| 53 | # |
| 54 | set blocks(1) [string trimleft [string map [list \\\\ \\] { |
| 55 | _HASHCHAR=^# |
| 56 | !IF ![echo !IFNDEF VERSION > rcver.vc] && \\ |
mistachkin | ea78f64 | 2017-10-24 21:17:12 +0000 | [diff] [blame] | 57 | ![for /F "delims=" %V in ('type "$(SQLITE3H)" ^| "%SystemRoot%\System32\find.exe" "$(_HASHCHAR)define SQLITE_VERSION "') do (echo VERSION = ^^%V >> rcver.vc)] && \\ |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 58 | ![echo !ENDIF >> rcver.vc] |
| 59 | !INCLUDE rcver.vc |
| 60 | !ENDIF |
| 61 | |
| 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:.=,) |
| 67 | |
| 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 |
| 73 | }]] |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 74 | |
mistachkin | 9aeb971 | 2016-02-26 23:13:16 +0000 | [diff] [blame] | 75 | # |
| 76 | # NOTE: This block is used to replace the section marked <<block2>> in |
| 77 | # the Makefile, if it exists. |
| 78 | # |
| 79 | set blocks(2) [string trimleft [string map [list \\\\ \\] { |
| 80 | Replace.exe: |
| 81 | $(CSC) /target:exe $(TOP)\Replace.cs |
| 82 | |
| 83 | sqlite3.def: Replace.exe $(LIBOBJ) |
| 84 | echo EXPORTS > sqlite3.def |
| 85 | dumpbin /all $(LIBOBJ) \\ |
mistachkin | e99cb2d | 2019-12-20 17:41:15 +0000 | [diff] [blame] | 86 | | .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup|rebaser|rbu)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \\ |
mistachkin | 9aeb971 | 2016-02-26 23:13:16 +0000 | [diff] [blame] | 87 | | sort >> sqlite3.def |
| 88 | }]] |
| 89 | |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 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" |
drh | 021f9a6 | 2016-01-23 20:34:27 +0000 | [diff] [blame] | 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" |
drh | 06cee48 | 2016-01-23 19:47:00 +0000 | [diff] [blame] | 96 | append data [readFile $fromFileName] |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 97 | |
| 98 | regsub -all -- {# <<mark>>\n.*?# <</mark>>\n} \ |
| 99 | $data "" data |
| 100 | |
mistachkin | 408273e | 2016-01-23 19:24:19 +0000 | [diff] [blame] | 101 | foreach i [lsort -integer [array names blocks]] { |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 102 | regsub -all -- [substVars \ |
| 103 | {# <<block${i}>>\n.*?# <</block${i}>>\n}] \ |
| 104 | $data [escapeSubSpec $blocks($i)] data |
| 105 | } |
| 106 | |
| 107 | set data [string map [list " -I\$(TOP)\\src" ""] $data] |
mistachkin | b0c99af | 2016-02-19 05:07:56 +0000 | [diff] [blame] | 108 | set data [string map [list " libsqlite3.lib" ""] $data] |
mistachkin | d5be6f0 | 2016-01-27 07:28:33 +0000 | [diff] [blame] | 109 | set data [string map [list " \$(ALL_TCL_TARGETS)" ""] $data] |
mistachkin | 3e78609 | 2016-01-23 07:53:04 +0000 | [diff] [blame] | 110 | set data [string map [list "\$(TOP)\\src\\" "\$(TOP)\\"] $data] |
| 111 | |
| 112 | writeFile $toFileName $data |