You're going to create a fairly simple makefile that performs some basic, common tasks. Compile a C program. Run a C program. Run a Python program. Compile and run a java program. Check for a README, display it. Compare 2 files. Clean up intermediary files.
Go through the steps below, adding 1 target at a time (and testing!) to your makefile.
Create a directory for this lab, then copy the following files from ~kschmidt/public_html/CS265/Labs/Makefiles :
You will create a makefile called Makefile, and fill that in as follows:
Create a target called foo.o . It will depend upon the files foo.c and foo.h . Here is the command that would do it:
$(cc) -c foo.c
Create a target called main.o . It will depend upon the files main.c and foo.h . Here is the command that would do it:
$(cc) -c main.c
Now we want to make the executable from those object files. Create a target called $(EXE), which would depend upon the files foo.o and main.o . Here is the command that would do it:
$(cc) -o$(EXE) main.o foo.o
To test this file, you would type make foo .
Now we want to run the program. Create a target called run-c, which would depend upon the file $(EXE) . Here is the command that would do it:
Create a target called read that checks for a file called README ; if it exists, display it using $(PAGER), from above.
Note that you don't want to list any dependencies here. We don't want make to yell at us if README doesn't exist; we want to check, quietly.
Create a target called foo.class . It will depend upon the file foo.java . Here is the command that would do it:
Create a target called run-java . It will depend upon the file foo.class . Here is the command that would do it:
Create a target called save-java , that will run your java program, but redirect the output to $(TEST_OUT). But for the redirection, this target will look very much like the previous one.
Create a target called test-java . We want to compare your output w/the expected output. It'll depend on the 2 output files, $(TEST_OUT) and $(EXP_OUT) . Here're the bash lines that would do it:
-@if diff $(TEST_OUT) $(EXP_OUT) &> /dev/null ; then \ echo "Passed!" ;\ else \ echo "Not the same!" ;\ fi
Create a target called clean that cleans up all generated files (the object files, the class file, the executable, and the test.out file).
Finally, note that clean run-py run-c read run-java save-java and test-java are all phony targets. Note this, near the top, under the variables.
Submit this Makefile along w/the files from the other parts of the lab.