GRAMMAR=GnuLd.g4 G4_PACKAGE ?= io.trygvis.ld.antlr PACKAGE_PATH = $(subst .,/,$(G4_PACKAGE)) G4_JAVA=\ $(patsubst %.g4,antlr/$(PACKAGE_PATH)/%Lexer.java,$(GRAMMAR)) # $(patsubst %.g4,antlr/$(PACKAGE_PATH)/%Parser.java,$(GRAMMAR)) \ # $(patsubst %.g4,antlr/$(PACKAGE_PATH)/%Listener.java,$(GRAMMAR)) \ # $(patsubst %.g4,antlr/$(PACKAGE_PATH)/%BaseListener.java,$(GRAMMAR)) G4_CLASSES=$(patsubst antlr/%.java,target/classes/%.class,$(G4_JAVA)) ANTLR_URL=http://repo1.maven.org/maven2/org/antlr/antlr4/4.5.3/antlr4-4.5.3.jar ANTLR_RUNTIME_URL=http://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.5.3/antlr4-runtime-4.5.3.jar ANTLR_JAR=$(notdir $(ANTLR_URL)) ANTLR_RUNTIME_JAR=$(notdir $(ANTLR_RUNTIME_URL)) all: meta-java meta-java: $(G4_JAVA) meta-classes: $(G4_CLASSES) info: @echo "ANTLR_JAR $(ANTLR_JAR)" @echo "GRAMMAR $(GRAMMAR)" @echo "G4_JAVA $(G4_JAVA)" @echo "G4_CLASSES $(G4_CLASSES)" target/classes antlr: mkdir -p $@ download: $(ANTLR_JAR) $(ANTLR_RUNTIME_JAR) $(ANTLR_JAR): wget $(ANTLR_URL) $(ANTLR_RUNTIME_JAR): wget $(ANTLR_RUNTIME_URL) $(G4_JAVA): $(GRAMMAR) | antlr $(ANTLR_JAR) java -cp $(ANTLR_JAR) org.antlr.v4.Tool \ -visitor \ -o antlr/$(PACKAGE_PATH) \ $(patsubst %,-package %,$(G4_PACKAGE)) \ $< $(G4_CLASSES): $(G4_JAVA) | target/classes javac -d target/classes -cp $(ANTLR_JAR) $(wildcard antlr/$(PACKAGE_PATH)/*.java) clean: rm -rf target/classes antlr