CC=g++
DEV=-Wall -g -std=c++14
OPT=-O3 -std=c++14

# explanatioin for compiler options
# https://web.stanford.edu/class/cs193d/handouts/make.pdf

JSON=json.hpp

CREATE_DATA_SRC=createsortingdata.cxx createheapoperationdata.cxx
CREATE_DATA_EXE=$(CREATE_DATA_SRC:.cxx=.exe)

TEST_DATA_SRC=testCode.cxx
TEST_DATA_EXE=$(TEST_DATA_SRC:.cxx=.exe)

PRIORITY_SOURCES=priorityqueue.cpp
PRIORITY_HEADERS=$(PRIORITY_SOURCES:.cpp=.h)
PRIORITY_DEV_OBJ=$(PRIORITY_SOURCES:.cpp=.o)
PRIORITY_OPT_OBJ=$(PRIORITY_SOURCES:.cpp=.o3)

.PHONY: all
all: priority_cla $(CREATE_DATA_EXE) $(TEST_DATA_EXE) 

# Priority Queue
.PHONY: $(PRIORITY_CLA)
priority_cla: $(PRIORITY_DEV_OBJ) $(PRIORITY_OPT_OBJ)

$(CREATE_DATA_EXE): %.exe: %.cxx $(JSON)
	$(CC) $(OPT) $< -o $@

# priority queue objects(?)
$(PRIORITY_DEV_OBJ): %.o: %.cpp %.h
	$(CC) $(DEV) -c $< -o $@

$(PRIORITY_OPT_OBJ): %.o3: %.cpp %.h
	$(CC) $(OPT) -c $< -o $@

# test code executable
$(TEST_DATA_EXE): %.exe: %.cxx $(PRIORITY_OPT_OBJ)
	$(CC) $(OPT) $< -o $@


# Build
.PHONY: clean
clean:
	rm -f *.o
	rm -f *.o3
	rm -f *.exe
	rm -rf *.exe.dSYM

.PHONY: update
update:
	make clean
	make all
