2016-01-23 10:53:04 +03:00
# !/usr/bin/tcl
#
2016-01-23 22:47:00 +03:00
# 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.
2016-01-23 23:16:40 +03:00
#
2016-01-23 22:47:00 +03:00
if { $argc == 0 } {
set basedir [ file dir [ file dir [ file normalize $argv0 ] ] ]
set fromFileName [ file join $basedir Makefile.msc]
2016-01-23 23:34:27 +03:00
set toFileName [ file join $basedir autoconf Makefile.msc]
2016-01-23 22:47:00 +03:00
} else {
set fromFileName [ lindex $argv 0 ]
2016-01-23 23:16:40 +03:00
if { ! [ file exists $fromFileName ] } {
2016-01-23 22:47:00 +03:00
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 ]
2016-01-23 23:16:40 +03:00
if { [ file exists $toFileName ] } {
2016-01-23 22:47:00 +03:00
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 "
}
2016-01-23 10:53:04 +03:00
}
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
}
2016-01-23 22:47:00 +03:00
2016-01-23 10:53:04 +03:00
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 " "
}
2016-01-23 22:47:00 +03:00
2016-01-23 10:53:04 +03:00
proc escapeSubSpec { data } {
regsub - all - - { & } $data { \ \ \ & } data
regsub - all - - { \ \ ( \ d + ) } $data { \ \ \ \ \ 1 } data
return $data
}
2016-01-23 22:47:00 +03:00
2016-01-23 10:53:04 +03:00
proc substVars { data } {
return [ uplevel 1 [ list subst - nocommands - nobackslashes $data ] ]
}
2016-01-23 22:47:00 +03:00
2016-01-23 10:53:04 +03:00
#
# 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] && \ \
2017-10-25 00:17:12 +03: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-01-23 10:53:04 +03: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-01-23 22:47:00 +03:00
2016-02-27 02:13:16 +03: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 ) \ \
2019-12-20 20:41:15 +03: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 | r b u ) ? _ [ ^ @ , ] * ) ( ? : @ \d + | , D A T A ) ? $ $ " $ $1 true \ \
2016-02-27 02:13:16 +03:00
| sort >> sqlite3.def
} ] ]
2016-01-23 22:47:00 +03: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 "
2016-01-23 23:34:27 +03:00
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 "
2016-01-23 22:47:00 +03:00
append data [ readFile $fromFileName ]
2016-01-23 10:53:04 +03:00
regsub - all - - { # <<mark>>\n.*?# <</mark>>\n} \
$data " " data
2016-01-23 22:24:19 +03:00
foreach i [ lsort - integer [ array names blocks] ] {
2016-01-23 10:53:04 +03:00
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-02-19 08:07:56 +03:00
set data [ string map [ list " l i b s q l i t e 3 . l i b " " " ] $data ]
2016-01-27 10:28:33 +03:00
set data [ string map [ list " \$ ( A L L _ T C L _ T A R G E T S ) " " " ] $data ]
2016-01-23 10:53:04 +03:00
set data [ string map [ list " \$ ( T O P ) \\ s r c \\ " " \$ ( T O P ) \\ " ] $data ]
writeFile $toFileName $data