#compiler	=icpc
#CANTERA_DIR	=/opt/scientific/cantera-2.3_intel_mkl
#IDA_DIR		=/opt/scientific/sundials-3.1.1_intel_mkl
#EXE		=lagrangianCombustion2
#DESTDIR		=~/bin

compiler	=g++
CANTERA_DIR	=/opt/scientific/cantera-2.4_gnu_blas
IDA_DIR		=/opt/scientific/sundials-3.1.1_intel_mkl
EXE		=DropletCombustionTest7-C7_C12
#DESTDIR		=~/bin
DESTDIR		= ../example

CANTERA_INCLUDES=-I$(CANTERA_DIR)/include
GSL_INCLUDES	=-I/usr/include/gsl
GSL_LIBS 	=-L/usr/lib -lgsl -lgslcblas
IDA_INCLUDES	=-I$(IDA_DIR)/include
SUN_INCLUDES	=-I$(IDA_DIR)/include
IDA_LIBS	=-L$(IDA_DIR)/lib -lsundials_nvecopenmp \
		 -lsundials_ida -lsundials_sunlinsollapackband
CANTERA_LIBS 	=-L$(CANTERA_DIR)/lib -lcantera_shared
RPATH		=-Wl,-rpath=$(IDA_DIR)/lib,-rpath=$(CANTERA_DIR)/lib
RM=rm -f

compiler?=g++

ifeq ($(compiler),g++)
ifeq ($(MAKECMDGOALS),debug)
CPPFLAGS= -Wall -g3 -ggdb
else
CPPFLAGS= -Wall -O3
endif
CPP=g++
endif

ifeq ($(compiler),icpc)
	export GXX_INCLUDE=/usr/lib/gcc/x86_64-pc-linux-gnu/7.4.1/include/c++
	CPPFLAGS= -Wall -O3 -gxx-name=/usr/bin/g++-7 -std=c++11
	CPP=icpc
endif

OBJS = parse.o UserData.o gridRoutines.o residue.o solution.o main.o 

all: $(EXE)

# pull in dependency info for *existing* .o files
-include $(OBJS:.o=.d)

parse.o: parse.cpp parse.h parse.hpp
	$(CPP) $(CPPFLAGS) -c parse.cpp -o parse.o
	$(CPP) -MM parse.cpp > parse.d

solution.o: solution.cpp solution.h 
	$(CPP) $(CPPFLAGS) $(CANTERA_INCLUDES) $(IDA_INCLUDES) \
		-c solution.cpp -o solution.o
	$(CPP) -MM $(CANTERA_INCLUDES) $(IDA_INCLUDES) \
		solution.cpp > solution.d

residue.o: residue.cpp residue.h UserData.h gridRoutines.h
	$(CPP) $(CPPFLAGS) $(CANTERA_INCLUDES) \
		$(IDA_INCLUDES) $(GSL_INCLUDES) -c residue.cpp \
		-o residue.o -fopenmp
	$(CPP) -MM $(CANTERA_INCLUDES) \
		$(IDA_INCLUDES) $(GSL_INCLUDES) \
		residue.cpp > residue.d

gridRoutines.o: gridRoutines.cpp gridRoutines.h parse.h
	$(CPP) $(CPPFLAGS) -c gridRoutines.cpp -o gridRoutines.o
	$(CPP) -MM gridRoutines.cpp > gridRoutines.d

UserData.o: UserData.cpp UserData.h gridRoutines.h parse.h 
	$(CPP) $(CPPFLAGS) $(CANTERA_INCLUDES) \
		-c  UserData.cpp -o UserData.o
	$(CPP) -MM $(CANTERA_INCLUDES) \
		UserData.cpp > UserData.d

main.o: main.cpp UserData.h solution.h residue.h macros.h
	$(CPP) $(CPPFLAGS) $(CANTERA_INCLUDES) $(IDA_INCLUDES) \
		-c  main.cpp -o main.o
	$(CPP) -MM $(CANTERA_INCLUDES) $(IDA_INCLUDES) \
		main.cpp > main.d

$(EXE): $(OBJS)
	$(CPP) $(CPPFLAGS) $(IDA_INCLUDES) \
		$(CANTERA_INCLUDES) $(GSL_INCLUDES) $(RPATH) \
		$(OBJS) -o $(EXE) -fopenmp $(IDA_LIBS)  \
		$(CANTERA_LIBS) $(GSL_LIBS)

debug: $(EXE)

.PHONY: install
install:
	cp $(EXE) $(DESTDIR)/$(EXE) 

.PHONY: clean
clean:
	rm -f $(EXE) $(OBJS) *.d

