# -*- mode: makefile -*-
# -----------------------------------------------------------------
# Programmer(s): Cody J. Balos @ LLNL
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2019, Lawrence Livermore National Security
# and Southern Methodist University.
# All rights reserved.
#
# See the top-level LICENSE and NOTICE files for details.
#
# SPDX-License-Identifier: BSD-3-Clause
# SUNDIALS Copyright End
# -----------------------------------------------------------------
# Makefile for CVODE Fortran 2003 interface serial examples
#
# This file is generated from a template using variables
# set at configuration time. It can be used as a template for
# other user Makefiles.
# -----------------------------------------------------------------

SHELL = sh

prefix       = /usr
exec_prefix  = /usr
includedir   = /usr//usr/lib/gcc/x86_64-mandriva-linux-gnu/8.3.1/finclude
libdir       = /usr//usr/lib64

F90         = /usr/bin/gfortran
F90FLAGS    = -O3 -DNDEBUG -O3
F90_LDFLAGS = -O3 -DNDEBUG -O3
F90_LIBS    =  -lm /usr/lib64/librt.so

LINKFLAGS = -Wl,-rpath,/usr//usr/lib64

# -----------------------------------------------------------------------------------------

INCLUDES_KLU  		= /usr/include/suitesparse
TMP_KLU_LIBRARIES = /usr/lib64/libklu.so;/usr/lib64/libamd.so;/usr/lib64/libcolamd.so;/usr/lib64/libbtf.so;/usr/lib64/libsuitesparseconfig.so
LIBRARIES_KLU 		= -lsundials_sunmatrixsparse -lsundials_fsunmatrixsparse_mod \
										-lsundials_sunlinsolklu -lsundials_fsunlinsolklu_mod \
										$(subst ;, , ${TMP_KLU_LIBRARIES})
LINKFLAGS_KLU 		= ${LINKFLAGS}:/usr/lib64

TMP_INCS  = ${includedir} ${INCLUDES_KLU}
INCLUDES  = $(addprefix -I, ${TMP_INCS})
LIBRARIES = -lsundials_cvode -lsundials_fcvode_mod ${LIBS}

# -----------------------------------------------------------------------------------------

EXAMPLES =  cv_analytic_fp cv_analytic_sys_dns cv_analytic_sys_dns_jac cv_brusselator_dns
OBJECTS  = ${EXAMPLES:=.o}

# KLU Examples
EXAMPLES_KLU =  cv_analytic_sys_klu
OBJECTS_KLU  = ${EXAMPLES_KLU:=.o}

# -----------------------------------------------------------------------------------------

.SUFFIXES : .o .f90

.f90.o :
	${F90} ${F90FLAGS} ${INCLUDES} -c $<

# -----------------------------------------------------------------------------------------

all: examples examples_klu

examples: ${OBJECTS}
	@for i in ${EXAMPLES} ; do \
	  echo "${F90} -o $${i} $${i}.o ${F90_LDFLAGS} ${F90_LIBS} ${INCLUDES} -L${libdir} ${LIBRARIES} ${LINKFLAGS}" ; \
	  ${F90} -o $${i} $${i}.o ${F90_LDFLAGS} ${F90_LIBS} ${INCLUDES} -L${libdir} ${LIBRARIES} ${LINKFLAGS} ; \
	done

examples_klu: ${OBJECTS_KLU}
	@for i in ${EXAMPLES_KLU} ; do \
	  echo "${F90} -o $${i} $${i}.o ${F90_LDFLAGS} ${F90_LIBS} ${INCLUDES} -L${libdir} ${LIBRARIES} ${LIBRARIES_KLU} ${LINKFLAGS_KLU}" ; \
	  ${F90} -o $${i} $${i}.o ${F90_LDFLAGS} ${F90_LIBS} ${INCLUDES} -L${libdir} ${LIBRARIES} ${LIBRARIES_KLU} ${LINKFLAGS_KLU} ; \
	done

clean:
	rm -f *.mod
	rm -f ${OBJECTS} ${OBJECTS_KLU}
	rm -f ${EXAMPLES} ${EXAMPLES_KLU}

# -----------------------------------------------------------------------------------------
