Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aptavout
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aptavout/32709625a2ef9837ec08 to your computer and use it in GitHub Desktop.
Save aptavout/32709625a2ef9837ec08 to your computer and use it in GitHub Desktop.
The Holy Grail of small-scale solutions
# a Tcl script to automate builds
# instructions from http://wiki.tcl.tk/11861
# using tclkit.exe and sdx.kit from Google Code
# https://code.google.com/p/tclkit/downloads/list
# *** as well as TWAPI binaries ***
#
# Copy your source files into a work directory !!
#
# usage: tclsh this-script.tcl gui.tcl
#
set sdx "sdx-20110317.kit"; # the current sdx version
set tclkit "tclkitsh-8.5.9-win32.upx.exe"; # the current tclkit.exe
set runtimekit "tclkit-gui-8_6_1-x86-max.exe"; # the runtime tclkit.exe
set respath "$env(TCLRESPATH)\\tclkit"; # resource path
if {$argc < 1} {
puts "error: specify source Tcl file to compile into an .exe"
exit 1
}
set tclsrc [lindex $argv 0]
set barename [string range "$tclsrc" 0 \
[expr {[string first . "$tclsrc"] - 1}]]; # to use with xxx.kit
if {[file exists "$tclsrc"] == 0} {
puts "error: $tclsrc doesn't exist in [pwd]"
exit 2
}
puts "The current directory is [pwd]"
puts "The Tcl source file is $tclsrc"
puts "The bare file name is $barename"
# Step 1 from wiki
puts "Step 1. Copy the .kit and tclkit.exe files"
if {[file exists "[pwd]\\$sdx"] == 0} {
file copy "$respath\\$sdx" [pwd]
puts "$sdx does not exist. Copied."
} else {
puts "$sdx already exists."
}
if {[file exists "[pwd]\\$tclkit"] == 0} {
file copy "$respath\\$tclkit" [pwd]
puts "$tclkit does not exist. Copied."
} else {
puts "$tclkit already exists."
}
if {[file exists "$runtimekit"] == 0} {
file copy "$respath\\$runtimekit" [pwd]
puts "$runtimekit does not exist. Copied."
} else {
puts "$runtimekit already exists."
}
# this step is no longer needed; we use tclsh to compile and tcl (non-sh) as
# runtime
puts "Step 2. tclkit2 (skip)"
#puts "Step 2. tclkit2"
#file copy -force "$tclkit" "[pwd]\\tclkit2.exe"
puts "Step 3. qwrap"
exec [pwd]\\$tclkit $sdx qwrap $tclsrc
puts "Step 4. unwrap"
exec [pwd]\\$tclkit $sdx unwrap $barename.kit
# - create a new main.tcl in the vfs dir
# - copy dependencies to vfs
puts -nonewline "Creating new main.tcl file..."
set fh [open "[pwd]\\$barename.vfs\\main.tcl" w]
puts $fh "package require starkit"
puts $fh "starkit::startup"
puts $fh "package require TclOO"
puts $fh "# via tclsh> package ifneeded tdbc"
puts $fh {source [file join [file dirname [info script]] lib/tdbc1.0.0/tdbc.tcl]}
puts $fh {load [file join [file dirname [info script]] lib/tdbc1.0.0/tdbc100.dll] tdbc}
puts $fh "# via tclsh> package ifneeded tdbc::odbc 1.0"
puts $fh {source [file join [file dirname [info script]] lib/tdbc_odbc1.0.0/tdbcodbc.tcl]}
puts $fh {load [file join [file dirname [info script]] lib/tdbc_odbc1.0.0/tdbcodbc100.dll] tdbcodbc}
puts $fh "package require app-$barename"
close $fh
puts "ok"
# copy tdbc stuff to $barename.vfs/lib
file copy "c:/tcl/lib/teapot/package/win32-ix86/lib/tdbc1.0.0" \
"$barename.vfs/lib"
file copy "c:/tcl/lib/teapot/package/win32-ix86/lib/tdbc_odbc1.0.0" \
"$barename.vfs/lib"
# These files you copied into your work directory will be copied into
# the virtual filesystem (.vfs folder)
puts -nonewline "Copying dependencies to vfs..."
file copy "[pwd]\\controller.tcl" \
"$barename.vfs\\lib\\app-$barename"
file copy "[pwd]\\dao.tcl" \
"$barename.vfs\\lib\\app-$barename"
file copy "[pwd]\\jnc-combobox.tcl" \
"$barename.vfs\\lib\\app-$barename"
puts "ok"
cd "$barename.vfs\\lib\\app-$barename"
puts "Changed to [pwd]"
puts "Make package index..."
pkg_mkIndex [pwd]
cd "../../../"
puts "Changed back to [pwd]"
# Step 5. Copy icons (skip)
puts "Step 5. icon (skip)"
puts "Step 6. wrap"
exec [pwd]\\$tclkit $sdx wrap $barename -runtime $runtimekit
puts "Step 7. rename with .exe"
#file rename $barename $barename.exe
file rename $barename $barename.exe
puts "Done! Standalone .exe created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment