The syntax of fakemake is as follows:
fakemake [ description-file ]If no description-file is specified, then it assumes that the description file is the file fmakefile. Obviously, if the description file doesn't exist, then the program should exit with an error.
Each line of the description file may be one of six things:
C list-of-filesAll files thus specified should end with .c. Multiple files can be separated by whitespace. The list may be empty, and there can be multiple lines starting with C.
H list-of-filesThe H list is formatted just like the C list, and there can be multiple lines starting with H.
E nameThere can be only one executable name; thus, there can be only one line starting with E. It is an error if there is no E line in the entire description file.
F flagsThese flags will be included right after gcc whenever it is called. As before, the flags are separated by whitespace, and there can be multiple F lines. This can be empty as well.
L list-of-librariesAs before, multiple files should be separated by whitespace. The list may be empty, and there can be multiple lines starting with L. This list is included at the end of the final gcc command that makes the executable.
What fakemake does is compile all the .c files into .o files (using gcc -c), and then compile all the .o files into the final executable. Like make, it doesn't recompile files if it is not necessary. It uses the following algorithm to decide whether or not to compile the .c files:
Obviously, if a .c or .h file is specified, and it does not exist, fakemake should exit with an error. If there are any compilation errors mid-stream, fakemake should exit immediately.
UNIX> cp ~cosc360/lab3/* . UNIX> ls f.c f.h f2.c makefile mysort.fm f.fm f1.c lab.html mysort.c UNIX> make gcc -c -g f.c gcc -c -g f1.c gcc -c -g f2.c gcc -g -o f f.o f1.o f2.o gcc -c -g -I/home/cosc360/include mysort.c gcc -g -o mysort mysort.o /home/cosc360/objs/libfdr.a UNIX> f This is the procedure F1 -- in f1.c This is the procedure F2 -- in f2.c UNIX> mysort < f.c f1(); f2(); main() { } UNIX> make clean rm -f core *.o f mysort UNIX> ls f.c f.h f2.c makefile mysort.fm f.fm f1.c lab.html mysort.c UNIX>So, this directory contains source code for two programs. The first, f, is made up of three C files: f.c, f1.c and f2.c, and one header file: f.h. The second is mysort.c from the Rbtree-1 lecture. The makefile contains a specification of how to make these programs using make. The file f.fm is the fakemake file for making f, and mysort.fm is the fakemake file for making mysort. Try it out, using the fakemake executable in ~cosc360/lab3/fakemake:
UNIX> ~cosc360/lab3/fakemake fakemake: fmakefile No such file or directory UNIX> ~cosc360/lab3/fakemake f.fm gcc -c -g f.c gcc -c -g f1.c gcc -c -g f2.c gcc -o f -g f.o f1.o f2.o UNIX> touch f.c UNIX> ~cosc360/lab3/fakemake f.fm gcc -c -g f.c gcc -o f -g f.o f1.o f2.o UNIX> rm f UNIX> ~cosc360/lab3/fakemake f.fm gcc -o f -g f.o f1.o f2.o UNIX> touch f.h UNIX> ~cosc360/lab3/fakemake f.fm gcc -c -g f.c gcc -c -g f1.c gcc -c -g f2.c gcc -o f -g f.o f1.o f2.o UNIX> touch f.h UNIX> touch f.o f1.o UNIX> ~cosc360/lab3/fakemake f.fm gcc -c -g f2.c gcc -o f -g f.o f1.o f2.o UNIX> ~cosc360/lab3/fakemake f.fm f up to date UNIX> f This is the procedure F1 -- in f1.c This is the procedure F2 -- in f2.c UNIX> ~cosc360/lab3/fakemake mysort.fm gcc -c -g -I/home/cosc360/include mysort.c gcc -o mysort -g -I/home/cosc360/include mysort.o /home/cosc360/objs/libfdr.a UNIX> mysort < f.c f1(); f2(); main() { } UNIX> rm f.h UNIX> ~cosc360/lab3/fakemake f.fm fmakefile: f.h: No such file or directory UNIX>As you can see, fm works according to the above specification. It only recompiles modules when it needs to. When you're in doubt about what your fakemake should do, see what ~cosc360/lab3/fakemake does and emulate its behavior.
To execute a string, you use the system() procedure. It executes the given string as if that string is a shell command (sh, not csh, although it shouldn't matter). If it returns zero, the command succeeded. If it returns anything else, the command failed.