# -*- mode: makefile -*-
# -----------------------------------------------------------------
# Programmer(s): Radu Serban, Cody Balos @ LLNL
#                Daniel R. Reynolds @ SMU
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2021, 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 @SOLVER@ PETSc 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 = @SHELL@

prefix       = @prefix@
exec_prefix  = @exec_prefix@
includedir   = @includedir@
libdir       = @libdir@

CPP      = @CPP@
CPPFLAGS = @CPPFLAGS@
CC       = @CC@
CFLAGS   = @CFLAGS@
LDFLAGS  = @LDFLAGS@
LIBS     = @LIBS@

LINKFLAGS = -Wl,-rpath,@libdir@

MPICC       = @MPICC@
MPI_INC_DIR = @MPI_INC_DIR@
MPI_LIB_DIR = @MPI_LIB_DIR@
MPI_LIBS    = @MPI_LIBS@
MPI_FLAGS   = @MPI_FLAGS@

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

PETSC_LIBRARIES = @PETSC_LIBRARIES_@
INCLUDES_PETSC  = @PETSC_INCLUDES_@
LIBRARIES_PETSC = $(subst ;, , ${PETSC_LIBRARIES})
LINKFLAGS_PETSC = ${LINKFLAGS}

TMP_INCS = ${includedir} ${MPI_INC_DIR} ${INCLUDES_PETSC}
INCLUDES = $(addprefix -I, ${TMP_INCS})
LIBRARIES = -l@SOLVER_LIB@ -lsundials_nvecpetsc -lsundials_sunnonlinsolpetscsnes ${LIBS} ${LIBRARIES_PETSC}

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

EXAMPLES = @EXAMPLES@
EXAMPLES_DEPENDENCIES = @EXAMPLES_DEPENDENCIES@

OBJECTS = ${EXAMPLES:=.o}
OBJECTS_DEPENDENCIES = ${EXAMPLES_DEPENDENCIES:=.o}

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

.SUFFIXES : .o .c

.c.o :
	${MPICC} ${CPPFLAGS} ${CFLAGS} ${MPI_FLAGS} ${INCLUDES} -c $<

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

all: ${OBJECTS}
	@for i in ${EXAMPLES} ; do \
	  echo "${MPICC} -o $${i} $${i}.o ${OBJECTS_DEPENDENCIES} ${MPI_FLAGS} ${CFLAGS} ${LDFLAGS} ${INCLUDES} -L${libdir} ${LIBRARIES} -L${MPI_LIB_DIR} ${MPI_LIBS} ${LINKFLAGS_PETSC}" ; \
	  ${MPICC} -o $${i} $${i}.o ${OBJECTS_DEPENDENCIES} ${MPI_FLAGS} ${CFLAGS} ${LDFLAGS} ${INCLUDES} -L${libdir} ${LIBRARIES} -L${MPI_LIB_DIR} ${MPI_LIBS} ${LINKFLAGS_PETSC} ; \
	done

${OBJECTS}: ${OBJECTS_DEPENDENCIES}

clean:
	rm -f ${OBJECTS_DEPENDENCIES}
	rm -f ${OBJECTS}
	rm -f ${EXAMPLES}

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