# This is the name of your program. The class dictionary file should # be $(PROG).cd, and the behavior file should be $(PROG).beh. PROG = program # This is the name of the class which has the "main" method. MAIN = Main # This is the directory into which .java files are generated. GENDIR = ./gen # This is the directory into which .class files are generated. CLASSDIR = ./gen # This is the package your generated code belongs to. It should match # the package specified at the beginning of your .cd file. PACKAGE = # Arguments for testing the program. TEST_ARGS = < $(PROG).input # Files the program test depends on. Probably some subset of $(TEST_ARGS). TEST_DEPS = $(PROG).input # Make sure these are all in your $PATH: # interpreter JAVA = java # compiler JAVAC = CLASSPATH=$(CLASSDIR):$$CLASSPATH javac -d $(CLASSDIR) # Demeter compiler DEMJAVA = demjava # parser generator PARSEGEN = jack #### # You shouldn't have to change anything below here. #### ifeq (,$(PACKAGE)) PACKAGE_PREFIX = PACKAGE_DIR = $(CLASSDIR) else PACKAGE_PREFIX = $(PACKAGE). PACKAGE_DIR = $(CLASSDIR)/$(subst .,/,$(PACKAGE)) endif MAIN_TARGET = $(PACKAGE_DIR)/$(MAIN).class SRC = $(GENDIR)/*.java GRAMMAR = $(PROG).jack PARSER = Parser.java all: $(MAIN_TARGET) $(MAIN_TARGET): $(GENDIR)/code $(GENDIR)/grammar $(GENDIR)/$(PARSER) @$(MAKE) --no-print-directory $(GENDIR)/compile @touch $(MAIN_TARGET) $(GENDIR)/code: $(PROG).cd $(PROG).beh @mkdir -p $(GENDIR) $(DEMJAVA) -code -outputdir $(GENDIR) $(PROG) @touch $@ $(GENDIR)/grammar: $(PROG).cd @mkdir -p $(GENDIR) $(DEMJAVA) -grammar -outputdir $(GENDIR) $(PROG) @touch $@ $(GENDIR)/$(PARSER): $(GENDIR)/$(GRAMMAR) (cd $(GENDIR); $(PARSEGEN) $(GRAMMAR)) $(GENDIR)/compile: $(SRC) @mkdir -p $(CLASSDIR) $(JAVAC) $? @touch $@ $(SRC): test: all $(TEST_DEPS) CLASSPATH=$(CLASSDIR):$$CLASSPATH $(JAVA) $(PACKAGE_PREFIX)$(MAIN) $(TEST_ARGS) clean: $(RM) -r $(GENDIR) $(RM) *~ core new: clean all .PHONY: all test clean new