blob: ef948a05c901b0c67f8965065642939ef546f2a1 [file] [log] [blame]
mistachkin3e786092016-01-23 07:53:04 +00001#!/usr/bin/tcl
2#
drh06cee482016-01-23 19:47:00 +00003# 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.
mistachkin4a255492016-01-23 20:16:40 +00008#
drh06cee482016-01-23 19:47:00 +00009if {$argc==0} {
10 set basedir [file dir [file dir [file normalize $argv0]]]
11 set fromFileName [file join $basedir Makefile.msc]
drh021f9a62016-01-23 20:34:27 +000012 set toFileName [file join $basedir autoconf Makefile.msc]
drh06cee482016-01-23 19:47:00 +000013} else {
14 set fromFileName [lindex $argv 0]
mistachkin4a255492016-01-23 20:16:40 +000015 if {![file exists $fromFileName]} {
drh06cee482016-01-23 19:47:00 +000016 error "input file \"$fromFileName\" does not exist"
17 }
18 set toFileName [lindex $argv 1]
mistachkin4a255492016-01-23 20:16:40 +000019 if {[file exists $toFileName]} {
drh06cee482016-01-23 19:47:00 +000020 error "output file \"$toFileName\" already exists"
21 }
mistachkin3e786092016-01-23 07:53:04 +000022}
mistachkin3e786092016-01-23 07:53:04 +000023
mistachkin3e786092016-01-23 07:53:04 +000024proc 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}
drh06cee482016-01-23 19:47:00 +000031
mistachkin3e786092016-01-23 07:53:04 +000032proc 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}
drh06cee482016-01-23 19:47:00 +000039
mistachkin3e786092016-01-23 07:53:04 +000040proc escapeSubSpec { data } {
41 regsub -all -- {&} $data {\\\&} data
42 regsub -all -- {\\(\d+)} $data {\\\\\1} data
43 return $data
44}
drh06cee482016-01-23 19:47:00 +000045
mistachkin3e786092016-01-23 07:53:04 +000046proc substVars { data } {
47 return [uplevel 1 [list subst -nocommands -nobackslashes $data]]
48}
drh06cee482016-01-23 19:47:00 +000049
mistachkin3e786092016-01-23 07:53:04 +000050#
51# NOTE: This block is used to replace the section marked <<block1>> in
52# the Makefile, if it exists.
53#
54set blocks(1) [string trimleft [string map [list \\\\ \\] {
55_HASHCHAR=^#
56!IF ![echo !IFNDEF VERSION > rcver.vc] && \\
mistachkinea78f642017-10-24 21:17:12 +000057 ![for /F "delims=" %V in ('type "$(SQLITE3H)" ^| "%SystemRoot%\System32\find.exe" "$(_HASHCHAR)define SQLITE_VERSION "') do (echo VERSION = ^^%V >> rcver.vc)] && \\
mistachkin3e786092016-01-23 07:53:04 +000058 ![echo !ENDIF >> rcver.vc]
59!INCLUDE rcver.vc
60!ENDIF
61
62RESOURCE_VERSION = $(VERSION:^#=)
63RESOURCE_VERSION = $(RESOURCE_VERSION:define=)
64RESOURCE_VERSION = $(RESOURCE_VERSION:SQLITE_VERSION=)
65RESOURCE_VERSION = $(RESOURCE_VERSION:"=)
66RESOURCE_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}]]
drh06cee482016-01-23 19:47:00 +000074
mistachkin9aeb9712016-02-26 23:13:16 +000075#
76# NOTE: This block is used to replace the section marked <<block2>> in
77# the Makefile, if it exists.
78#
79set blocks(2) [string trimleft [string map [list \\\\ \\] {
80Replace.exe:
81 $(CSC) /target:exe $(TOP)\Replace.cs
82
83sqlite3.def: Replace.exe $(LIBOBJ)
84 echo EXPORTS > sqlite3.def
85 dumpbin /all $(LIBOBJ) \\
mistachkine99cb2d2019-12-20 17:41:15 +000086 | .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup|rebaser|rbu)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \\
mistachkin9aeb9712016-02-26 23:13:16 +000087 | sort >> sqlite3.def
88}]]
89
drh06cee482016-01-23 19:47:00 +000090set data "#### DO NOT EDIT ####\n"
91append data "# This makefile is automatically "
92append data "generated from the [file tail $fromFileName] at\n"
drh021f9a62016-01-23 20:34:27 +000093append data "# the root of the canonical SQLite source tree (not the\n"
94append data "# amalgamation tarball) using the tool/[file tail $argv0]\n"
95append data "# script.\n#\n\n"
drh06cee482016-01-23 19:47:00 +000096append data [readFile $fromFileName]
mistachkin3e786092016-01-23 07:53:04 +000097
98regsub -all -- {# <<mark>>\n.*?# <</mark>>\n} \
99 $data "" data
100
mistachkin408273e2016-01-23 19:24:19 +0000101foreach i [lsort -integer [array names blocks]] {
mistachkin3e786092016-01-23 07:53:04 +0000102 regsub -all -- [substVars \
103 {# <<block${i}>>\n.*?# <</block${i}>>\n}] \
104 $data [escapeSubSpec $blocks($i)] data
105}
106
107set data [string map [list " -I\$(TOP)\\src" ""] $data]
mistachkinb0c99af2016-02-19 05:07:56 +0000108set data [string map [list " libsqlite3.lib" ""] $data]
mistachkind5be6f02016-01-27 07:28:33 +0000109set data [string map [list " \$(ALL_TCL_TARGETS)" ""] $data]
mistachkin3e786092016-01-23 07:53:04 +0000110set data [string map [list "\$(TOP)\\src\\" "\$(TOP)\\"] $data]
111
112writeFile $toFileName $data