#!/usr/bin/env modbuild

SOURCE_URL="http://crd-legacy.lbl.gov/~xiaoye/SuperLU/superlu_$V.tar.gz"

if (( V_MAJOR < 5 )); then
pbuild::configure() {
	cat <<EOF > "${MODULE_SRCDIR}/make.inc"
PLAT		= 
SuperLUroot 	= \${PREFIX}
SUPERLULIB   	= \$(SuperLUroot)/lib/libsuperlu.a
BLASDEF	     	= -DUSE_VENDOR_BLAS
BLASLIB      	= \${OPENBLAS_PREFIX}/lib/libopenblas.a
TMGLIB          = libtmglib.a
METISLIB	=
PARMETISLIB	=
FLIBS	 	= 
LIBS            = \$(DSUPERLULIB) \$(BLASLIB) \$(PARMETISLIB) \$(METISLIB)
ARCH         	= ar
ARCHFLAGS    	= cr
RANLIB       	= ranlib
CC           	= ${CC}
CFLAGS          = -pipe -O3
NOOPTS		= 
FORTRAN         = ${FC}
F90FLAGS	= 
LOADER	        = ${FC}
LOADOPTS	= -fopenmp 
CDEFS        = -DAdd_ 
EOF
}
else
pbuild::configure() {
	cmake "${MODULE_SRCDIR}" \
		-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
		|| exit 1 

}
fi

pbuild::build() {
	if (( V_MAJOR < 5 )); then
		cd "${MODULE_SRCDIR}"
		mkdir -p "${PREFIX}/lib"
	fi
	make
}

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

pbuild::add_to_group 'Compiler'
pbuild::compile_in_sourcetree
pbuild::set_docfiles 'README'
pbuild::make_all
pbuild::cleanup_src
