# -*- mode: makefile -*-
# -----------------------------------------------------------------
# Programmer: Slaven Peles, Cody Balos @ LLNL
# -----------------------------------------------------------------
# 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@ 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 = @SHELL@

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

CC      	  = @MPI_C_COMPILER@
CFLAGS      = @CMAKE_C_FLAGS@
CXX         = @MPI_CXX_COMPILER@
NVCC        = @CMAKE_CUDA_COMPILER@
NVCCFLAGS   = $(subst ;, ,@CMAKE_CUDA_FLAGS@)
MPI_LIBS    = $(subst ;, ,@MPI_CXX_LIBRARIES@)
MPI_INC_DIR = @MPI_CXX_INCLUDE_PATH@
LD          = ${NVCC}
LDFLAGS     = @LDFLAGS@ -Xcompiler \"-Wl,-rpath,${libdir}\"
LIBS        = @LIBS@ ${MPI_LIBS}

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

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

TMP_SUNDIALSLIBS = @SOLVER_LIB@ sundials_nvecparallel sundials_nveccuda sundials_nvecserial \
									sundials_nvecmpimanyvector sundials_nvecmpiplusx
SUNDIALSLIBS     = $(addprefix -l, ${TMP_SUNDIALSLIBS})
LIBRARIES = ${SUNDIALSLIBS} ${LIBS}

EXAMPLES = @EXAMPLES@ @EXAMPLES_BL@
EXAMPLES_DEPENDENCIES = @EXAMPLES_DEPENDENCIES@

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

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

.SUFFIXES : .o .cu

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

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

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

all: ${OBJECTS}
	@for i in ${EXAMPLES} ; do \
	  echo "${LD} -o $${i} $${i}.o ${OBJECTS_DEPENDENCIES} ${INCLUDES} ${LIBDIRS} ${LIBRARIES} ${LDFLAGS}"; \
	  ${LD} -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}

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

