# -*- mode: makefile -*-
# -----------------------------------------------------------------
# Programmer: Slaven Peles, Cody Balos @ LLNL
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2025, 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 CUDA examples
#
# This file is generated from a template using various variables
# set at configuration time. It can be used as a template for
# other user Makefiles.
# -----------------------------------------------------------------

SHELL = sh

prefix       = /workspace/destdir
exec_prefix  = /workspace/destdir
includedir   = /workspace/destdir/include
libdir       = /workspace/destdir/lib

CC          = /opt/bin/x86_64-linux-gnu-libgfortran3-cxx11-cuda+11.4/x86_64-linux-gnu-gcc
CFLAGS      = 
CXX         = /opt/bin/x86_64-linux-gnu-libgfortran3-cxx11-cuda+11.4/x86_64-linux-gnu-g++
CXXFLAGS    = 
NVCC        = /workspace/destdir/cuda/bin/nvcc
NVCCFLAGS   = -ccbin=${CXX} -std=c++11  --expt-extended-lambda --expt-relaxed-constexpr
LD          = ${NVCC}
LDFLAGS     =  ${NVCCFLAGS} -Xcompiler \"-Wl,-rpath,${libdir}\"
LIBS        =  -lm -lcusolver -lcusparse

TMP_INCS = ${includedir}
INCLUDES = $(addprefix -I, ${TMP_INCS})

TMP_LIBDIRS  = ${libdir}
LIBDIRS      = $(addprefix -L, ${TMP_LIBDIRS})

TMP_SUNDIALSLIBS = sundials_cvode sundials_nveccuda   sundials_core 
SUNDIALSLIBS     = $(addprefix -l, ${TMP_SUNDIALSLIBS})
LIBRARIES = ${SUNDIALSLIBS} ${LIBS}

EXAMPLES =  cvAdvDiff_kry_cuda cvAdvDiff_kry_cuda_managed cvAdvDiff_diag_cuda 
EXAMPLES_DEPENDENCIES = 

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

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

.SUFFIXES : .o .cu

.c.o :
	${CC} ${CFLAGS} ${INCLUDES} -c $<

.cu.o :
	${NVCC} ${NVCCFLAGS} ${INCLUDES} -c $<

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

all: ${OBJECTS}
	@for i in ${EXAMPLES} ; do \
	  echo "${NVCC} -o $${i} $${i}.o ${OBJECTS_DEPENDENCIES} ${INCLUDES} ${LIBDIRS} ${LIBRARIES} ${LDFLAGS}"; \
	  ${NVCC} -o $${i} $${i}.o ${OBJECTS_DEPENDENCIES} ${INCLUDES} ${LIBDIRS} ${LIBRARIES} ${LDFLAGS}; \
	done

${OBJECTS}: ${OBJECTS_DEPENDENCIES}

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

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

