It is very funny. Making a package for tcl is so easy! I am using tcl/tk 8.5 on FreeBSD 9.0. To make a hello world package, it only needs to create two files. One file is the source code, another is pkgIndex.tcl. You can write some functions in the source code file. The pkgIndex.tcl can be created by a tcl command: pkg_mkIndex . *.tcl
Follow these steps to make a package:
1. Make a directory named 3d-egg-1.0. 3d-egg is the package name that will be required by applications, 1.0 is the package version.
$ mkdir 3d-egg-1.0 $ cd 3d-egg-1.0
2. Write your code into 3d-egg.tcl in current directory. My 3d-egg.tcl is:
package provide 3d-egg 1.0 namespace eval 3d-egg { namespace export * } proc 3d-egg::hello {} { puts "hello 3d-egg!" } proc 3d-egg::bye {} { puts "bye 3d-egg!" }
3. Run tclsh in current directory, and make the pkgIndex.tcl with a command:
$ tclsh8.5 % pkg_mkIndex . *.tcl
It's done! The package is ready. You maybe want to release the package, then just compress the 3d-egg-1.0 directory and pushlish it on the Internet to give others. I suggest you release your code with BSD style license to share knowledge.
Installing the package is very easy, just copy the directory 3d-egg-1.0 to the path where tcl invoked. On FreeBSD copy 3d-egg-1.0 to /usr/local/lib.
$ cd .. $ sudo cp -r 3d-egg-1.0 /usr/local/lib/
Use 3d-egg package:
$ tclsh8.5 % package require 3d-egg 1.0 % 3d-egg::hello hello 3d-egg! % 3d-egg::bye bye 3d-egg!
Published at 10:40:41 Mar. 18, 2012 UTC
Updated at 10:44:11 Mar. 18, 2012 UTC
http://glx.me/docs/3d-egg/tcl-tk/index.php?page=tcl-make-a-package