CC=g++

LIBSRCS=utils.cpp
LIBOBJS=$(LIBSRCS:.cpp=.o)

CLASSSRCS=PenningTrap.cpp Particle.cpp
CLASSOBJS=$(CLASSSRCS:.cpp=.o)

INCLUDE=../include

CFLAGS=-Wall -larmadillo -std=c++11 -O3 -fomit-frame-pointer
#CFLAGS=-Wall -larmadillo -lblas -llapack -std=c++11 -O3 -fomit-frame-pointer
OPENMP=-fopenmp

# Add a debug flag when compiling (For the DEBUG macro in utils.hpp)
DEBUG ?= 0
ifeq ($(DEBUG), 1)
	DBGFLAG=-DDBG
else
	DBGFLAG=
endif

# Add profiling for serial code
PROFILE ?= 0
ifeq ($(PROFILE), 1)
	PROFFLAG=-pg -fno-inline-functions
else
	PROFFLAG=
endif

.PHONY: clean

all: test_suite main

# Instrumentation using scorep for parallel analysis
instrument:
	scorep $(CC) -c PenningTrap.cpp -o PenningTrap.o $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
	scorep $(CC) -c Particle.cpp -o Particle.o $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
	scorep $(CC) -c utils.cpp -o utils.o $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
	scorep $(CC) -c main.cpp -o main.o $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
	scorep $(CC) $(LIBOBJS) $(CLASSOBJS) main.o -o main $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)
	



# Rules for executables
main: main.o $(LIBOBJS) $(CLASSOBJS)
	$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)

frequency_narrow_sweeps_long: frequency_narrow_sweeps_long.o $(LIBOBJS) $(CLASSOBJS)
	$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)


test_suite: test_suite.o $(LIBOBJS) $(CLASSOBJS)
	$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)

# Rule for object files
%.o: %.cpp
	$(CC) -c $^ -o $@ $(CFLAGS) $(DBGFLAG) $(PROFFLAG) -I$(INCLUDE) $(OPENMP)

clean:
	rm *.o
	rm test_suite
	rm main 
