# -*- 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

PortSystem          1.0
PortGroup           compilers 1.0

name                whatcheck
version             8.1
revision            2
categories          science
# license conditions: http://swift.cmbi.ru.nl/gv/whatcheck/
license             Restrictive
maintainers         {gmail.com:howarth.at.macports @jwhowarth} openmaintainer

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

compilers.choose    f77
compilers.setup     require_fortran

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&nbsp;([0-9.]+)}
