#!/usr/bin/env modbuild

pbuild::set_download_url "http://glaros.dtc.umn.edu/gkhome/fetch/sw/$P/$P-${V_PKG}.tar.gz"

pbuild::add_to_group 'MPI'

case ${V_MAJOR} in
3 )
	pbuild::install_docfiles CHANGES INSTALL LICENSE.txt README VERSION
	;;
4 )
	pbuild::install_docfiles Changelog Install.txt LICENSE.txt
	;;
* )
	std::die 4 "Unsupported major version!"
	;;
esac

pbuild::configure() {
	CC=$MPICC
	CXX=$MPICXX
	F77=$MPIF77
	F90=$MPIF90
	FC=$MPIFC
	FORTRAN=$MPIFORTRAN
	if (( V_MAJOR == 4 )) ; then
		cmake \
			-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
			-DMETIS_PATH="${SRC_DIR}/metis" \
			-DGKLIB_PATH="${SRC_DIR}/metis/GKlib" \
			"${SRC_DIR}" \
			|| exit 1
	fi
}

pbuild::compile() {
	CC=$MPICC
	CXX=$MPICXX
	F77=$MPIF77
	F90=$MPIF90
	FC=$MPIFC
	FORTRAN=$MPIFORTRAN
	if (( V_MAJOR == 3 )) ; then
		cd "${SRC_DIR}"
		make -e -j3 || exit 1

		mkdir -p $PREFIX/include/metis
		mkdir -p $PREFIX/lib

		cp *.h $PREFIX/include
		cp METISLib/*.h $PREFIX/include/metis
		cp lib*.a $PREFIX/lib
	elif (( V_MAJOR == 4 )); then
		make -j3 || exit 1
		make install

		LIBMETIS_A=$(find . -name libmetis.a)
		METIS_H=$(find "${SRC_DIR}" -name metis.h)

		install -m 0644 $METIS_H    $PREFIX/include
		install -m 0644 $LIBMETIS_A $PREFIX/lib
	else
		std::die 42 "Unsupported version: $V"
	fi
}

pbuild::install() {
	:
}

# vim: filetype=sh
