1.2. From source to running program

The easiest way to get our program running is by creating a GNUmakefile with the following contents:

UNIT=               hello
TOM_SRC=            hello

TOM_MAKEFILES_DIR=  /usr/lib/tom/makefiles
include $(TOM_MAKEFILES_DIR)/GNUmakefile.bin

This GNUmakefile assumes that our program source is contained in the file hello.t and that our executable program will be called hello. Furthermore, it assumes that the TOM Makefiles (see Appendix A) are available in /usr/lib/tom/makefiles; adjust the definition of the macro TOM_MAKEFILES_DIR if their location on your machine is different.

If we now run make, output will be similar to this (what appears here has been edited to fit better):

[In the preceding paragraph, using <command>make</command> results in make, which is rather ugly.]

$ make
/usr/local/lib/tom/makefiles/GNUmakefile.common:168: GNUmakefile.link: No such file or directory
building GNUmakefile.link...
if test -z "yes"; then touch GNUmakefile.link; else \
        /usr/local/lib/tom/makefiles/genlinkfile -o GNUmakefile.link \
         -I /usr/local/lib/tom  -I /usr/local/lib/tom tom; \
using unit tom from /usr/local/lib/tom/tom
test -f hello.u || \
        tug -u hello   -U tom hello.t
time tesla  -freadable-c :cc-pre :cc-post -1  \
        -u hello -I . -I /usr/local/include -I /usr/local/lib/tom
Number of units: 3
Loading unit tom...
Loading unit hello...
Preparing unit _builtin_...
Preparing unit tom...
Preparing unit hello...
1.94user 0.08system 0:02.82elapsed 71%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (625major+665minor)pagefaults 0swaps
touch .stamp-prepare
/usr/local/lib/tom/makefiles/libtool  --mode=compile gcc -g -O2     -I /usr/local/include -I /usr/local/lib/tom -I . -c hello.c
rm -f .libs/hello.lo
gcc -g -O2 -I /usr/local/include -I /usr/local/lib/tom -I . -c  -fPIC -DPIC hello.c -o .libs/hello.lo
gcc -g -O2 -I /usr/local/include -I /usr/local/lib/tom -I . -c hello.c -o hello.o >/dev/null 2>&1
mv -f .libs/hello.lo hello.lo
/usr/local/lib/tom/makefiles/libtool  --mode=compile gcc -g -O2     -I /usr/local/include -I /usr/local/lib/tom -I . -c hello-r.c
rm -f .libs/hello-r.lo
gcc -g -O2 -I /usr/local/include -I /usr/local/lib/tom -I . -c  -fPIC -DPIC hello-r.c -o .libs/hello-r.lo
gcc -g -O2 -I /usr/local/include -I /usr/local/lib/tom -I . -c hello-r.c -o hello-r.o >/dev/null 2>&1
mv -f .libs/hello-r.lo hello-r.lo
TOM_MAKEFILES_DIR=/usr/local/lib/tom/makefiles /usr/local/lib/tom/makefiles/libtool --mode=link  \
        gcc    -L/usr/local/lib hello.lo hello-r.lo   -L/usr/local/lib/tom/tom -ltom -ltrt \
         -ldl -lpthread  -l_builtin_ -o hello
gcc -L/usr/local/lib hello.o hello-r.o -L/usr/local/lib/tom/tom -ltom -ltrt -ldl -lpthread -l_builtin_ -o hello

[Briefly explain every command and its use.]

Now our program has been built, we can run it:

$ ./hello
Hello, world!

Of course, since we are using make, we can change our program hello.t as much as we want and all we need to do to rebuild it is run make again.