#!/usr/bin/env modbuild

# :FIXME: need review!

pbuild::configure() {
	case ${COMPILER} in
	gcc )
		LOADER='mpif90'
		;;
	intel )
		LOADER='mpicc'
		;;
	* )
		die 3 "Oops: unknown compiler: ${COMPILER}"
		;;
	esac
	cat <<EOF > "${SRC_DIR}/make.inc"
PLAT		= 
DSuperLUroot 	= \${PREFIX}
DSUPERLULIB   	= \$(DSuperLUroot)/lib/libsuperlu_dist.a
BLASDEF	     	= -DUSE_VENDOR_BLAS
BLASLIB      	= \${OPENBLAS_PREFIX}/lib/libopenblas.a
METISLIB	= \${PARMETIS_PREFIX}/lib/libmetis.a
PARMETISLIB	= \${PARMETIS_PREFIX}/lib/libparmetis.a
FLIBS	 	= 
LIBS            = \$(DSUPERLULIB) \$(BLASLIB) \$(PARMETISLIB) \$(METISLIB)
ARCH         	= ar
ARCHFLAGS    	= cr
RANLIB       	= ranlib
CC           	= mpicc
CFLAGS          = -pipe -O3
NOOPTS		= 
FORTRAN         = mpif90
F90FLAGS	= 
LOADER	        = mpicc
LOADOPTS	= 
CDEFS        = -DAdd__ 
EOF
}

pbuild::compile() {
	cd "${SRC_DIR}"
	mkdir -p "${PREFIX}/lib"
	make
}

pbuild::install() {
	make install
	mkdir -p "${PREFIX}/include"
	install -m 0444 "${SRC_DIR}"/SRC/*.h "${PREFIX}/include"
}


pbuild::add_to_group 'MPI'
pbuild::set_runtime_dependencies "${COMPILER}" "${MPI} 'OpenBLAS' 'parmetis'"
pbuild::set_build_dependencies "${COMPILER}" "${MPI}" 'OpenBLAS' 'parmetis'
pbuild::install_docfiles 'README'
pbuild::make_all
pbuild::cleanup_src
