# Makefile for iterativeSystemSolveLegacy example
#
# To compile this example, please ensure that some extra environment
# variables are defined. An example configuration may look like the following:
#
#     export INTEL_ROOT=/opt/intel/composerxe-2011.3.174
#     export INTEL_LIB_PATH_32=$INTEL_ROOT/compiler/lib/ia32
#     export INTEL_LIB_PATH_64=$INTEL_ROOT/compiler/lib/intel64
#
#     export MKL_ROOT=$INTEL_ROOT/mkl
#     export MKL_INC_PATH=$MKL_ROOT/include
#     export MKL_LIB_PATH_32=$MKL_ROOT/lib/ia32
#     export MKL_LIB_PATH_64=$MKL_ROOT/lib/intel64
#
# Due to recent changes in Intel's MKL distribution, this example only supports
# MKL 10.3 or greater.  If you do not have MKL, append 'mkl=0' to your command
# line when calling make.  Similarly, to compile without cuda, use 'cuda=0'
#
# e.g.   make build32 mkl=0
# e.g.   make build32 cuda=0
# e.g.   make build32 mkl=0 cuda=0

include ../common/common.mk

ifeq ($(mkl), 0)
CFLAGS+=-DNO_MKL
else
MKL_INC=-I${MKL_INC_PATH}
MKL_LIB_32=-L${INTEL_LIB_PATH_32} -L${MKL_LIB_PATH_32}
MKL_LIB_64=-L${INTEL_LIB_PATH_64} -L${MKL_LIB_PATH_64}
MKL_LIBS_32=-lmkl_intel -lmkl_intel_thread -lmkl_core
MKL_LIBS_64=-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core
endif

ifeq ($(cuda), 0)
CFLAGS+=-DNO_CUDA
else
CUDA_INC=-I${CUDA_INC_PATH}
endif

INCLUDES=-I${CULASPARSE_INC_PATH} ${MKL_INC} ${CUDA_INC}
LIBPATH32=-L${CULASPARSE_LIB_PATH_32} ${MKL_LIB_32}
LIBPATH64=-L${CULASPARSE_LIB_PATH_64} ${MKL_LIB_64}

LIBS=-lcula_sparse -lcolamd -lcublas -lcudart -lcusparse -lpthread -liomp5

usage:
	@echo "To build this example, type one of:"
	@echo ""
	@echo "    make build32"
	@echo "    make build64"
	@echo ""
	@echo "where '32' and '64' represent the platform you wish to build for"
	@echo ""
	@echo "Note that this example requires Intel MKL 10.3 or greater to build"

build32:
	sh ../checkenvironment.sh
	${CC} -m32 -o iterativeSystemSolveLegacy iterativeSystemSolveLegacy.c $(CFLAGS) $(INCLUDES) $(LIBPATH32) $(MKL_LIBS_32) $(LIBS)

build64:
	sh ../checkenvironment.sh
	${CC} -m64 -o iterativeSystemSolveLegacy iterativeSystemSolveLegacy.c $(CFLAGS) $(INCLUDES) $(LIBPATH64) $(MKL_LIBS_64) $(LIBS)

clean:
	rm -f iterativeSystemSolveLegacy

