# Standard CS61B Makefile definitions for Java # Targets: # all: All classes compiled from files listed in JAVA_SRC # clean: Clean up compiled .class files and other junk # test: Run standard tests listed in $(TESTS). # # Assumes that you have defined JAVA_SRC (list of .java files) # The limit on the number of 512-byte blocks of file that any program # can create during testing. Set FILE_LIMIT to another figure AFTER # including this file to change it. FILE_LIMIT = 200 # Default Java compiler JC = javac # Default flags to Java compiler JFLAGS = -g JAVA_SRC += $(SRCS) CLASSES = $(JAVA_SRC:.java=.class) # Default rule for random Java compilation (so that typing gmake foo.class # compiles foo.java). %.class: %.java $(JC) $(JFLAGS) $< # Default target. Typing plain 'gmake' compiles RatioCalc.class (and # Rational.class, if needed. all: $(CLASSES) $(CLASSES): $(JAVA_SRC) $(JC) $(JFLAGS) $(JAVA_SRC) # Typing 'gmake test' runs all the input files listed in TESTS through # the program. The FILTER_OUTPUT command is applied to the output of the # program before the output is compared against a standard output file # (same name as the input file, but with the suffix .std). If you don't # define FILTER_OUTPUT, the output is compared verbatim. If the input file # is named F and a file F.args exists, then the contents of F.args is used # as command-line arguments to the program. That is, the test performed is # java $(MAIN_CLASS) contents-of-F.args < F # The ulimit command limits the sizes of the files produced so as to prevent # a runaway program. This command only works on the Intel Solaris machines. # test: $(TESTS) $(PROG) @ulimit -f $(FILE_LIMIT); code=0; \ for tst in $(TESTS); do \ /bin/rm -f $${tst}.results $${tst}.tmp; \ if [ -r $${tst}.args ]; then \ args="`cat $${tst}.args`"; \ else \ args=; \ fi; \ echo "Test: java $(MAIN_CLASS) $${args} < $${tst}"; \ if java $(MAIN_CLASS) $${args} < $${tst} > $${tst}.tmp 2>&1; then \ if [ -z "$(FILTER_OUTPUT)" ]; then \ mv $${tst}.tmp $${tst}.results; \ else \ $(FILTER_OUTPUT) < $${tst}.tmp > $${tst}.results; \ fi; \ if cmp $${tst}.results $${tst}.std >/dev/null 2>&1; then \ echo " Input $${tst} OK."; \ else \ echo "Differences found (<: from program; >: correct):"; \ diff $${tst}.results $${tst}.std; \ code=1; \ fi; \ else \ echo " Execution failed for input $${tst}."; \ code=1; \ fi; \ done; \ exit $$code clean:: /bin/rm -f *~ "#"* core */*~ */"#"* */core *.tmp */*.tmp /bin/rm -f $(CLASSES) $(TESTS:%=%.results)