# -*- mode: makefile -*-
# -----------------------------------------------------------------
# Programmer(s): Radu Serban, Cody Balos @ LLNL
#                Daniel R. Reynolds @ UMBC
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2025-2026, Lawrence Livermore National Security,
# University of Maryland Baltimore County, and the SUNDIALS contributors.
# Copyright (c) 2013-2025, Lawrence Livermore National Security
# and Southern Methodist University.
# Copyright (c) 2002-2013, Lawrence Livermore National Security.
# All rights reserved.
#
# See the top-level LICENSE and NOTICE files for details.
#
# SPDX-License-Identifier: BSD-3-Clause
# SUNDIALS Copyright End
# -----------------------------------------------------------------
# Makefile for ARKODE 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 = sh

prefix       = /usr
exec_prefix  = /usr
includedir   = /usr/include
libdir       = /usr/lib64/mpich/lib

CPP      = /usr/lib64/mpich/bin/mpic++
CPPFLAGS = -DNDEBUG
CC       = /usr/lib64/mpich/bin/mpicc
CFLAGS   = -O2  -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -mbranch-protection=standard -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -I/usr/include/flexiblas
LDFLAGS  = 
LIBS     =  -lm

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

MPICC       = /usr/lib64/mpich/bin/mpicc
MPI_INC_DIR = .
MPI_LIB_DIR = .
MPI_LIBS    = 
MPI_FLAGS   = 

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

PETSC_LIBRARIES = -L/usr/lib64/mpich/lib;-lpetsc;-lhdf5
INCLUDES_PETSC  = /usr/include/mpich-aarch64/petsc
LIBRARIES_PETSC = $(subst ;, , ${PETSC_LIBRARIES})
LINKFLAGS_PETSC = ${LINKFLAGS}

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

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

EXAMPLES =  ark_petsc_ex25
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}

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