# -*- 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                ortep3
version             1.0.3
revision            2
categories          science chemistry
license             public-domain
maintainers         {@kamischi web.de:karl-michael.schindler} openmaintainer
description         Thermal ellipsoid plot program
long_description    ortep3 is a thermal ellipsoid plot program for crystal \
                    structure illustrations
homepage            https://ornl-ndav.github.io/ortep/ortep.html

set ccp14mirror     http://ccp14.cryst.bbk.ac.uk/ccp/ccp14/ftp-mirror/ornl-ortep/pub/ortep
master_sites        https://github.com/ornl-ndav/ortep/raw/master:source \
                    ${ccp14mirror}/man:instructions \
                    ${ccp14mirror}/man/pdf:manual

set source          ortep.f
checksums           ${source} \
                    rmd160  edcac4b789916910f7cf08925413ace321863417 \
                    sha256  9935184a66d2b3bdadf20b4eba5c2e42e5dfb39ddd268956e417afb27d1a4c54 \
                    size    177233

set manual          manual.pdf
checksums-append    ${manual} \
                    rmd160  5cf60f83b5c28e0cfdba8f38eb62581e0e9bc526 \
                    sha256  9648c4260d3cdf59eec0e3a60d8bc0136ffdd6d4efa4c51c7c855d1f9292971f \
                    size    2320766

set instructions    instrsum.pdf
checksums-append    ${instructions} \
                    rmd160  58dc34e5dd1524dc1e082a5d6deba05a99c10ea5 \
                    sha256  e2dd60a5bfd7ca452c17d63014e58b41f511602a63e0954680f87a602d35376f \
                    size    65818

distfiles           ${source}:source ${manual}:manual ${instructions}:instructions

depends_lib         port:aquaterm \
                    port:libpng \
                    port:pgplot \
                    port:xorg-libX11

compilers.choose    fc f77 f90
compilers.setup     require_fortran
use_configure       no

extract.suffix
extract.mkdir       yes
extract.cmd         cp
extract.pre_args
extract.post_args   ${worksrcpath}/

post-patch {
    # Extract the license from the source code file
    system -W ${worksrcpath} "head -n 20 ortep.f > LICENSE"
}

use_parallel_build  no

# Note: Not setting -O0 leads to errorneous lines in the graphics
build {
    system -W ${worksrcpath} "${configure.f90} \
        -fdiagnostics-color=auto -std=legacy  \
        -O0 \
        -F${frameworks_dir} -framework AquaTerm \
        -L${prefix}/lib \
        -lpng -lpgplot -lX11 \
        -o ortep3 ortep.f"
}

destroot {
    xinstall -m 0755 -W ${worksrcpath} ortep3 \
        ${destroot}${prefix}/bin
    xinstall -d ${destroot}${prefix}/share/doc/ortep3
    xinstall -m 0444 -W ${worksrcpath} LICENSE \
        ${destroot}${prefix}/share/doc/ortep3
    xinstall -m 0444 -W ${worksrcpath} manual.pdf \
        ${destroot}${prefix}/share/doc/ortep3
    xinstall -m 0444 -W ${worksrcpath} instrsum.pdf \
        ${destroot}${prefix}/share/doc/ortep3
}

livecheck.type  regex
livecheck.url   ${homepage}
livecheck.regex "VERSION (\\d+(?:\\.\\d+)*) \\(JAN. 31, 2000\\)"
