# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 68284 2010-05-31 01:57:44Z snc@macports.org $

PortSystem	1.0

name		        afni
version		        2009_12_31_1431
revision            1
distname	        AFNI_${version}
categories	        science
maintainers	        snc openmaintainer
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/
extract.suffix      .tgz

checksums           md5     00959234f2e512cf1b16335d3ab80f1d \
                    sha1    cfde2df4edd33ae78bcd41ae9226c44f0174c005 \
                    rmd160  fbe9f7afc5a28fe4fa3bcba1bdc87494ca47ce85

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       http://www.neuro.mcw.edu/~bacon/Ports/distfiles/AFNI/
livecheck.regex     (\\d+\\.\\d+\\.\\d+\\.\\d+)
