Updated 2017-03-02 09:51:12 by JOB

Purpose: to guide a new user through the steps of building a starkit.

Starkits rely on a feature of Tcl/Tk 8.4 and above called the Virtual File System (VFS). Through the magic of VFS, a starkit contains an entire directory structure, including scripts, libraries, and even data files. The trick is to set up a structure which works in unpacked form while coding and testing, and which can later be assembled into an equivalent packaged starkit. Fortunately, all the infrastructure and tools are provided for you, and the whole process is very easy.

STEP 1: Get Tclkit and sdx

Note: the tclkit web site is now at Google Code [1]: check there first for tclkit and sdx.

  • For Windows, get tclkit.exe and tclkitsh.exe
  • For Linux, get one of the tclkit-*-linux-ix86.gz files
  • For Mac OS X, get a tclkit-*-darwin-univ.gz - these are universal (fat) binaries.
  • For everything else, look around for something relevant.

The Unix, Linux and Mac binaries need to be unpacked, renamed, and made runnable:
    gzip -d tclkit-*.gz
    mv tclkit-* tclkit
    chmod +x tclkit

On UNIX/Linux/MacOS X, be certain that tclkit is in a directory that is in your $PATH.

SDX is the Starkit Developer eXtension. It is a starkit containing tools for manipulating Starkits and Starpacks. Get sdx.kit from http://tclkit.googlecode.com/ (see the Downloads section on the right). Since it's a starkit, you run it with the command
    tclkit sdx.kit

Windows note: On Windows you need to use tclkitsh.exe. tclkit.exe is a GUI program and you need a command-line program when using sdx. It is useful on Windows to create a batch script so that you have a sdx command. eg: create sdx.cmd containing:
 @c:\Path\To\tclkitsh.exe c:\Path\To\sdx.kit %1 %2 %3 %4 %5 %6 %7 %8 %9

Then you can just issue sdx wrap hello.kit like the unix users.

If this command responds with the error "can't find package starkit" then you need to add read permissions to your tclkit binary. On UNIX/Linux type systems, this would be via:
    chmod u+r tclkit

You now have STARKIT TECHNOLOGY!!

Note that ActiveTcl also contains tclkit files but call them basekit. sdx can be driven with basekit just as with tclkit. Basekit executables are mostly identical to tclkit executables.

STEP 2: Wrap Your Application

You can easily wrap any single file Tcl application. For this example, create a file named "hello.tcl" and use the following two lines of text as its contents:
        package require Tk
        pack [button .b -text "Hello World!" -command bell]

Use sdx's "qwrap" option to quickly turn a single script into a starkit:
        tclkit sdx.kit qwrap hello.tcl

The result is a file called hello.kit. On Windows, SDX will also create a file hello.bat. Type "hello" on Windows, or "./hello.kit" on Unix. You'll see a window with button which beeps when clicked

STEP 3: Unwrap Your Application

Your wrapped application contains an entire virtual file system. In this case, we have just one script file, but even this simple application has all the virtual file system support you would get with a complex applcation. To see the contents of your starkit, unwrap it like this.
        tclkit sdx.kit unwrap hello.kit

This creates a copy of hello.kit's virtual file system in a directory named "hello.vfs/". You will find the startup script at "hello.vfs/main.tcl", and your hello.tcl script has been converted into a package in hello.vfs/lib/app-hello/.

STEP 4: Make Changes

One of the benefits of starkit applications is that they run exactly the same way wrapped or unwrapped. Both these commands will execute your application, and your application will execute identically.
    tclkit hello.kit
    tclkit hello.vfs/main.tcl

So you can continue application development in the unwrapped starkit. Add scripts, data files, or packages under hello.vfs/lib/, and they will all be found by your application. Work on the unwrapped application until it's just right.

If your application needs to know the location of the top of the vfs tree it should use the variable $starkit::topdir which gets set appropriately when the starkit is initialized. This ensures the correct result is obtained for any of the ways a tclkit can run your code. Either as a starkit, a starpack or unwrapped or even under tclsvc or the browser plugin.

STEP 5: Wrap It Up

When you are ready to create an updated starkit, do:
        tclkit sdx.kit wrap hello.kit

This takes hello.vfs/ as input, and overwrites hello.kit as before, creating an application that can be run with "hello" (Windows) or "./hello.kit" (Unix)

Notice that your application development structure (hello.vfs/) is exactly the same as the starkit. And your starkit will run on any plaform with a Tclkit binary runtime because in this case, the application makes use of only scripts in the starkit and packages in tclkit.

RLH 2005-07-22: For Windows 2000/XP I create these simple bat files to help me create a starkit. It is a given that I am not a very good bat creator. : )
 @echo off
 title CREATING STARKIT FOR POPUPS SCRIPT
 echo.
 echo "Wrapping and Unwrapping popups..."
 tclsh.exe c:\Tcl\bin\sdx.kit qwrap popups.tcl
 tclsh.exe c:\Tcl\bin\sdx.kit unwrap popups.kit
 echo.
 echo "Copying mime into the archive"
 xcopy C:\Tcl\lib\tcllib1.7\mime "C:\Path_to_vfs\Popups.vfs\lib\mime\" /s /v /y
 echo.
 echo "Copying MD5 into the archive"
 xcopy C:\Tcl\lib\tcllib1.7\md5 "C:\Path_to_vfs\Popups.vfs\lib\MD5\" /s /v /y
 echo.
 echo "Copying base64 into the archive"
 xcopy C:\Tcl\lib\tcllib1.7\base64 "C:\Path_to_vfs\Popups.vfs\lib\base64\" /s /v /y
 echo.
 echo "Creating the EXE file"
 tclsh.exe c:\Tcl\bin\sdx.kit wrap popups.exe -runtime c:\Tcl\bin\tclkitsh.exe
 echo.
 echo "Deleting unnecessary files..."
 del popups.bat /q
 del popups.kit /q
 rmdir popups.vfs /s /q
 echo.
 echo "Popups executable built..."

MHo: Take a look at Windows batch script for 'compiling' starpacks.

RPH: Is it possible to cross-build a StarKit? If so how is it done?

MSH: By default a starkit is cross-platform as it needs a local tclkit executable to run on a platform, except binary extensions which must be stubs aware and have each .dll/.so for the required platforms and a pkgindex which loads the correct extension.

dcd: see Building Starkits and Starpacks using a Makefile 2

[Jaj0] - 2017-03-01 22:19:54

Hello, is there possibility to pack additional .exe file into startkit/exe? I have tcl script which calls (by exec) aditional .exe program which is in the same folder. When i copy this additional .exe into .vfs directory and pack kit i cannot run this .exe. APN The operating system does not know about the starkit filesystem or have access to it. You have to explicitly copy the exe, and supporting files if any, to the physical file system and invoke it from there.

JOB - 2017-03-02

Maybe this helps you out to solve the problem: Executing programs which are shipped within starpacks