Updated 2006-10-24 23:01:52 by dkf

Purpose: To compare and contrast the various compiling technologies currently available for Tcl scripts.

Reasons why one might want to do this:

  • One file to distribute instead of dozens of runtime scripts, shared libraries, etc.
  • Decrease probability that the user will modify application (accidentally or intentionally)
  • Hide/obfuscate the algorithm being used in application

Reasons why this is hard:

  • Creating one file means that you either limit the versions of tcl/tk/etc. that can be used, as well as the platforms, or that you spend all your time creating variations.
  • Users can still, in many cases, modify the script by editing the binary.
  • To get around that, one has to encrypt the application, resulting in more difficult time debugging, etc.

Tools available for this type of requirement

  • Freewrap - read in scripts and write out single executable.
  • TclPro/Tcl Dev Kit - commercial product which includes a wrapper.
  • GE ICE Tcl compiler - commercial product
  • Tclkit - attempt to separate the runtime environment from the application environment; results in two files to distribute. One is platform specific but application neutral. The other is platform independent, but application specific.
  • Mktclapp [1] - a different kind of approach; provides tools for creating your own C or C++ mainline which then invokes tcl functions.
  • Kt2c [2] - translates Tcl bytecodes into C. * Note on June 08, 2004: TPHNRAF
  • TOBE ("Tcl as One Big Executable") [3] - builds UNIX and Windows binaries
  • TclWrap
  • Geek Oct. 2006

Scroll down to find a table, in this same page, indicating which ones run on which platform.

See also a recent post by Karl Lehenbauer [4]

Also see "Transforming Tcl scripts into binary code", "makeself" and "Building Stand Alone Executables in Unix"

At last there is also Jan Nijtmans "wrap" extension.

A farther relation is the GNU Lightning library for on-the-fly generation of executable machine code. Something similar not under GPL could be used in kt2c (see above).

Not all the above tools provide the same level of protection for your scripts, so it is important to understand how they work and account for that against your protection needs. Many of the wrapping solutions only embed the same code in a binary, but that doesn't prevent others from unwrapping and reading it. Those solutions are good for general ease of use and development, but are best for preventing end users from tinkering with your code, as they don't provide a high level of protection.

The compiling solutions in Tcl Dev Kit/TclPro and the GE ICE Tcl compiler are the strongest protection because they actually obfuscate in such a way that not even runtime introspection would reveal your code. The latter is arguably the best, as it translates to compilable C code, but it only works for Tcl 8.0.

CL collects more information on this subject at http://phaseit.net/claird/comp.lang.tcl/tcl_compilers.html .

FW: Note that the standard, officially advocated technique for bundling a Tcl interpreter and your script (and optionally even libraries etc) into a single executable is now Starpacks via TclKit. There's no longer a lack of a standard on the matter. The rest of these options have become esoteric in comparison. I believe even Tcl Dev Kit now uses Starpacks (I don't know what has become of the original wrapping tool - maybe included as well).

Of course, Starpacks are not only usually unobfuscated (and uncompiled), but tools are actually provided in the distro to unwrap them - so of these apps, the ones that actually do some compilation rather than just bundling still have a leg up on TclKit. But overall, for bundling, TclKit is now definitely the recommendation. It's a more standard and globally accepted method than is provided for any of the other major scripting languages.

Platform x tools availability table:
                 [BSD]  [Linux]  [Mac OSX]  [Solaris]  [Windows]
 [Tclkit]         yes     yes       yes        yes        yes
 [Freewrap]        ?      yes        ?          ?         yes
 [TclPro]*         ?      yes        ?          ?         yes
 [Tcl Dev Kit]     ?      yes        ?          ?         yes
 [Mktclapp]        ?      yes        ?          ?          ?
 [GE ICE]          ?       ?         ?          ?          ?
 [TOBE]            ?      yes        ?          ?         yes
 [TclWrap]**       ?      yes        ?          ?         yes
 [Kt2c]***         ?       ?         ?          ?          ?

* TclPro is old software that became Tcl Dev Kit and is now offered by ActiveState with a commercial license.

** TclWrap used to be distributed by Souza Monteiro. Doesn't seem to be available anymore.

*** Kt2c seems to be a TPHNRAF.
 ''25 Oct 05'', SF project has disapeared, I have source code if anyone wants it -[pwq].

As of 8.4, ActiveTcl includes "base kits" (i.e. Tclkit) and is distributed itself as a starpack. -jcw

[Category Development|Category Deployment]
Generated in 213ms