# -*- 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
# $Id: Portfile 108382 2013-07-22 04:10:31Z larryv@macports.org $

PortSystem          1.0

name                raxml
version             7.2.9
description         Estimation of phylogenetic trees
long_description    RAxML is a program for sequential and parallel \
                    estimation of phylogenetic trees written by \
                    Alexandros Stamatakis.
license             GPL-2+
maintainers         gmail.com:mattoates
categories          science biology
homepage            http://www.exelixis-lab.org/
platforms           darwin
master_sites        http://sco.h-its.org/exelixis/software/
distname            RAxML-${version}
checksums           md5     028b70c7c96900e1f70cdc2c2acab449 \
                    sha1    a038b72e197434d7fa8a7c35687b70adb4b0750b
use_bzip2           yes

patchfiles          Makefiles.patch

use_configure       no

#Strings used by the variant options
set HPCm ""
set HPCb ""
set SSEm ""
set SSEb ""

#Use the MPI implementation
variant mpi conflicts pthreads description {MPI implementation} {
    depends_lib-append  port:openmpi
    set HPCm ".MPI"
    set HPCb "-MPI"
    configure.cc        ${prefix}/bin/openmpicc
}

#Use the pthreads implementation (default)
variant pthreads conflicts mpi description {Pthreads implementation} {
    set HPCm ".PTHREADS"
    set HPCb "-PTHREADS"
}

if {![variant_isset mpi]} {
    default_variants    +pthreads
}

#For Intel machines add SSE as a variant and use it by default with pthreads
if {${build_arch} == "i386" || ${build_arch} == "x86_64"} {
    variant sse3 description {Use the SSE3 extended instruction set from Intel since 2004} {
        set SSEm ".SSE3"
        set SSEb "-SSE3"
    }

    if {![catch {sysctl hw.optional.sse3} result] && ${result} == 1} {
        default_variants-append  +sse3
    }
} else {
    post-patch {
        reinplace "s/-msse//" ${worksrcpath}/Makefile.gcc \
                              ${worksrcpath}/Makefile.PTHREADS.gcc \
                              ${worksrcpath}/Makefile.MPI.gcc
    }
}

#Pass in architecture information
build.args              EXTRA_CFLAGS="${configure.cc_archflags}" \
                        LDFLAGS="${configure.ld_archflags}"

#Make sure we are using the correct Makefile for this variant combo
pre-build {
    build.pre_args      -f Makefile${SSEm}${HPCm}.gcc
    build.args-append   CC="${configure.cc}"
}

#We only need the single raxml binary
destroot {
    copy ${worksrcpath}/raxmlHPC${HPCb}${SSEb} ${destroot}${prefix}/bin/raxml
}
