# Makefile for iterativeSystemSolveFortran example

include ../common/common.mk

INCLUDES=-I${CULASPARSE_INC_PATH}
LIBPATH32=-L${CULASPARSE_LIB_PATH_32}
LIBPATH64=-L${CULASPARSE_LIB_PATH_64}

LIBS=-lcula_sparse -lcolamd -lcublas -lcudart -lcusparse -liomp5
MODULES=${CULASPARSE_INC_PATH}/cula_sparse_legacy.f90

GFORVERSION := `${FC} --version | sed '/^$$/ d' | sed -n "1{s/.* \\([0-9]\+\\.[0-9]\\).*/\\1/p};"`
GFORVERSIONGTEQ43 := $(shell echo "4.3 >= $(GFORVERSION)" | bc)

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"

check_compiler:
ifneq ($(GFORVERSIONGTEQ43),0)
	@echo Your Fortran compiler version $(GFORVERSION) does not support ISO_C_BINDINGS - stopping compilation
	@false
endif

build32:
	sh ../checkenvironment.sh
	gfortran -m32 -o iterativeSystemSolveFortran $(MODULES) iterativeSystemSolveFortran.f90 $(CFLAGS) $(INCLUDES) $(LIBPATH32) $(LIBS)

build64:
	sh ../checkenvironment.sh
	gfortran -m64 -o iterativeSystemSolveFortran $(MODULES) iterativeSystemSolveFortran.f90 $(CFLAGS) $(INCLUDES) $(LIBPATH64) $(LIBS)

clean:
	rm -f iterativeSystemSolveFortran
	rm -f *.mod

