LIBS=-lc
DYNAMIC_LINKER=/usr/lib/ld-linux-x86-64.so.2


.PRECIOUS: %.cpp
%.cpp: %.l yyTestParser.h
	flex -o $@ $<


yyTestParser.h: parser.cpp
%.cpp: %.y
	bison -v -Wcounterexamples -o $@ $<


%.o: %.cpp
	g++ -o $@ -c $<


test.elf: lexer.o parser.o test.o ast/symboltable.o ast/expression.o ast/statement.o ast/type.o
	g++ -o $@ $^ -lLLVM


.PHONY: run
run: test.elf example.txt
	./test.elf example.txt example.ll
	llc -o example.s example.ll
	as -o example.o example.s
	ld -o example.elf -I${DYNAMIC_LINKER} /usr/lib64/crt1.o example.o ${LIBS}
	./example.elf

	./test.elf example2.txt example2.ll
	lli example2.ll


.PHONY: clean
clean:
	rm -f lexer.cpp parser.cpp parser.output yyTestParser.h *.o *.elf ast/*.o *.ll *.s

