# -*- 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 111069 2013-09-14 06:54:24Z ryandesign@macports.org $

PortSystem          1.0

name                ccpnmr
version             2.3.1r2
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://www2.ccpn.ac.uk/download/ccpnmr/
distname            analysis${version}
checksums           rmd160  f695780f5bce5f0c1e84080b8364b5bfaba2a0e9 \
                    sha256  a9e47a24d84f7b8261c6c23a8607af5a6ba2f2db9e161a7f873794c1ba8663ef
worksrcdir          ${name}
depends_lib         port:py27-scipy port:mesa port:freeglut port:tk port:py27-tkinter
patchfiles          ccpnmr.patch
use_configure       no

set python.branch	2.7
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}

set lib ""

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
    reinplace  "s|@CC@|${configure.cc}|g" ${worksrcpath}/ccpnmr${branch}/c/environment-opengl.txt
    reinplace  "s|@GCCLIB@|${lib}|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}"
}

variant gcc45 conflicts gcc46 gcc47 gcc48 gcc49  description {Build with GCC 4.5} {
    configure.compiler  macports-gcc-4.5
    set lib ${prefix}/lib/gcc45
}
variant gcc46 conflicts gcc45 gcc47 gcc48 gcc49 description {Build with GCC 4.6} {
    configure.compiler  macports-gcc-4.6
    set lib ${prefix}/lib/gcc46
}
variant gcc47 conflicts gcc45 gcc46 gcc48 gcc49 description {Build with GCC 4.7} {
    configure.compiler  macports-gcc-4.7
    set lib ${prefix}/lib/gcc47
}
variant gcc48 conflicts gcc45 gcc46 gcc47 gcc49 description {Build with GCC 4.8} {
    configure.compiler  macports-gcc-4.8
    set lib ${prefix}/lib/gcc48
}
variant gcc49 conflicts gcc45 gcc46 gcc47 gcc48 description {Build with GCC 4.9} {
    configure.compiler  macports-gcc-4.9
    set lib ${prefix}/lib/gcc49
}

if {![variant_isset gcc45] && ![variant_isset gcc46] && ![variant_isset gcc47] && ![variant_isset gcc48] && ![variant_isset gcc49]} {
    default_variants    +gcc48
}
