| [ Team LiB ] |
|
Creating tclhttpd.kitThe Tcl Web Server, TclHttpd, has its source tree organized so you can run the server without any installation steps. This makes it very easy to put into a Starkit. For our first version, which we will refine later, all we need is a copy of the TclHttpd source code and a copy of the Standard Tcl Library, tcllib. I used the tcllib1.3 directory that was installed in the main lib directory of my desktop Tcl environment, and the tclhttpd3.4.3 source distribution. Example 22-7 shows the contents of the tclhttpd.vfs directory: Example 22-7 The contents of the tclhttpd.vfs directory, version 1main.tcl tclhttpd3.4.3/bin/httpd.tcl tclhttpd3.4.3/bin/httpdthread.tcl tclhttpd3.4.3/bin/tclhttpd.rc tclhttpd3.4.3/lib/ (lots of files) tclhttpd3.4.3/htdocs/ (lots of files) tcllib1.3 (copy of /usr/local/lib/tclib1.3) Example 22-8 shows the short main.tcl script used to start up the Starkit. The first two lines are common to all Starkits. The starkit::autoextend command is used to add the tcllib1.3 directory to the auto_path so the Standard Tcl Library packages are available. The last line uses starkit::topdir to find the TclHttpd startup script, bin/httpd.tcl. Example 22-8 The main program for the TclHttpd Starkit, version 1package require starkit starkit::startup starkit::autoextend [file join $starkit::topdir tcllib1.3] source [file join $starkit::topdir tclhttpd3.4.3/bin/httpd.tcl] The Starkit is created and used as shown below, assuming tclhttpd.vfs is in the current directory. Note that command line options are passed through, so you can also use this Starkit to host an htdocs directory outside the Starkit. If you don't specify one, the htdocs tree inside the Starkit is used: sdx wrap tclhttpd.kit tclkit tclhttpd.kit -port 8080 -docRoot /my/htdocs The standard structure introduced in Example 22-2 organizes packages under a lib directory. By convention, the version numbers are dropped from the package directory names. Because everything is self contained, there really isn't any need to have explicit version numbers in the directory names. The file system for the second version of tclhttpd.kit is shown in Example 22-9. Example 22-9 Contents of the tclhttpd.vfs directory, version 2main.tcl bin/httpd.tcl bin/httpdthread.tcl bin/tclhttpd.rc lib/tclhttpd/pkgIndex.tcl lib/tclhttpd/*.tcl (lots of files) lib/tcllib/pkgIndex.tcl lib/tcllib/* (lots of subdirectories) The main.tcl file is shown in Example 22-10. There is no need to adjust the auto_path because starkit::startup ensures that the lib directory is on it. Example 22-10 The main program for the TclHttpd Starkit, version 2package require starkit starkit::startup source [file join $starkit::topdir bin/httpd.tcl] One of the first things I noticed about the tclhttpd.vfs was that tcllib took up far more space than the rest of TclHttpd. TclHttpd only uses a few of the many modules in tcllib. I ended up only adding the modules I needed in order to keep the Starkit smaller. Another way to solve this problem is to use the tcllib.kit Starkit that can be shared among applications. Creating shared Starkits is the topic of the next section. |
| [ Team LiB ] |
|