# -*- 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                cfitsio
epoch               1
version             4.4.0
revision            0
categories          science
license             zlib MIT {LGPL Noncommercial}
platforms           darwin
maintainers         nomaintainer

description         C access to FITS data files with optional Fortran wrappers

long_description    CFITSIO is a library of C and Fortran subroutines for \
                    reading and writing data files in FITS (Flexible Image \
                    Transport System) data format. CFITSIO simplifies the \
                    task of writing software that deals with FITS files by \
                    providing an easy to use set of high-level routines that \
                    insulate the programmer from the internal complexities \
                    of the FITS file format. At the same time, CFITSIO \
                    provides many advanced features that have made it the \
                    most widely used FITS file programming interface in the \
                    astronomical community.

homepage            https://heasarc.gsfc.nasa.gov/fitsio/
master_sites        https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/

checksums           rmd160  2fb010be76661065f751a38b16cebfd81413d997 \
                    sha256  95900cf95ae760839e7cb9678a7b2fad0858d6ac12234f934bd1cb6bfc246ba9 \
                    size    4278372

patchfiles          patch-configure.diff \
                    patch-Makefile.in.diff

post-patch {
    reinplace "s|@@MPORTS_PREFIX@@|${prefix}|" ${worksrcpath}/configure
}

depends_lib-append  port:curl \
                    port:zlib

use_parallel_build  no

compilers.choose    fc
compilers.setup     require_fortran

# turn off FORTRAN compiler wrappers by removing FORTRAN from the path
if {![fortran_variant_isset]} {
    configure.fc none
}

# error: redefinition of typedef ‘ParseData’
compiler.c_standard  2011

configure.env-append "CURLCONFIG=${prefix}/bin/curl-config"
configure.cflags    -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
configure.universal_args-delete --disable-dependency-tracking

build.target        all shared

post-destroot {
    system "ranlib ${destroot}${prefix}/lib/libcfitsio.a"
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -m 755 -d ${docdir}
    xinstall -m 644 \
        ${worksrcpath}/README.md \
        {*}[glob ${worksrcpath}/*.txt] \
        {*}[glob ${worksrcpath}/docs/*.pdf] \
        ${docdir}
}

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     "${name}-(\\d+(?:\\.\\d+)+)"
