ifeq ($(MPI),1)
FC = mpifort
CC = mpicc
CXX = mpicxx
else
FC = gfortran
CC = gcc
CXX = g++
endif

LD = $(FC)


# Archive tool
AR = ar rv

# default flags
# --------------
# free-line-length-none : turn of line length limitation (why is this not a default??)
# cpp  					: perform preprocessing
# fPIC                  : for compiling a shared object library
FFLAGS += -ffree-line-length-none -cpp -fPIC -fno-stack-arrays 
CXXFLAGS += -std=c++11 -fPIC
CFLAGS += -fPIC

# -fallow-argument-mismatch required for gfortran >= 10 (added unconditionally for Windows compatibility)
FFLAGS += -fallow-argument-mismatch

# Using MinGW on Windows — always use -lstdc++
LDLIBS += -lstdc++

# Windows build — no RPATH needed
RPATH=

ifeq ($(DEBUG),1)
# Debugging mode
# --------------
# g             : enable gnu debugger compatibility
# O0            : no optimisation
# Wall          : all warnings
# Wextra        : even more warnings
# pedantic      : check for language features not part of f95 standard
# implicit-none : specify no implicit typing 
# backtrace     : produce backtrace of error
# fpe-trap      : search for floating point exceptions (dividing by zero etc)
# fbounds-check : check array indices
FFLAGS += -g -O0 -Wall -Wextra -pedantic -fcheck=all -fimplicit-none -fbacktrace -ffpe-trap=zero,overflow 
#
CXXFLAGS += -g -O0 -Wall -Wextra -Wshadow -Weffc++
CFLAGS += -g -O0 -Wall -Wextra -Wshadow -Weffc++
else
# Optimised mode
# --------------
# Ofast : maximum optimisation
FFLAGS += -Ofast
CXXFLAGS += -Ofast
CXFLAGS += -Ofast
endif
