We can build the improved program using the same cc command we did the first time:
cc guess.c sequence.c test.c
However, it is somewhat inefficient to recompile ALL of the modules of the program, when it was only guess.c that changed. Instead, we could have simply done:
cc guess.c sequence.o test.o
to recompile guess.c, and link the previously compiled sequence.o and test.o modules.
We can save time this way - only recompile the parts of the program that need to be recompiled. Unfortunately, as we modify different parts of the program, it is up to US to keep track of what modules need to be recompiled. This is even more difficult if we only change a .h file, then we need to remember to recompile all the .c files which include that .h. We are likely to make mistakes, and end up tracking down a bug that doesn't exist, simply because we forgot to recompile somthing we should have.
There ought to be a better way...
Fortunatley, Unix provides a utility that will do this for us, called make. To use this utility, we need to create a file, called makefile that describes the organization of our program to the make utility, such as what .c files are needed to build the program and what .h files are included in what .c files. Then, when we run:
ee150:wiliki:66> make
cc -c guess.c
Linking guess ...
done
The make utility uses the Makefile to determine which files are needed and which files they are dependent on, look at their modification times, and determines just which files should be recompiled and then links the modules to update the executable.
One other technique I used in the Improve1 directory to share the .c and .h files we didn't change with the previous version of the program is to create symbolic links rather than copy the files. We can see which files are links when we list the directory:
ee150:wiliki:75> ls
Makefile guess.h@ sequence.c@ tfdef.h@
guess.c play.h@ test.c@
Those with the '@' character after the names are links. We can see where they are linked with
ee150:wiliki:76> ll
total 18
-rw-r--r-- 1 ee150tep 99 1618 Sep 24 12:36 Makefile
-rw-r--r-- 1 ee150tep 99 1716 Sep 24 12:14 guess.c
lrwxr-xr-x 1 ee150tep 99 10 Sep 20 16:07 guess.h@ -> ../guess.h
lrwxr-xr-x 1 ee150tep 99 9 Sep 20 16:07 play.h@ -> ../play.h
lrwxr-xr-x 1 ee150tep 99 13 Sep 20 16:07 sequence.c@ -> ../sequence
.c
lrwxr-xr-x 1 ee150tep 99 9 Sep 20 16:07 test.c@ -> ../test.c
lrwxr-xr-x 1 ee150tep 99 10 Sep 20 16:07 tfdef.h@ -> ../tfdef.h
I created these links with commands like:
ln -s ../guess.h .