Updated 2016-02-14 15:48:48 by dbohdan

Assemble bundles multiple Tcl source code files into a single file. It also works as a preprocessor that understands #define and #ifdef/#ifndef. Assemble is developed as part of the Sqawk project.

Use case  edit

Assemble can be compared to Perl's App::FatPacker.

Note that in most cases a Starpack is a more robust alternative to an "assembled" script. However, assembled scripts have the following advantages:

  • Over Starpacks (if you already have Tcl installed on the target system): lower startup delays.
  • Over Starkits: being usable as executable files on Unix. Assembled scripts can be run directly and do not require a wrapper shell script or a Tclkit with which to run them.
  • Over both: being plain text.

Assembling also works for Jim Tcl source code. Assemble itself can be run with Jim Tcl.

Example  edit

The following example comes from Sqawk v0.14.1:

Input

sqawk-dev.tcl

# ...

#define SQAWK
interp alias {} ::source+ {} ::source
source+ lib/tabulate.tcl
source+ lib/utils.tcl
source+ lib/parsers/awk.tcl
source+ lib/parsers/csv.tcl
source+ lib/serializers/awk.tcl
source+ lib/serializers/csv.tcl
source+ lib/serializers/table.tcl
source+ lib/serializers/tcl.tcl
source+ lib/classes/sqawk.tcl
source+ lib/classes/table.tcl

# ...

lib/tabulate.tcl

#! /usr/bin/env tclsh
# Tabulate -- turn standard input into a table.
# ...
        set data $updateData
        dict unset argv FS
    }

    puts [tabulate -data $data {*}$argv]
}

#ifndef SQAWK
# If this is the main script...
if {[info exists argv0] && ([file tail [info script]] eq [file tail $argv0])} {
    ::tabulate::main $argv0 $argv
}
#endif

Output

sqawk.tcl

# ...

interp alias {} ::source+ {} ::source

# ============================= lib/tabulate.tcl ===============================
#! /usr/bin/env tclsh
# Tabulate -- turn standard input into a table.
# ...
        set data $updateData
        dict unset argv FS
    }

    puts [tabulate -data $data {*}$argv]
}


# =========================== end lib/tabulate.tcl =============================
# ...

Discussion  edit

See also  edit