.PHONY:

CXX_COMPILER  := g++-11
COMPILE_FLAGS := -std=c++14 -O3
PYTHON        := python3.10

LIBS := -lfunc -larmadillo
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S), Linux)
LINKING_FLAGS := $(LIBS) -fopenmp -lquadmath # assuming g++ is from the gcc
endif

ifeq ($(UNAME_S), Darwin)
LINKING_FLAGS := $(LIBS) -Xpreprocessor -fopenmp -lgomp
#LINKING_FLAGS := $(LIBS)
#LINKING_FLAGS := $(LIBS) -lquadmath -fopenmp # assuming g++ is from the gcc
endif

all: python_branch_prediction

python_branch_prediction: branch_prediction
	$(PYTHON) plot.py "ChebyInterpTable<1>.txt" "ChebyInterpTable<3>.txt" "ChebyInterpTable<7>.txt"


SIZE := 33554432
NTABLES := 300
NTRIALS := 300
NEVALS := 100000
SEED := 0


#SIZE := 65536
#NTABLES := 30
#NTRIALS := 100
#NEVALS := 100000
#SEED := 0


# define a macro for changing the current LUT of interest
branch_prediction: branch_prediction.cpp
	$(CXX_COMPILER) $(COMPILE_FLAGS) -DTABLE_DEGREE=1 $< -o $@ $(LINKING_FLAGS)
	time ./$@ $(SIZE) $(NTABLES) $(NTRIALS) $(NEVALS) $(SEED) > "ChebyInterpTable<1>.txt"
	$(CXX_COMPILER) $(COMPILE_FLAGS) -DTABLE_DEGREE=3 $< -o $@ $(LINKING_FLAGS)
	time ./$@ $(SIZE) $(NTABLES) $(NTRIALS) $(NEVALS) $(SEED) > "ChebyInterpTable<3>.txt"
	$(CXX_COMPILER) $(COMPILE_FLAGS) -DTABLE_DEGREE=7 $< -o $@ $(LINKING_FLAGS)
	time ./$@ $(SIZE) $(NTABLES) $(NTRIALS) $(NEVALS) $(SEED) > "ChebyInterpTable<7>.txt"

clean:
	rm -f branch_prediction 
