# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                mahout
version             0.9
categories          java math
maintainers         nomaintainer

description         A scalable machine learning library that supports large data sets
long_description    Mahout is a scalable machine learning library that implements many \
                    different approaches to machine learning. \
                    The project currently contains implementations of algorithms for \
                    classification, clustering, genetic programming and collaborative \
                    filtering, all enabled to scale by leveraging the power of Hadoop's \
                    Map-Reduce (https://hadoop.apache.org) implementation.

homepage            https://mahout.apache.org/
platforms           any
license             Apache-2

master_sites        apache:${name}/${version}
checksums           rmd160  545417d7257b42500268475da9d87e28f163b29d \
                    sha256  d7a0f2c58ee464a9011b0fc189f79abd7863111ce2b3635bdadb282112cc240f

distname            ${name}-distribution-${version}

depends_lib         port:hadoop

use_configure       no
supported_archs     noarch

build {}

set mahout_home     ${prefix}/share/java/${distname}
set mahout_log_dir  ${prefix}/var/hadoop/log

destroot {
    # Copy the distribution to Mahout home directory.
    xinstall -m 755 -d  ${destroot}${prefix}/share/java
    copy ${worksrcpath} ${destroot}${prefix}/share/java/

    # Read the configuration of Hadoop from 'hadoop-bin'.
    set f [open ${prefix}/bin/hadoop-bin]
    set string [read $f]
    close $f
    regexp {JAVA_HOME=(\S+)}   $string m java_home
    regexp {HADOOP_HOME=(\S+)} $string m hadoop_home
    regexp {sudo -E -u (\S+)}  $string m hadoopuser

    # Install an extra script for this port.
    set mahout_bin ${destroot}${prefix}/bin/mahout-bin
    xinstall -m 755 ${filespath}/mahout-bin            ${mahout_bin}
    reinplace "s|@java_home@|${java_home}|g"           ${mahout_bin}
    reinplace "s|@hadoop_home@|${hadoop_home}|g"       ${mahout_bin}
    reinplace "s|@mahout_home@|${mahout_home}|g"       ${mahout_bin}
    reinplace "s|@mahout_log_dir@|${mahout_log_dir}|g" ${mahout_bin}
    reinplace "s|@hadoopuser@|${hadoopuser}|g"         ${mahout_bin}
}

livecheck.type      regex
livecheck.url       https://www.apache.org/dist/mahout/
livecheck.regex     >(\[0-9.\]+)\/<
