# -*- 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 91623 2012-04-07 01:44:49Z ryandesign@macports.org $

PortSystem    1.0

name                afni
version             2010_10_19_1028
revision            1
distname            AFNI_${version}
categories          science
maintainers         nomaintainer
description         Analysis of Functional Neuro Images
long_description    This is a port of AFNI, Advanced Functional Neuro \
                    Imaging.  AFNI is a tool for analyzing 3 dimensional \
                    images, especially functional MRI images used in \
                    brain mapping research.
homepage            http://afni.nimh.nih.gov/

platforms           darwin
depends_lib         path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:glib1 \
                    port:openmotif
depends_run         port:netpbm \
                    port:jpeg \
                    port:whirlgif \
                    port:endian

master_sites        http://afni.nimh.nih.gov/pub/dist/tgz/AFNI_ARCHIVE/
dist_subdir         ${name}/${version}_${revision}
extract.suffix      .tgz

checksums           sha1    42234a0570d62352c0ddb71b48070e9f10744846 \
                    rmd160  b39884591e88ae95d5f985b232c31f323067c8aa

pre-patch {
    # use the right makefile
    file copy ${worksrcpath}/Makefile.${combination} ${worksrcpath}/Makefile
    # replace Fink path with ours
    reinplace s|\/sw|${prefix}|g ${worksrcpath}/Makefile
    # use the right compiler
    reinplace s|cc|${configure.cc}|g ${worksrcpath}/Makefile
    # add -ljpeg to llibs
    reinplace {s|LLIBS  = |LLIBS  = -ljpeg |} ${worksrcpath}/Makefile
    # separate bin/lib/share for manual destroot
    reinplace "s|INSTALLDIR = ${combination}|INSTALLDIR = ${destroot}${prefix}/bin|" ${worksrcpath}/Makefile
    reinplace "s|LIBDIR = \$(INSTALLDIR)|LIBDIR = ${destroot}${prefix}/lib|" ${worksrcpath}/Makefile
    reinplace "s|shared_objs: \$(INSTALLDIR) libmri.so libmrix.so|shared_objs: \$(LIBDIR) libmri.so libmrix.so|" ${worksrcpath}/Makefile
    reinplace "s|MAKE = make|MAKE = make\\\nSHAREDIR = ${destroot}${prefix}/share/${name}|" ${worksrcpath}/Makefile
}
patchfiles          patch-Makefile.INCLUDE.diff

use_configure       no

if {${os.major} == 10} {
    set combination macosx_10.6_Intel_64
}

if {${os.major} == 9} {
    if {${configure.build_arch} == "x86_64"} {
        set combination macosx_10.5_Intel_64
    }
    if {${configure.build_arch} == "i386"}  {
        set combination macosx_10.5_Intel
    }
    if {${configure.build_arch} == "ppc64"} {
        set combination macosx_10.5_G5
    }
    if {${configure.build_arch} == "ppc"} {
        set combination macosx_10.5_G4
    }
}

if {${os.major} == 8} {
    if {${configure.build_arch} == "i386"}  {
        set combination macosx_10.4_Intel
    }
    if {${configure.build_arch} == "ppc64"} {
        set combination macosx_10.4_G5
    }
    if {${configure.build_arch} == "ppc"} {
        set combination macosx_10.4
    }
}

pre-build    {
        # this appears to be Tiger-only, but i'm uncertain (predates me)
        if { ! [file exists "/usr/X11R6/lib/libGLw.a"] } {
            file copy ${distpath}/libGLw.a.tiger /usr/X11R6/lib/libGLw.a
        }
        #file copy -force ${distpath}/afni.1 ${workpath}
        #reinplace "s|%%PREFIX%%|${prefix}|g" ${workpath}/afni.1
}
build.target        all plugins

destroot.target     vastness
post-destroot {
        # Deal with files that conflict with other ports
        eval file delete ${destroot}${prefix}/bin/cjpeg ${destroot}${prefix}/bin/djpeg \
            ${destroot}${prefix}/bin/whirlgif
        file rename ${destroot}${prefix}/bin/abut ${destroot}${prefix}/bin/afni_abut

#        xinstall -d -m 755 ${destroot}${prefix}/lib/${name}
#        xinstall -d -m 755 ${destroot}${prefix}/include/${name}
#        xinstall -d -m 755 ${destroot}${prefix}/share/${name}
#        xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}

#       eval file rename [glob ${destroot}${prefix}/bin/*.a] ${destroot}${prefix}/lib/${name}
#       eval file rename [glob ${destroot}${prefix}/bin/*.so] ${destroot}${prefix}/lib/${name}
#       eval file rename [glob ${destroot}${prefix}/bin/*.h] ${destroot}${prefix}/include/${name}
#       eval file rename [glob ${destroot}${prefix}/bin/*.jpg] ${destroot}${prefix}/share/${name}
#       eval file rename [glob ${destroot}${prefix}/bin/README.*] ${destroot}${prefix}/share/doc/${name}
#       eval file rename [glob ${destroot}${prefix}/bin/*.txt] ${destroot}${prefix}/share/${name}

# Install binaries and scripts
#        xinstall -d -m 755 ${destroot}${prefix}/bin
#        eval xinstall -m 755 [glob ${worksrcpath}/macosx_bin/*] ${destroot}${prefix}/bin
}

notes "
abut has been renamed to afni_abut to resolve a collision with the unixstat port.

AFNI_PLUGIN_PATH should be set to ${prefix}/lib/afni:${prefix}/share/afni.
AFNI_GLOBAL_SESSION should be set to ${prefix}/share/afni.
"

livecheck.url       ${master_sites}
livecheck.regex     (\\d+(\\_\\d+)+)
