# -*- 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 61626 2009-12-17 03:45:52Z macsforever2000@macports.org $

PortSystem          1.0
PortGroup           python26 1.0

name                apbs
version             1.2.0
revision            1
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          science
maintainers         bromo.med.uc.edu:howarth

description         APBS
long_description    APBS is a software package for the numerical solution \
                    of the Poisson-Boltzmann equation, a popular continuum \
                    model for describing electrostatic interactions between \
                    molecular solutes over a wide range of length scales.

homepage            http://apbs.sourceforge.net
platforms           darwin
master_sites        sourceforge
distname            apbs-${branch}-source

checksums           md5     ba32bb323b25307204436eaac1ff877b \
                    sha1    43e766a8c6166288c25229e0615a72dca5e8a3b5 \
                    rmd160  62cb82da9ca5276c3d7127a4d1f9737747dac315

depends_lib         port:gcc44 \
                    port:readline \
                    port:py26-zsi
patchfiles          apbs.diff

use_parallel_build  no

use_configure       yes

build.cmd           make
build.target        all
configure.env       py_path=${python.bin} F77=gfortran-mp-4.4
configure.args      --enable-python --with-python=${python.bin} --with-blas="-L/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A -lblas -Wl,-framework -Wl,vecLib -Wl,-undefined -Wl,dynamic_lookup" FFLAGS="-O3"

post-patch {
    reinplace  "s|@PYTHON_PKGD@|${python.pkgd}|g" ${worksrcpath}/configure
    reinplace  "s|/usr/bin/python|${python.bin}|g" ${worksrcpath}/bin/ApbsClient.py.in
    reinplace  "s|/usr/local/apbs-1.1.0|${prefix}|g" ${worksrcpath}/bin/ApbsClient.py.in
    reinplace  "s|python2.5|python2.6|g" ${worksrcpath}/bin/ApbsClient.py.in
}

destroot {
      reinplace "s|always_built_SUBDIRS =  maloc |always_built_SUBDIRS =  |g" ${worksrcpath}/contrib/Makefile
      reinplace "s|pmgZ aqua opal|pmgZ aqua|g" ${worksrcpath}/contrib/Makefile
      file mkdir ${destroot}${python.pkgd}/apbs
      
      system "cd ${worksrcpath}; make install DESTDIR=${destroot} INSTALL='install -p' CPPROG='cp -p'"

      eval xinstall [glob ${worksrcpath}/contrib/opal/opal-py-1.9.3/wsdl/*.py] \
                   ${destroot}${python.pkgd}/apbs
      eval xinstall -m 644 [glob ${worksrcpath}/src/aaa_inc/apbs/*.h] ${destroot}${prefix}/include/apbs

      foreach {bin} {psize.py coulomb born} {
         xinstall -m 755 ${worksrcpath}/tools/manip/${bin} ${destroot}${prefix}/bin/apbs-${bin}
      }
      foreach {bin} {mgmesh dxmath mergedx2 mergedx value uhbd_asc2bin smooth dx2mol dx2uhbd similarity \
                      multivalue benchmark analysis} {
         xinstall -m 755 ${worksrcpath}/tools/mesh/${bin} ${destroot}${prefix}/bin/apbs-${bin}
      }

     xinstall -m 755 ${worksrcpath}/bin/ApbsClient.py ${destroot}${prefix}/bin

}

post-destroot {
    system "${python.bin} -O ${python.libdir}/compileall.py -d ${python.pkgd}/apbs ${destroot}${python.pkgd}/apbs"
}
