# SI 413 Fall 2021
# Lab 4
# Makefile for simple calculator

CXX = g++
CXXFLAGS = -Wall -Wextra -Wno-unused-function

# Since it is the first rule, it is what will get made if
# we call "make" with no arguments.
calc: calc.tab.o lex.yy.o colorout.hpp
	$(CXX) $(CXXFLAGS) -o calc lex.yy.o calc.tab.o

# Bison generates a C++ source file and a C++ header file.
calc.tab.cpp calc.tab.hpp: calc.ypp
	bison -d calc.ypp

# Flex generates just a C++ source file.
lex.yy.cpp: calc.lpp
	flex -o lex.yy.cpp calc.lpp

# The lex file includes the header from Bison.
lex.yy.o: lex.yy.cpp calc.tab.hpp
	$(CXX) $(CXXFLAGS) -c lex.yy.cpp

calc.tab.o: calc.tab.cpp
	$(CXX) $(CXXFLAGS) -c calc.tab.cpp

# The following line makes "make" automatically clean up these
# files for you when they are no longer needed.
.INTERMEDIATE: calc.tab.o lex.yy.o lex.yy.cpp calc.tab.cpp calc.tab.hpp

# Run "make clean" to clear all extra files.
clean:
	-rm -f *.o *.yy.cpp *.tab.?pp calc

# Do "make run" to run your program... this is used in the submit system
run: compile
	@./calc

# used by the auto-tester to compile silently
compile:
	@$(MAKE) -s calc

# This is how we tell make that these two targets aren't actual files.
.PHONY: clean run compile