# -*- coding: utf-8; mode: tcl; tab-width: 2; 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

# Place holder for future Port group for ESO packages
#PortGroup           eso 1.0

set eso.prefix      ${prefix}/libexec/eso

name                eso-flames-fposs

version             115.0.3
revision            0

categories          science
license             GPL-2+
maintainers         eso.org:john.pritchard
homepage            http://www.eso.org/sci/observing/phase2/SMGuidelines/FPOSS.FLAMES.html
description         ESO FLAMES Observation Preparation software
long_description    ESO FLAMES Observation Preparation software.
                 
master_sites        https://ftp.eso.org/pub/usg/fposs/

distname            fposs-${version}

checksums           rmd160 065a65f558317661d1356bfeee579f8790c14ecb \
                    sha256 9d16463dacfaa493a2221c352b2aa323bd0edd2f86c3d1fcafe6588a11f0989b \
                    size 2319171

compilers.choose    cc cxx
compilers.setup     gcc

compiler.c_standard  2011

use_parallel_build  no

depends_run         port:tk port:tcl \
                    port:ncurses \
                    port:xorg-server

patchfiles          Makefile_Darwin.diff \
                    fposs.sh.tpl.diff \
                    pafchk.makefile.novlt.diff

configure {
  # Update the @@ESO_...@@ placeholders set in patchfiles with Portfile variables
  reinplace "s?@@ESO_CC@@?${configure.cc}?g" \
    ${worksrcpath}/fposs/src/Makefile_Darwin
  reinplace "s?@@ESO_CC@@?${configure.cc}?g" \
    ${worksrcpath}/pafchk/src/makefile.novlt
  reinplace "s?@@ESO_PREFIX@@?${eso.prefix}?g" \
    ${worksrcpath}/fposs/scripts/fposs.sh.tpl
}

build {
  # Non-standard build of pafchk...
  system -W "${worksrcpath}/pafchk/src" \
      "\
        CC=${configure.cc} CXX=${configure.cxx} \
        CFLAGS='[get_canonical_archflags cc] ${configure.cflags}' CXXFLAGS='[get_canonical_archflags cxx] ${configure.cxxflags}' \
        make -f makefile.novlt \
      "
  # Non-stadnard build of fposs...
  system -W "${worksrcpath}/fposs/src" \
      "\
        CC=${configure.cc} CXX=${configure.cxx} \
        CFLAGS='[get_canonical_archflags cc] ${configure.cflags}' CXXFLAGS='[get_canonical_archflags cxx] ${configure.cxxflags}' \
        make \
      "
}

destroot {
  system -W "${worksrcpath}/fposs/src" "make INTROOT='${destroot}${eso.prefix}' install"
  xinstall                                                      -d  ${destroot}${prefix}/bin
  xinstall                                                      -d  ${destroot}${prefix}/share
  xinstall                                                      -d  ${destroot}${eso.prefix}/bin
  xinstall ${worksrcpath}/fposs/scripts/fposs.sh.tpl                ${destroot}${eso.prefix}/bin/fposs.sh
  xinstall ${worksrcpath}/fposs/scripts/bash_library.sh             ${destroot}${eso.prefix}/bin
  xinstall ${worksrcpath}/fposs/scripts/fposs_fixINSfilename.sh     ${destroot}${eso.prefix}/bin
  ln -s ${eso.prefix}/bin/fposs.sh                                  ${destroot}${prefix}/bin
  ln -s ${eso.prefix}/share/fposs                                   ${destroot}${prefix}/share/fposs
}

livecheck.type          regex
livecheck.url           https://ftp.eso.org/pub/usg/fposs/ver_info.html
livecheck.regex         ".*https://ftp.eso.org/pub/usg/fposs/eso-fposs-\"(\\d+(?:\\.\\d+)*)\.tar.gz.*"
