Wrapping an application with Tarcel makes it much easier to distribute by allowing you to include all the files for the application along with the packages that it requires in a single file. As an example we’ll wrap Tarcel itself using the tarcel.tarcel file in the repo.

Looking at the tarcel.tarcel file, we first define the files that make up the utility:

set appFiles [list \
  tarcel.tcl \
  [file join lib commands.tcl] \
  [file join lib parameters.tcl] \
  [file join lib xplatform.tcl] \
  [file join lib config.tcl] \
  [file join lib compiler.tcl] \
  [file join lib tvfs.tcl] \
  [file join lib tar.tcl] \
  [file join lib tararchive.tcl] \
  [file join lib embeddedchan.tcl]

Then define the modules it requires. In this case it needs the configurator module and uses find module to locate it.

set modules [list \
  [find module configurator]

We set version and baseDir for use later in the script. baseDir will be the root of the tarcel to which all other files in the tarcel will be relative to.

set version 0.1
set baseDir tarcel-$version.vfs

Now we can import the files defined above for the utility and put them in the app directory off of $baseDir while keeping their relative directory structure.

import [file join $baseDir app] $appFiles

And fetch the modules defined above and place them directly in the modules directory off of $baseDir without keeping any relative directory structure.

fetch [file join $baseDir modules] $modules

We’ll set the version and homepage within the config to provide useful information via the info command of tarcel.tcl.

config set version $version
config set homepage "https://github.com/LawrenceWoodman/tarcel"

Finally we set the script which will start the application. Note that it adds the modules directory to the list of paths that are searched for modules.

set initScript {
  ::tcl::tm::path add [file join @baseDir modules]
  source [file join @baseDir app tarcel.tcl]

config set init [string map [list @baseDir $baseDir] $initScript]

Once you have the .tarcel file you can run tarcel.tcl on it to wrap the files into a single package. We’ll create a tarcel called t.tcl:

$ tclsh tarcel.tcl wrap -o t.tcl tarcel.tarcel

You can test that it worked by querying itself:

$ tclsh t.tcl info t.tcl

Which will give something like the following:

Information for tarcel: t.tcl
Created with tarcel.tcl version: 0.1

  Homepage: https://github.com/LawrenceWoodman/tarcel
  Version: 0.1

Find out More

To find out more have a look at the Tarcel Project page and the following articles: