Save your programs in a file called
in folders called
respectively for phases 1 and 2 of your project.
I will test your code in the same environment as the lab
machines in MI 302, using the command
/bin/bash --norc proj.sh
For phase 2 of your project,
you will write a program that imitates some of the features of the
popular linux utility
You should submit your program in a folder called
and be sure that it runs as described above.
Your program will read from a file called
a simplified makefile).
This file will consist of a series of rules. Each
rule is structured like
target : prereq1 prereq2 ... command1 command2 ...
You will notice a few components of the rule:
targetis the name of a single file in the directory. This rule gives instructions on how to generate or update this file. Any given filename must appear only once as a target in a given
prereq2, etc. are also the names of single files. These are collectively called the prerequisites of the given target. There can be 0 or more prerequisites for a single target, and they may be separated by any number of spaces, but they must all fit on a single line.
command2, etc. are
bashcommand lines that are executed in sequence every time the target needs to be re-generated. These commands can contain absolutely anything, but must each be preceded by some whitespace (spaces or tabs), and fit on a single line. These commands may assume that every one of the prerequisites exists, and after running the commands the target should be created or re-generated.
The meaning of the rule is that the target should be re-generated whenever every one of its prerequisites exists, and either (1) the target does not exist, or (2) at least one of the prerequisites is newer (in terms of file modification time) than the target. Re-generation just involves executing each of the commands in sequence.
spec.txt file can also contain comment lines,
which are indicated by starting the line with a
Note that comments must be whole lines; they cannot start in the middle of
a rule, for instance.
Your program will read the
spec.txt file and repeatedly
re-generate targets according to the rules above, until no more
targets can be created or re-generated. Note that target names are not
specified as they normally are to
make; instead, your program
will essentially attempt to make every possible target, repeatedly.
I suggest you write your program in the following steps:
spec.txtonce, and run the commands to generate every target once.
For full credit, your program should:
Suppose we are in a directory that initially only contains the
spec.txt, consisting of:
a : echo "this will go into a" > a b.txt : index.php a cp a b.txt head index.php >> b.txt c : c.cpp g++ -o c c.cpp index.php : wget "http://www.usna.edu/Users/cs/roche/courses/f11si413/project/index.php"
Running your program in this directory should first cause the files
index.php to be generated, since those targets
do not exist, but all of their prerequisites do (vacuously, since they have
no prerequisites). They are generated, in any order, by running the
wget commands as specified.
After this, the
b.txt file should be generated, since it
does not exist, and now both of its prerequisites do. This will cause
head commands to be run, as specified,
and in order.
And then your program should terminate, since there is nothing else to do.
Notice that the target
c never gets generated, since its
single prerequisite does not exist.