Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/tool/mkmsvcmin.tcl # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / tool / mkmsvcmin.tcl` 113 lines ยท 3736 bytes Raw Blame History 1 #!/usr/bin/tcl 2 # 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. 8 # 9 if {$argc==0} { 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] 13 } else { 14 set fromFileName [lindex $argv 0] 15 if {![file exists $fromFileName]} { 16 error "input file \"$fromFileName\" does not exist" 17 } 18 set toFileName [lindex $argv 1] 19 if {[file exists $toFileName]} { 20 error "output file \"$toFileName\" already exists" 21 } 22 } 23 24 proc readFile { fileName } { 25 set file_id [open $fileName RDONLY] 26 fconfigure $file_id -translation binary 27 set result [read $file_id] 28 close $file_id 29 return $result 30 } 31 32 proc writeFile { fileName data } { 33 set file_id [open $fileName {WRONLY CREAT TRUNC}] 34 fconfigure $file_id -translation binary 35 puts -nonewline $file_id $data 36 close $file_id 37 return "" 38 } 39 40 proc escapeSubSpec { data } { 41 regsub -all -- {&} $data {\\\&} data 42 regsub -all -- {\\(\d+)} $data {\\\\\1} data 43 return $data 44 } 45 46 proc substVars { data } { 47 return [uplevel 1 [list subst -nocommands -nobackslashes $data]] 48 } 49 50 # 51 # NOTE: This block is used to replace the section marked <> 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] && \\ 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] 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 }]] 74 75 # 76 # NOTE: This block is used to replace the section marked <> 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) \\ 86 | .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup|rebaser|rbu)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \\ 87 | sort >> sqlite3.def 88 }]] 89 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] 97 98 regsub -all -- {# <>\n.*?# <>\n} \ 99 $data "" data 100 101 foreach i [lsort -integer [array names blocks]] { 102 regsub -all -- [substVars \ 103 {# <>\n.*?# <>\n}] \ 104 $data [escapeSubSpec $blocks($i)] data 105 } 106 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] 111 112 writeFile $toFileName $data 113 puts "generated $toFileName from $fromFileName"