# -*- 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 115019 2013-12-22 09:29:46Z ryandesign@macports.org $

PortSystem          1.0
PortGroup           python27 1.0

name                pymol-devel
conflicts           pymol
svn.revision        4007
version             1.5.0.3.r${svn.revision}
# license is equivalent to the 3-clause BSD (https://svn.code.sf.net/p/pymol/code/trunk/pymol/LICENSE)
license             BSD
revision            2
categories          science chemistry
maintainers         nomaintainer
description         Molecular graphics system
long_description    PyMOL is a molecular graphics system with an embedded Python interpreter \
                    designed for real-time visualization and rapid generation of high-quality \
                    molecular graphics images and animations.

platforms           darwin

homepage            http://www.pymol.org/

master_sites        sourceforge
fetch.type          svn
svn.url             https://svn.code.sf.net/p/pymol/code/trunk/pymol/
worksrcdir          pymol

depends_lib         port:freetype port:libpng port:python27 port:py27-pmw port:py27-numpy port:py27-scipy port:mesa port:glew port:py27-tkinter port:freeglut
depends_run         port:xdpyinfo

pre-fetch {
    set i [lindex [registry_active "tcl"] 0]
    set regref [registry_open [lindex $i 0] [lindex $i 1] [lindex $i 2] [lindex $i 3] [lindex $i 5]]
    set variants [registry_prop_retr $regref variants]
    if {[regexp "\\+corefoundation(\\+|-|$)" ${variants}]} {
        ui_debug "Port '${name}' is incompatible with the 'corefoundation' variant of the 'tcl' port."
        return -code error "incompatible variant in dependent port"
    }
}

# py27-scipy is not universal
universal_variant   no

patchfiles          pymol_shell.diff pmg_tk_platform.patch apbs-psize.patch

post-patch {
    reinplace  "s|@PREFIX@|${prefix}|g" ${worksrcpath}/setup.py
    reinplace  "s|@@PYTHON_PKGDIR@@|${python.pkgd}|g" ${worksrcpath}/setup/pymol_macports
    reinplace  "s|@@PYTHON_BINARY@@|${python.bin}|g" ${worksrcpath}/setup/pymol_macports
}

use_parallel_build yes

variant gcc43 description conflicts gcc44 gcc45 gcc46 gcc47 description {build using macports-gcc-4.3} {
    python.add_archflags   no
    configure.compiler  macports-gcc-4.3
}

variant gcc44 description conflicts gcc43 gcc45 gcc46 gcc47 description {build using macports-gcc-4.4} {
    python.add_archflags   no
    configure.compiler  macports-gcc-4.4
}

variant gcc45 description conflicts gcc43 gcc44 gcc46 gcc47 description {build using macports-gcc-4.5} {
    python.add_archflags   no
    configure.compiler  macports-gcc-4.5
}

variant gcc46 description conflicts gcc43 gcc44 gcc45 gcc47 description {build using macports-gcc-4.6} {
    python.add_archflags   no
    configure.compiler  macports-gcc-4.6
}

variant gcc47 description conflicts gcc43 gcc44 gcc45 gcc46 description {build using macports-gcc-4.7} {
    python.add_archflags   no
    configure.compiler  macports-gcc-4.7
}

build {
}

pre-destroot {
    destroot.env CC="${configure.cc}" CXX="${configure.cxx}"
}

post-destroot {
     file copy ${worksrcpath}/setup/pymol_macports ${destroot}${prefix}/bin/pymol
     file attributes ${destroot}${prefix}/bin/pymol -permissions a+x
     ln -s ${python.pkgd}/pymol ${destroot}${python.pkgd}/pymol/pymol_path
     foreach d {data modules examples test scripts} {
        copy ${worksrcpath}/${d} ${destroot}${python.pkgd}/pymol
    }
}
