# -*- 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 75128 2011-01-16 01:30:15Z snc@macports.org $

PortSystem          1.0

name                ccpnmr
version             2.1.5
set branch          [join [lrange [split $version .] 0 1] .]
categories          science python
maintainers         bromo.med.uc.edu:howarth
description         CCPNMR
long_description    The CcpNmr software suite is a series of programs \
                    for macromolecular NMR spectroscopy integrated with \
                    the CCP data model. The CCP Data Model for macro- \
                    molecular NMR is intended to cover all data needed \
                    for macromolecular NMR spectroscopy from the initial \
                    experimental data to the final validation.
platforms           darwin
homepage            http://www.ccpn.ac.uk/ccpn/software/ccpnmr-suite
master_sites        http://www.bio.cam.ac.uk/ccpn/download/ccpnmr/
distname            analysis${version}
checksums           md5     e1e93cac7516c6f8fbe4b503a223cdd4 \
                    sha1    70dc5e6b2752d6b7d5c8673fc992ebd0a88e6ad0
worksrcdir          ${name}
depends_lib         port:py26-scipy port:mesa port:tk port:py26-tkinter
patchfiles          ccpnmr.patch
use_configure       no

set python.branch	2.6
set python.prefix	${frameworks_dir}/Python.framework/Versions/${python.branch}
set python.bin	${python.prefix}/bin/python${python.branch}
set python.pkgd	${python.prefix}/lib/python${python.branch}/site-packages
set python.libdir ${python.prefix}/lib/python${python.branch}
set python.include	${python.prefix}/include/python${python.branch}

post-patch {
    reinplace  "s|@PYTHON_BIN@|${python.bin}|g"   ${worksrcpath}/bin/analysis \
                                                  ${worksrcpath}/bin/formatConverter \
                                                  ${worksrcpath}/bin/pipe2azara \
                                                  ${worksrcpath}/ccpnmr${branch}/c/environment-opengl.txt \
                                                  ${worksrcpath}/bin/dataShifter \
                                                  ${worksrcpath}/bin/updateAll \
                                                  ${worksrcpath}/bin/updateCheck
    reinplace  "s|@PYTHON_PKGD@|${python.pkgd}|g" ${worksrcpath}/bin/analysis \
                                                  ${worksrcpath}/bin/formatConverter \
                                                  ${worksrcpath}/bin/pipe2azara \
                                                  ${worksrcpath}/bin/dataShifter \
                                                  ${worksrcpath}/bin/updateAll \
                                                  ${worksrcpath}/bin/updateCheck
    reinplace  "s|@PREFIX@|${prefix}|g" ${worksrcpath}/ccpnmr${branch}/c/environment-opengl.txt
    reinplace  "s|/usr/X11R6|${prefix}|g" ${worksrcpath}/ccpnmr${branch}/c/environment-opengl.txt
    reinplace  "s|@PYTHON_INCL@|${python.include}|g" ${worksrcpath}/ccpnmr${branch}/c/environment-opengl.txt
}
pre-build {
    copy ${worksrcpath}/ccpnmr${branch}/c/environment-opengl.txt ${worksrcpath}/ccpnmr${branch}/c/environment.txt
}
build.args      CC=${configure.cc} ARCHFLAGS="${configure.cc_archflags}"
build.dir       ${worksrcpath}/ccpnmr${branch}/c
build.target    all links
destroot {
    foreach f {analysis dataShifter formatConverter pipe2azara updateAll updateCheck} {
        xinstall -m 755 ${worksrcpath}/bin/${f} ${destroot}${prefix}/bin
    }
    file mkdir ${destroot}${python.pkgd}/${name}/${name}${branch}/
    foreach d {c python data model doc} {
        copy ${worksrcpath}/ccpnmr${branch}/${d} ${destroot}${python.pkgd}/${name}/${name}${branch}
    }
    system "echo '${name}/${name}${branch}/python' > ${destroot}${python.pkgd}/${name}.pth"
    copy ${worksrcpath}/doc ${destroot}${python.pkgd}/${name}
}
post-destroot {
    system "${python.bin} -O ${python.libdir}/compileall.py -d ${python.pkgd}/${name}/${name}${branch} ${destroot}${python.pkgd}/${name}/${name}${branch}"
}
