Updated 2013-03-27 06:01:26 by pooryorick

Summary  edit

Steps to create a basic starpack

Description  edit

The following instructions assume a simple application called "example.tcl" which exists in the current directory:
package require Tk
pack [button .b -text "That's all for now" -command exit]

The process is straightforward enough that these instructions can be used with applications which involve several auxiliary files, extensions (but only stubsified ones?), and so on.

Read Beyond TclKit - Starkits, Starpacks and other *stuff pdf EPUB, by Steve Landers

Download a tclkit for your platform. For Windows, download both the gui-version (e.g., tclkit-win32.upx.exe) and the command-line version (e.g., tclkitsh-win32.upx.exe). The command-line version is silent and does not produce pop-up screens, so it can be used to script the generation your executable. The gui-version should be used when you specify the run-time tool in the final step when you link your script, otherwise your application will be silent too ;-).

Download sdx

Install tclkit and it's available in your PATH. On Unix, these may be installed as tclkit and sdx, while on Windows, these are more likely installed as tclkit.exe and sdx.kit. On Unix, remember to change the permission modes of tclkit to be executable. Put sdx.kit in your working directory.

To turn the example.tcl into a starkit on a Unixy system:
tclkit sdx.kit qwrap example.tcl

or
tclkit sdx qwrap example.tcl

On a Windows system:
tclkitsh-win32.upx.exe sdx.kit qwrap example.tcl

This should create example.kit, which is a starkit. In this form, it would still be necessary to invoke it with a Tclkit or with some other starkit-aware Tcl interpreter. On Windows, this step will create an additional file called example.bat.

Unwrap the example.kit that was just created:

Unixy:
tclkit sdx.kit unwrap example.kit

Windows:
tclkitsh-win32.upx.exe sdx.kit unwrap example.kit

A directory called example.vfs should now exist. It contains the contents of the starkit - a set of files laid out in a particular directory structure.

sdx can't copy an in-use tclkit into the starpack, so if necessary, create a copy, i.e., tclkitsh-win32.upx.copy.exe. The following steps assume that the copy is in the current directory.

Use sdx to make a starpack from this starkit.

Unixy:
tclkit sdx.kit wrap example -runtime tclkitcopy

Windows:
tclkitsh-win32.upx.exe sdx.kit wrap example.exe -runtime tclkit-win32.upx.copy.exe

if the Tclkit is not in the current directory, the examples above should be changed so that the argument to -runtime is a path to the needed Tclkit

Of course, on Unix-like systems, you will eventually learn that if you have your environment set properly, and sdx.kit permission modes set to execute, then you will be able to skip that initial word of the command and abbreviate things to:
sdx.kit wrap example -runtime tclkitcopy
sdx wrap example -runtime tclkitcopy

The Script  edit

The following script is an implementation of the instructions on this page, and can be used to automate the process:
#
# Creation of executables ("starpacks") that can run standalone starting from a TCL-script:
#
# Call: tcl2exe <tclscript> <platform>
#
# where the name of the TCL-script is given without extension, 
# and where <platform> is either linux or MinGW
#
# result: an executable named <tclscript>.exe
#
TCLScript=$1
Platform=$2
#
# Set the tools:
#
case $Platform in
#
  linux )
#
mytclkit=./tclkit-linux-x86
myruntime=$mytclkit
    ;;
#
  MinGW )
#
mytclkit=./tclkitsh-win32.upx.exe
myruntime=./tclkit-win32.upx.exe
    ;;
esac
#
# Construct executable:
#
$mytclkit sdx.kit qwrap $TCLScript.tcl
$mytclkit sdx.kit unwrap $TCLScript.kit
cp $myruntime tclkitcopy.exe
$mytclkit sdx.kit wrap $TCLScript.exe -runtime tclkitcopy.exe
#
# Clean up the dirt:
#
rm tclkitcopy.exe
rm $TCLScript.kit
rm -rf $TCLScript.vfs 
#

Misc  edit

Just a note of clarification - if I am on, say, Windows, I can take a cross platform example.kit (assuming that in fact I created it as cross-platform), specify a tclkit for Solaris, or HP/UX, Linux, MacOS X, etc. and have as a result a starpack stand alone executable for that platform.

If, however, my starkit has platform specific components - compiled extensions, special platform-specific commands, etc. - then the starkit application is going to need to be updated to work on all the platforms for which I want to create starpacks.

JOB: Assuming one might have created a subdirectory (registered in auto_path) say "dynlib" to hold all required platform specific dynamic loadable libraries, the following dispatcher code can be used to choose the OS dependent binary "on the fly":
# pkgIndex.tcl ---
# Tcl package index file.
# -------------------------------------------------------------------------
# Created by: Johann Oberdorfer
# This source file is distributed under the BSD license.
# -------------------------------------------------------------------------

# tree structure might look like
#  dynlib 
#  . AIX
#  .. sqlite3.6.10
#  .. tktable2.10
#  .. treectrl2.2.7
#  . Darwin
#  .. Tktable2.10
#  .. sqlite3.6.10
#  .. treectrl2.2.7
#  . Windows
#  .. Tktable2.10
#  .. sqlite3.6.10
#  .. treectrl2.2.8


# pay attention to the dir' structure and
# extend auto_path - if required, to make packages available

switch -glob -- $::tcl_platform(os) {
  "AIX"      { set libDir "AIX" }
  "Darwin"   { set libDir "Darwin" }
  "Windows*" { set libDir "Windows" }
  default    { set libDir "" }
}

if { $libDir == "" } {
  error "Libraries missing - please maintain lib directory!"
}

# re-assemble taking current dir into account:
set libDir [file join $dir $libDir]

               
if {[lsearch -exact $::auto_path $libDir] == -1} {
  lappend ::auto_path $libDir
}

This technique is not new, for sure, just thought, this info fits in here quite well...