This began as a short howto on adding your own little image "brushes" to Coccinella, a Jabber-compatible open-source collaborative whiteboard system, written in Tcl/Tk by Mats Bengtsson. But then it became more about how to make standalone executables from Tcl/Tk code. So, the Coccinella-specific stuff can be thought of as the working example for how to create binaries out of Tcl/Tk source. Please keep in mind that I know nearly nothing about Tcl/Tk, so my methods here may not be very efficient or "correct," and may not generalize to all Tcl/Tk scripts (I have only done this with Coccinella).
Mac OS X Preparation, method #1:
Contents->Resources->Scripts->Coccinella
Mac OS X Preparation, method #2: (i.e. if you plan to do substantial hacking of this source)
package require xmldefs 2.0and change it to
package require xmldefs 3.1
chmod 755 Coccinella.tcl ./Coccinella.tcl
Leave the Terminal open. After a few moments, Coccinella should start up normally (splash screen etc.) Quit Coccinella and you should get your prompt back in the Terminal window.
Building Windows and Linux executables: (Mats Bengtsson's method)
Get SDX. Download http://www.equi4.com/pub/sk/sdx.kit
Rename the file, "mv sdx.kit sdx"
Make it executable, "chmod +x sdx"
sudo mv sdx /usr/bin (so it is in the default PATH)
Get tclkit. Go to http://www.equi4.com/pub/tk/, then "8.4.9/", and download the version for your machine that you will be building on. In my case, since I am using Mac OS X, it was "tclkit-darwin-ppc.gz". Un-gzip-it with Stuffit or gzip -d tclkit-darwin-ppc.gz.
Rename the file, "mv tclkit-darwin-ppc tclkit"
Make it executable, "chmod +x tclkit"
sudo mv tclkit /usr/bin (so it is in the default PATH)
# Hardcoded for my machine! array set tclkit { linux /root/Tcl/TclKits/8.4.5/tclkit-linux-x86.upx.bin windows /root/Tcl/TclKits/8.4.1/tclkit-win32.upx.exe }and adjust the paths accordingly -- in this example,
# Hardcoded for my machine! array set tclkit { linux /Users/mbates/Desktop/build/tclkit-linux-x86.upx.bin windows /Users/mbates/Desktop/build/tclkit-win32.upx.exe }
Finally, save the changes, and make the file executable (chmod +x BuildCoccinella.tcl).
Into this directory, put:
cd /Users/mbates/Desktop/build/ ./BuildCoccinella.tclYour output should look something like this. You'll get prompted for a version number, enter something sane:
mbates@apocalypse build$ ./BuildCoccinella.tcl rootdir=/Users/mbates/Desktop/build Version number: 0.95.5.1 BuildSources Coccinella copy coccinella Coccinella-0.95.5.1Src PurgeDirRecursive building source tar archive Coccinella-0.95.5.1Src.tar.gz BuildEmptyVFS /Users/mbates/Desktop/build/linux BuildVFS linux /Users/mbates/Desktop/build/linux/Coccinella-0.95.5.1.vfs PurgeNonplatformBins linux /Users/mbates/Desktop/build/linux/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin PurgePlatformBins macosx /Users/mbates/Desktop/build/linux/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin /Users/mbates/Desktop/build/linux/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin/macosx/PowerMacintosh PurgePlatformBins windows /Users/mbates/Desktop/build/linux/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin /Users/mbates/Desktop/build/linux/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin/windows/intel sdx wrap linux Coccinella-0.95.5.1.bin making Coccinella-0.95.5.1Linux-x86 BuildEmptyVFS /Users/mbates/Desktop/build/windows BuildVFS windows /Users/mbates/Desktop/build/windows/Coccinella-0.95.5.1.vfs PurgeNonplatformBins windows /Users/mbates/Desktop/build/windows/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin PurgePlatformBins macosx /Users/mbates/Desktop/build/windows/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin /Users/mbates/Desktop/build/windows/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin/macosx/PowerMacintosh PurgePlatformBins linux /Users/mbates/Desktop/build/windows/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin /Users/mbates/Desktop/build/windows/Coccinella-0.95.5.1.vfs/lib/app-Coccinella/bin/unix/Linux/i686 sdx wrap windows Coccinella-0.95.5.1.exe making Coccinella-0.95.5.1Win finished! mbates@apocalypse build$
If you get errors about "sdx not found" or "tclkit not found", check to see that each of them has been a) renamed to just "sdx" and just "tclkit" respectively, b) that they are in your default path (/usr/bin works), and c) that they are both set to be executable (chmod +x /usr/bin/sdx and /usr/bin/tclkit). Then try running the script again.
drwxr-xr-x 26 mbates staff 884 7 Apr 13:16 Coccinella-0.95.5.1Src -rw-r--r-- 1 mbates staff 3866768 7 Apr 13:16 Coccinella-0.95.5.1Src.tar.gz drwxr-xr-x 5 mbates staff 170 7 Apr 13:16 linux drwxr-xr-x 5 mbates staff 170 7 Apr 13:16 windows
In order:
You should be able to happily take these executables and run them on their respective platforms without any trouble.
To perform this process on linux, all is fundamentally the same except that the version of tclkit that you download needs to be the proper version for your architecture. In other words, tclkit is the main thing that performs this build process, and thus needs to match the machine you're building on. SDX is used also, but is cross-platform so the same version works no matter what your build platform is. The other two tclkit downloads are resources that get wrapped into the build regardess of what build platform you're on. You build both binaries no matter what machine you're running the build on.
The same story is true for building under Windows, BUT you also need to download SDX.bat from here, and you're on your own as far as DOS and paths go, cuz I haven't a clue.
Building Windows executables: (my accidentally-discovered method; Mats's is better)
NOTE: If you get errors about "node not found" or "directory not found", exit and relaunch TclApp and try again. I dunno if it's a bug, or a problem with my system, but that happened once.
You can also change the output file default path and name at the bottom of this screen.
NOTE: I don't know if it is possible to change the default icon or the application properties at this stage; I think you can use some sort of Windows resource editor to customize the icon/properties after the fact.
Main Steps for Coccinella image library mod:
So, I'm going to rename my copied ladyBug.can file to "invader.can".
You will need to change two things here: 1) The path/filename, and 2) the image width/height (in pixels).
Note that the path to the image file is relative -- in other words, it is based on the location of this (invader.can) file. The path says, "go up one directory and descend into the 'images' directory to find 'ladybug.gif'." If you want to, say, put your custom images in their own submenu, called "custom", then make a directory under images called "custom" and edit the path in your .can file(s) accordingly:
And of course the filename needs to match. Then, change the width and height to match your image; if you don't know your image's dimensions, open it in a browser and look at the dimensions in the title bar (see screenshot). This works in Apple's Safari browser, I think in Firefox and other Mozilla offspring you can right-click and get info on an image to see its dimensions.
So then my invader.can file would look like this:
Save and exit from the editor.
NOTE: Other Coccinella users will be able to see this image if you use it, because of the nature of the server/client communication (the invader.gif file will be "pushed" to the clients). However, they themselves will not be able to see and use the invader option in their own Library menus unless you make this same mod on their version of Coccinella.
NOTE: Turns out that there is an even simpler way to add images to the menu, in a more-ephemeral way. Mats Bengtsson writes:
If you run from sources just place any images within the coccinella/
directory (so they are somewhat protected) and import the image
in the whiteboard as usual. Then just save the canvas in coccinella/items
directory. That should be enough. You shouldn't need to edit any files.
So, I still don't know exactly what all the data inside the .can files _means_, but this is how it normally gets generated I guess. :) The new items get saved to an "items" directory under ~/Library/Preferences/Coccinella/ on Mac OS X.
References/Resources:
# Version: 2
import 21.0 61.0 -tags xxx/66898426 -file ../images/ladybug.gif -width 54 -height 108
... -file ../images/custom/invader.gif ...
# Version: 2
import 21.0 61.0 -tags xxx/66898426 -file ../images/custom/invader.gif -width 102 -height 78
If you look at the whiteboard's File menu there is a "Save As Object"
entry that saves the current whiteboard content as Library item
the next time you launch Coccinella. The canvas file is saved
in the prefs directory, but with links to any image files.
So if you move the image file a "broken link" is the result.