
JAVA=/usr/bin/java
OUTPUT=output
GENERATED=generated
GRAMMAR1=PlSqlParser.g4
GRAMMAR2=PlSqlLexer.g4

# here is where you plug in the runtime for your OS
RUNTIME=runtime-linux
CC=g++
CCARGS=-c -I $(RUNTIME)/antlr4-runtime/ -I $(GENERATED) -std=c++11
LDARGS=-g
LIBS=$(RUNTIME)/lib/libantlr4-runtime.a

all: parser

parser: dirs antlr4 example.cpp
	$(CC) $(CCARGS) example.cpp  -o $(OUTPUT)/example.o 
	$(CC) $(CCARGS) $(GENERATED)/PlSqlParserBaseListener.cpp -o $(OUTPUT)/PlSqlParserBaseListener.o 
	$(CC) $(CCARGS) $(GENERATED)/PlSqlLexer.cpp -o $(OUTPUT)/PlSqlLexer.o 
	$(CC) $(CCARGS) $(GENERATED)/PlSqlParserListener.cpp -o $(OUTPUT)/PlSqlParserListener.o 
	$(CC) $(CCARGS) $(GENERATED)/PlSqlParser.cpp -o $(OUTPUT)/PlSqlParser.o 
	
	#$(CC) $(LDARGS) $(OUTPUT)/parser.o $(OUTPUT)/PlSqlBaseListener.o $(OUTPUT)/PlSqlLexer.o $(OUTPUT)/PlSqlListener.o $(OUTPUT)/PlSqlParser.o $(LIBS) -o parser
	$(CC) $(LDARGS) $(OUTPUT)/example.o $(OUTPUT)/PlSqlLexer.o $(OUTPUT)/PlSqlParser.o $(LIBS) -o example

antlr4: $(GRAMMAR1) $(GRAMMAR2)
	$(JAVA) -jar antlr-4.7-complete.jar -Dlanguage=Cpp -o $(GENERATED) $(GRAMMAR1) $(GRAMMAR2)

dirs:
	mkdir -p $(OUTPUT) 
	mkdir -p $(GENERATED) 

clean:
	rm -rf $(OUTPUT)
	rm -rf $(GENERATED)
