An Introduction To Embedded Tk (page 22 of 32)

[Previous Page][Next Page][Table of Contents]

11.1 Compiling ET Itself

But before we begin talking about how to compile ET applications, we need to first mention how to compile ET itself -- the et2c preprocessor and the et.o library. (If you have one of the platforms supported by the CD-ROM in the back of this book, then you already have precompiled versions of et2c and et.o and can skip this step.)

The source code to the et2c preprocessor is contained in a single file named et2c.c. The preprocessor is written in highly portable K&R C and should compile without change on just about any 32-bit architecture. All you have to do is this:

  cc -O -o et2c et2c.c

Compiling the et.o library is a little more problematic, but still not difficult. There are three steps. First you have to select an appropriate source code file. There are different versions of the source code (sometimes radically different) depending on which version of Tcl/Tk you are using. For Tk version 3.6, choose et36.c. For Tk version 4.0, choose et40.c. For Tk version 4.1 on UNIX and X11, choose et41.c. Your ET distribution may also have other options, such as versions for MS-Windows or Macintosh, or versions with built-in support for various Tcl extensions.

Let's suppose, for the sake of discussion, that you selected the source file et41.c. The next step is to preprocess this file using et2c. This step is a little tricky because we have to use the -I option to et2c to tell the preprocessor where to find the Tcl/Tk startup scripts.

Recall that the stardard Tcl/Tk interpreter program, wish, reads and executes a series of Tcl/Tk scripts when it first starts up. These scripts set up default widget bindings, create procedures for handling menus, and so forth. The names of the directories from which these scripts are loaded are hard-coded in the wish executable. There are about 15 different startup scripts (the number varies from one version of Tcl/Tk to the next) and wish will not run without them.

But ET applications don't read the startup scripts at run-time. Instead, a series of ET_INCLUDE() statements inside the Et_Init() function bind the startup scripts into an ET executable at compile-time. This feature is what enables ET applications to run on machines that do not have Tcl/Tk installed.

It is because of 15 or so startup scripts included by ET_INCLUDE() statements in the ET library that we have to preprocess the library source code using et2c. But we also have to tell et2c what directories to use when searching for the startup scripts. If Tcl/Tk has already been installed on your system, then you can find out the names of the startup script directories by executing the following wish script:

  #! wish
  puts $tk_library
  puts $tcl_library
Let's suppose that the startup scripts are located in the directories /usr/local/lib/tcl and /usr/local/lib/tk. Then the command to preprocess the ET library source code would be the following:
  et2c -I/usr/local/lib/tcl -I/usr/local/lib/tk et41.c >et.c

After preprocessing the library source code, all that remains is to compile it. The library references the <tk.h> header file, which in turn references <tcl.h>, so you may have to add some -I options to the compiler command line to specify the directories where these header files are located. The following is typical:

  cc -c -o et.o -I/usr/include/tcl -I/usr/include/tk et.c

[Next Page][Table of Contents]