A program in source form can be fun to read, but sources are rather
useless if they can not be transformed into something executable. This
section will detail the steps involved in turning TOM source into an
executable. If you are not interested in the details, you can safely
skip this and continue to read the next section (1.3,
page ), which explains how you'd normally
compile TOM programs.
The first step is creating the source file containing our example
program. You can enter the example from the previous section manually or
simply copy copy it from
/usr/local/tom/ttpl/ex/hello.t. In any case, you should
end up with a file hello.t in a preferrably empty directory.
The next thing to do is to run the interface generator, gi. Apart from its main task--generating interfaces; hence its name--it is also responsible for creating the so-called unit file. A unit is the largest building block in TOM. A program is a unit, and each library is also a unit. The unit file declares which classes are defined in every file contained in the unit.
We will elaborate on the interface generator later on. For now it is
important to know that you must run it because it will generate the unit
file. Accomplish this by entering the following command line:
$ gi -u hello -U tom hello.t
00.5cm(You don't actually enter the $. It is here to remind you that the line is a shell command.)
This command tells gi:
Now that all necessary files are in place, it is time to run the compiler, which will turn a TOM source file into a C source file. Enter the following command:
$ otmc hello
otmc is the TOM compiler. It will search the current directory
for the unit file. After it has verified that the unit
file indeed contains the file hello, it will read hello.t
and produce hello.c.
Next, we let the C compiler do its work. The code produced by otmc can only be compiled by the GNU C Compiler (gcc), since it employs gcc specific constructs.
$ gcc -c hello.c
This turns the file hello.c into hello.o, which is the object file corresponding to the TOM source file hello.t.
Normally, a unit contains several source files, and you must run both otmc and gcc for every file in the unit.
When all files have been compiled--only hello.t in our example--you'd expect time has come to link the object files, with any libraries needed, to create the executable. However, when building a TOM program, one extra step is needed before the linking: the resolver must be run to build the data structures needed by the runtime library.
$ otmr
Similar to otmc, otmr operates on the unit file it finds in the current directory, creating a C source file containing the datastructures. In our example, it will create hello-r.c. Obviously, this needs to be compiled too.
$ gcc -c hello-r.c
Now we're really done compiling and the objects can be linked together to
form the executable.
$ gcc -o hello hello.o hello-r.o /usr/local/tom/tom.o
Obviously, the objects hello.o and hello-r.o are linked against the TOM library object and any implict libraries included by gcc.
When you've successfully completed the above steps, you can now run Your First TOM Program.
$ ./hello Hello, world!