# -*- 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 90833 2012-03-15 06:28:14Z jmr@macports.org $

PortSystem          1.0

name                whatcheck
version             8.1
categories          science
maintainers         bromo.med.uc.edu:howarth

description         Protein verification tools from WhatIf
long_description    ${description}

homepage            http://swift.cmbi.ru.nl/gv/whatcheck/
platforms           darwin
master_sites        ${homepage}:whatcheck \
                    ftp://ftp.cmbi.ru.nl/pub/molbio/software/old-dssp/:dsspcmbi
distfiles           whatcheck.tar.bz2:whatcheck \
                    dsspcmbi.zip:dsspcmbi

checksums           whatcheck.tar.bz2 \
                    sha1    1ea39eb695218643f26e80315a8d560f57b91de5 \
                    rmd160  a6d6a0abe2fc378ae795675719f36a7f4d79817e \
                    dsspcmbi.zip \
                    sha1    880538dd36cc29918584f92dbc4e094c76ca3959 \
                    rmd160  e18d010308ae2252135c72988247518cf44a8841

dist_subdir         ${name}/${version}
worksrcdir          ${name}
depends_lib         port:xfig
patchfiles          whatcheck.patch
use_configure       no
use_bzip2           yes
extract.only        whatcheck.tar.bz2

variant gcc44 conflicts gcc45 description {Build with GCC 4.4} {}
variant gcc45 conflicts gcc44 description {Build with GCC 4.5} {}

if {[variant_isset gcc44]} {
    configure.compiler  macports-gcc-4.4
    depends_lib-append  port:gcc44
} else {
    default_variants    +gcc45
    configure.compiler  macports-gcc-4.5
    depends_lib-append  port:gcc45
}

post-extract {
    system "cd ${worksrcpath} && rm -fr *.o dbdata/fonts/.svn"
    system "cd ${worksrcpath} && rm -fr dssp && unzip ${distpath}/dsspcmbi.zip"
}

post-patch {
    reinplace  "s|@PREFIX@|${prefix}|g"     ${worksrcpath}/Makefile_whatcheck \
                                            ${worksrcpath}/WHATIF.FIG \
                                            ${worksrcpath}/DO_WHATCHECK.COM
    if {"little" != ${os.endian}} {
        configure.f77-append -fconvert=little-endian
    }
    reinplace "s|@F77@|${configure.f77}|g"  ${worksrcpath}/Makefile_whatcheck \
                                            ${worksrcpath}/scatter/Makefile
}

build {
    system "cd ${worksrcpath}/scatter && make clean"
    system "cd ${worksrcpath} && touch * && make -f Makefile_whatcheck CC=${configure.cc}"
    system "cd ${worksrcpath}/dssp && CC=${configure.cc} ./DsspCompileGCC"
}

destroot {
    file mkdir ${destroot}${prefix}/share/whatcheck/dssp
    copy ${worksrcpath}/dssp/dsspcmbi ${destroot}${prefix}/share/whatcheck/dssp/DSSP.EXE

    foreach d {whatcheck WHATIF.FIG supertab.sty DO_WHATCHECK.COM ascdata bindata dbdata nqual qualty} {
        copy ${worksrcpath}/${d} ${destroot}${prefix}/share/whatcheck
    }

    file mkdir ${destroot}${prefix}/share/whatcheck/scatter
    foreach d {scatter SCATTER.fig scatter.html} {
        copy ${worksrcpath}/scatter/${d} ${destroot}${prefix}/share/whatcheck/scatter
    }

    ln -s ${prefix}/bin/fig2dev ${destroot}${prefix}/share/whatcheck/scatter/fig2dev
    ln -s ${prefix}/share/whatcheck/DO_WHATCHECK.COM  ${destroot}${prefix}/bin/whatcheck
    ln -s ${prefix}/share/whatcheck/dssp/DSSP.EXE ${destroot}${prefix}/bin/dssp
}

livecheck.type      regex
livecheck.url       ${homepage}WCHECK_misc.html
livecheck.regex     {Version ([0-9.]+) \(stable\)}
