2016-02-23 15:07:39 +00:00
# !/usr/bin/tcl
#
# This script reads the regular MSVC makefile (../Makefile.msc) and outputs
# a revised version of that Makefile that is "minimal" in the sense that
# it uses the sqlite3.c amalgamation as input and does not require tclsh.
# The resulting "../Makefile.min.msc" is suitable for use in the amalgamation
# tarballs.
#
if { $argc == 0 } {
set basedir [ file dir [ file dir [ file normalize $argv0 ] ] ]
set fromFileName [ file join $basedir Makefile.msc]
set toFileName [ file join $basedir autoconf Makefile.msc]
} else {
set fromFileName [ lindex $argv 0 ]
if { ! [ file exists $fromFileName ] } {
error " i n p u t f i l e \" $ f r o m F i l e N a m e \" d o e s n o t e x i s t "
}
set toFileName [ lindex $argv 1 ]
if { [ file exists $toFileName ] } {
error " o u t p u t f i l e \" $ t o F i l e N a m e \" a l r e a d y e x i s t s "
}
}
proc readFile { fileName } {
set file_id [ open $fileName RDONLY]
fconfigure $file_id - encoding binary - translation binary
set result [ read $file_id ]
close $file_id
return $result
}
proc writeFile { fileName data } {
set file_id [ open $fileName { WRONLY CREAT TRUNC} ]
fconfigure $file_id - encoding binary - translation binary
puts - nonewline $file_id $data
close $file_id
return " "
}
proc escapeSubSpec { data } {
regsub - all - - { & } $data { \ \ \ & } data
regsub - all - - { \ \ ( \ d + ) } $data { \ \ \ \ \ 1 } data
return $data
}
proc substVars { data } {
return [ uplevel 1 [ list subst - nocommands - nobackslashes $data ] ]
}
#
# NOTE: This block is used to replace the section marked <<block1>> in
# the Makefile, if it exists.
#
set blocks( 1 ) [ string trimleft [ string map [ list \ \ \ \ \ \ ] {
_HASHCHAR = ^ #
! IF ! [ echo ! IFNDEF VERSION > rcver.vc] && \ \
2018-09-18 16:31:37 +00:00
! [ for / F " d e l i m s = " % V in ( ' type " $ ( S Q L I T E 3 H ) " ^ | " % S y s t e m R o o t % \S y s t e m 3 2 \f i n d . e x e " " $ ( _ H A S H C H A R ) d e f i n e S Q L I T E _ V E R S I O N " ' ) do ( echo VERSION = ^ ^ % V >> rcver.vc) ] && \ \
2016-02-23 15:07:39 +00:00
! [ echo ! ENDIF >> rcver.vc]
! INCLUDE rcver.vc
! ENDIF
RESOURCE_VERSION = $ ( VERSION : ^ # = )
RESOURCE_VERSION = $ ( RESOURCE_VERSION : define= )
RESOURCE_VERSION = $ ( RESOURCE_VERSION : SQLITE_VERSION= )
RESOURCE_VERSION = $ ( RESOURCE_VERSION : " = )
RESOURCE_VERSION = $ ( RESOURCE_VERSION : .= , )
$ ( LIBRESOBJS ) : $ ( TOP ) \ sqlite3.rc rcver.vc $ ( SQLITE3H )
echo # ifndef SQLITE_RESOURCE_VERSION > sqlite3rc.h
echo # define SQLITE_RESOURCE_VERSION $ ( RESOURCE_VERSION ) >> sqlite3rc.h
echo # endif >> sqlite3rc.h
$ ( LTRCOMPILE ) -fo $ ( LIBRESOBJS ) - DRC_VERONLY $ ( TOP ) \ sqlite3.rc
} ] ]
2016-12-05 20:29:15 +00:00
#
# NOTE: This block is used to replace the section marked <<block2>> in
# the Makefile, if it exists.
#
set blocks( 2 ) [ string trimleft [ string map [ list \ \ \ \ \ \ ] {
Replace.exe :
$ ( CSC ) / target : exe $ ( TOP ) \ Replace.cs
sqlite3.def : Replace.exe $ ( LIBOBJ )
echo EXPORTS > sqlite3.def
dumpbin / all $ ( LIBOBJ ) \ \
2018-09-18 16:31:37 +00:00
| . \ Replace.exe " ^ \s + / E X P O R T : _ ? ( s q l i t e 3 ( ? : s e s s i o n | c h a n g e s e t | c h a n g e g r o u p | r e b a s e r ) ? _ [ ^ @ , ] * ) ( ? : @ \d + | , D A T A ) ? $ $ " $ $1 true \ \
2016-12-05 20:29:15 +00:00
| sort >> sqlite3.def
} ] ]
2016-02-23 15:07:39 +00:00
set data " # # # # D O N O T E D I T # # # # \n "
append data " # T h i s m a k e f i l e i s a u t o m a t i c a l l y "
append data " g e n e r a t e d f r o m t h e [ f i l e t a i l $ f r o m F i l e N a m e ] a t \n "
append data " # t h e r o o t o f t h e c a n o n i c a l S Q L i t e s o u r c e t r e e ( n o t t h e \n "
append data " # a m a l g a m a t i o n t a r b a l l ) u s i n g t h e t o o l / [ f i l e t a i l $ a r g v 0 ] \n "
append data " # s c r i p t . \n # \n \n "
append data [ readFile $fromFileName ]
regsub - all - - { # <<mark>>\n.*?# <</mark>>\n} \
$data " " data
foreach i [ lsort - integer [ array names blocks] ] {
regsub - all - - [ substVars \
{ # <<block${i}>>\n.*?# <</block${i}>>\n}] \
$data [ escapeSubSpec $blocks ( $i ) ] data
}
set data [ string map [ list " - I \$ ( T O P ) \\ s r c " " " ] $data ]
2016-12-05 20:29:15 +00:00
set data [ string map [ list " l i b s q l i t e 3 . l i b " " " ] $data ]
2016-02-23 15:07:39 +00:00
set data [ string map [ list " \$ ( A L L _ T C L _ T A R G E T S ) " " " ] $data ]
set data [ string map [ list " \$ ( T O P ) \\ s r c \\ " " \$ ( T O P ) \\ " ] $data ]
writeFile $toFileName $data