SUMMARY="Scalable c++ machine learning library"
DESCRIPTION="mlpack is an intuitive, fast, scalable C++ machine learning \
library, meant to be a machine learning analog to LAPACK. It aims to implement \
a wide array of machine learning methods and functions as a \"swiss army \
knife\" for machine learning researchers."
HOMEPAGE="https://www.mlpack.org/"
COPYRIGHT="2011-2012 mlpack Team"
LICENSE="BSD (3-clause)"
REVISION="1"
SOURCE_URI="https://github.com/mlpack/mlpack/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="7a7ad88c4c870b19e6c3946de23a1de1b0ee2768ddb83447bd72ea90d8cae49d"
SOURCE_FILENAME="mlpack-$portVersion.tar.gz"
SOURCE_URI_2="http://www.ensmallen.org/files/ensmallen-2.14.2.tar.gz"
CHECKSUM_SHA256_2="d067ce6aec567e1f49e47c6b59600a666f74755ff46228e8855cd21cb04188cc"
SOURCE_URI_3="http://mlpack.org/files/stb-2.22/stb_image.h#noarchive"
CHECKSUM_SHA256_3="0e28238d865510073b5740ae8eba8cd8032cc5b25f94e0f7505fac8036864909"
SOURCE_URI_4="http://mlpack.org/files/stb-1.13/stb_image_write.h#noarchive"
CHECKSUM_SHA256_4="0e8b3d80bc6eb8fdb64abc4db9fec608b489bc73418eaf14beda102a0699a4c9"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="?x86"

libVersion="$portVersion"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	mlpack$secondaryArchSuffix = $portVersion
	lib:libmlpack$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libarmadillo$secondaryArchSuffix
	lib:libboost_serialization$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libboost_unit_test_framework$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	lib:libhdf5$secondaryArchSuffix
	lib:liblapack$secondaryArchSuffix
	lib:libopenblas$secondaryArchSuffix
	lib:libsuperlu$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	"

PROVIDES_cli="
	mlpack${secondaryArchSuffix}_cli = $portVersion
	cmd:mlpack_adaboost = $libVersionCompat
	cmd:mlpack_approx_kfn = $libVersionCompat
	cmd:mlpack_bayesian_linear_regression = $libVersionCompat
	cmd:mlpack_cf = $libVersionCompat
	cmd:mlpack_dbscan = $libVersionCompat
	cmd:mlpack_decision_stump = $libVersionCompat
	cmd:mlpack_decision_tree = $libVersionCompat
	cmd:mlpack_det = $libVersionCompat
	cmd:mlpack_emst = $libVersionCompat
	cmd:mlpack_fastmks = $libVersionCompat
	cmd:mlpack_gmm_generate = $libVersionCompat
	cmd:mlpack_gmm_probability = $libVersionCompat
	cmd:mlpack_gmm_train = $libVersionCompat
	cmd:mlpack_hmm_generate = $libVersionCompat
	cmd:mlpack_hmm_loglik = $libVersionCompat
	cmd:mlpack_hmm_train = $libVersionCompat
	cmd:mlpack_hmm_viterbi = $libVersionCompat
	cmd:mlpack_hoeffding_tree = $libVersionCompat
	cmd:mlpack_image_converter = $libVersionCompat
	cmd:mlpack_kde = $libVersionCompat
	cmd:mlpack_kernel_pca = $libVersionCompat
	cmd:mlpack_kfn = $libVersionCompat
	cmd:mlpack_kmeans = $libVersionCompat
	cmd:mlpack_knn = $libVersionCompat
	cmd:mlpack_krann = $libVersionCompat
	cmd:mlpack_lars = $libVersionCompat
	cmd:mlpack_linear_regression = $libVersionCompat
	cmd:mlpack_linear_svm = $libVersionCompat
	cmd:mlpack_lmnn = $libVersionCompat
	cmd:mlpack_local_coordinate_coding = $libVersionCompat
	cmd:mlpack_logistic_regression = $libVersionCompat
	cmd:mlpack_lsh = $libVersionCompat
	cmd:mlpack_mean_shift = $libVersionCompat
	cmd:mlpack_nbc = $libVersionCompat
	cmd:mlpack_nca = $libVersionCompat
	cmd:mlpack_nmf = $libVersionCompat
	cmd:mlpack_pca = $libVersionCompat
	cmd:mlpack_perceptron = $libVersionCompat
	cmd:mlpack_preprocess_binarize = $libVersionCompat
	cmd:mlpack_preprocess_describe = $libVersionCompat
	cmd:mlpack_preprocess_imputer = $libVersionCompat
	cmd:mlpack_preprocess_one_hot_encoding = $libVersionCompat
	cmd:mlpack_preprocess_scale = $libVersionCompat
	cmd:mlpack_preprocess_split = $libVersionCompat
	cmd:mlpack_radical = $libVersionCompat
	cmd:mlpack_random_forest = $libVersionCompat
	cmd:mlpack_range_search = $libVersionCompat
	cmd:mlpack_softmax_regression = $libVersionCompat
	cmd:mlpack_sparse_coding = $libVersionCompat
	"
REQUIRES_cli="
	mlpack$secondaryArchSuffix == $portVersion base
	$REQUIRES
	"

PROVIDES_devel="
	mlpack${secondaryArchSuffix}_devel = $portVersion
	devel:libmlpack$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	mlpack$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libarmadillo$secondaryArchSuffix
	devel:libboost_serialization$secondaryArchSuffix
	devel:libboost_system$secondaryArchSuffix
	devel:libboost_unit_test_framework$secondaryArchSuffix
	devel:libhdf5$secondaryArchSuffix
	devel:liblapack$secondaryArchSuffix
	devel:libopenblas$secondaryArchSuffix
	devel:libsuperlu$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:find
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage mlpack$secondaryArchSuffix \
	$libDir/libmlpack.so.${portVersion%.*}

BUILD()
{
	mkdir -p build/deps/stb
	cp "$sourceDir3"/stb_image.h "$sourceDir4"/stb_image_write.h build/deps/stb
	ln -s "$sourceDir2" build/deps/ensmallen-2.14.2 || true

	cd build

	cmake .. \
		-DCMAKE_INSTALL_PREFIX=$prefix \
		-DBUILD_TESTS=OFF \
		-DDEBUG=OFF \
		-DPROFILE=OFF

	# mlpack easily eats up all your ram, so don't do parallel jobs!
	make
}

INSTALL()
{
	cd build

	make install $jobArgs

	mkdir -p $includeDir
	mv $prefix/include/* $includeDir/
	rmdir $prefix/include

	prepareInstalledDevelLib libmlpack

	fixPkgconfig

	packageEntries cli \
		"$binDir"

	packageEntries devel \
		$developDir \
		$libDir/cmake
}

TEST()
{
	# Switch it on first in BUILD()
	# Takes way too much time to build the tests
	cd build
	make test
}
