# Define our compilers.................................
#
# MVAPICH2
MPI_HOME=/v/linux26_x86_64/opt/mvapich2/1.5.1p1-intel
F90    = $(MPI_HOME)/bin/mpif90
F77    = $(MPI_HOME)/bin/mpif90
CC     = $(MPI_HOME)/bin/mpicc

#AR=ar
AR=xiar
#BITS=_v0.2a-intel_11.1.064-mvapich2_1.5.1p1
BITS=_v0.2a-intel_12.0.4-mvapich2_1.5.1p1

#IMKL = /fs/local/linux26_x86_64/opt/intel/Compiler/2011.4.191/composerxe-2011.4.191/mkl/include
#IMKL = /v/linux26_x86_64/opt/intel/mkl/10.2.4.032/include
#IMKL = /v/linux26_x86_64/opt/intel/Compiler/11.1/064/mkl/include
#INCLUDE=-I$(IMKL)

# Define FORTRAN compiler flags.......................
#
# For the PGI compiler
#F90FLAGS  = -O2 -heap-arrays 10
#F77FLAGS  = -O2 -heap-arrays 10
#F90FLAGS  = -fast
#F77FLAGS  = -fast
F90FLAGS  = -O0 -fp-model strict -g -debug all -traceback -heap-arrays 10
F77FLAGS  = -O0 -fp-model strict -g -debug all -traceback -heap-arrays 10
#F90FLAGS  = -O0 -check all -warn all,nodec,interfaces -gen_interfaces -traceback -fpe0
#F77FLAGS  = -O0 -check all -warn all,nodec,interfaces -gen_interfaces -traceback -fpe0

# Define C compiler flags.............................
#
#CFLAGS  = -O2 -I.
#CFLAGS  = -fast -I.
CFLAGS  = -O0 -I. -fp-model strict -g -debug all -traceback
#CFLAGS  = -O0 -check all -warn all,nodec,interfaces -gen_interfaces -traceback -fpe0

# Libraries.............................

# Intel MKL libs
#LMKL = /fs/local/linux26_x86_64/opt/intel/Compiler/2011.4.191/composerxe-2011.4.191/mkl/lib/intel64
#LMKL = /v/linux26_x86_64/opt/intel/mkl/10.2.4.032/lib/64
#LMKL = /v/linux26_x86_64/opt/intel/Compiler/11.1/064/mkl/lib/em64t
LMKL =

# MPI
MPI = -L$(MPI_HOME)/lib -lmpich

#WSMP = /home/u1/dwhipp/software/wsmp/v11.05.20/wsmp-Linux64-Intel/lib/mpi2
WSMP = $(USERAPPL)/software/wsmp/v12.12.12/wsmp-Linux64-Intel/lib/11.1/mvapich2
#WSMP = $(USERAPPL)/software/wsmp/v13.01.30/wsmp-Linux64-Intel/lib/intelmpi
#WSMP = $(USERAPPL)/software/wsmp/v13.01.30/wsmp-Linux64-Intel/lib/openmpi

LIBS = \
 -LOCTREE -lOctree$(BITS) \
 -LNN -lnn_f$(BITS) \
 -LNN -lnn_c$(BITS) \
 -LCASCADE -lcascade$(BITS) \
 -LRESAMPLE -lresample$(BITS) \
 -L$(WSMP) -lpwsmp64 \
 -L$(LMKL) -lmkl_scalapack_lp64 -lmkl_intel_lp64 -lmkl_sequential \
 -lmkl_core -lmkl_blacs_intelmpi_lp64 -lm \
 $(MPI) -lpthread

 #-L$(LMKL) -lmkl_scalapack_lp64 -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lmkl_blacs_intelmpi_lp64 -lpthread -lm
 # ORIGINAL BELOW
 #-L$(LMKL) -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 \
 #-L$(LMKL) -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread \

# The Makefiles look at compile output with this
PAGER=more

# compile rules.......................................
#
COMPILE_OUT=$(NAME)$(BITS).compile
.SUFFIXES:
.SUFFIXES: .o .c .f .f90
.f90.o:
	@echo "--"                                   >>$(COMPILE_OUT) 2>&1
	@echo "$(F90) $(F90FLAGS) $(INCLUDES) -c $<" >>$(COMPILE_OUT) 2>&1
	$(F90) $(F90FLAGS) $(INCLUDES) -c $<         >>$(COMPILE_OUT) 2>&1

.f.o:
	@echo "--"                                   >>$(COMPILE_OUT) 2>&1
	@echo "$(F77) $(F77FLAGS) $(INCLUDES) -c $<" >>$(COMPILE_OUT) 2>&1
	$(F77) $(F77FLAGS) $(INCLUDES) -c $<         >>$(COMPILE_OUT) 2>&1

.c.o:
	@echo "--"                                 >>$(COMPILE_OUT) 2>&1
	@echo "$(CC) $(CFLAGS) -c $<"              >>$(COMPILE_OUT) 2>&1
	$(CC) $(CFLAGS) -c $<                      >>$(COMPILE_OUT) 2>&1