# -*- 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$
PortSystem      1.0

name            cpl
conflicts       cpl-devel
version         7.3.2
revision        13
categories      science
license         GPL-2+
platforms       darwin
maintainers     eso.org:usd-help
description     ESO library for automated astronomical data-reduction tasks
long_description The Common Pipeline Library (CPL) comprises a set of ISO-C  \
                 libraries that provide a comprehensive, efficient and robust  \
                 software toolkit. It forms a basis for the creation of  \
                 automated astronomical data-reduction tasks  \
                 (known as pipelines) for ESO (European Southern Observatory) \
                 instruments. The CPL was developed to standardize the way \
                 VLT (Very Large Telescope) instrument pipelines are built, \
                 to shorten their development cycle and to ease their maintenance.
homepage        http://www.eso.org/sci/software/cpl
master_sites    https://ftp.eso.org/pub/dfs/pipelines/libraries/${name}
checksums       sha256 a50c265a8630e61606567d153d3c70025aa958a28473a2411585b96894be7720

patch {
  # Have to check if WCSLIB was built with the symbolic link for libwcs.dylib.
  # Otherwise have to identify which major version number to use for the -lwcs.N
  # linker option and update the configure script.
  if {! [file exists ${prefix}/lib/libwcs.dylib]} {
    set wcslib_major_version -1
    foreach path [glob ${prefix}/lib/libwcs*.dylib] {
      if {[regexp {libwcs\.(\d+)} [file rootname [file tail ${path}]] -> tmp_wcslib_major_version]} {
        if {${tmp_wcslib_major_version} > ${wcslib_major_version}} {
          set wcslib_major_version ${tmp_wcslib_major_version}
        }
      }
    }
    if {${wcslib_major_version} != -1} {
      system "sed -i '' -e 's/-lwcs/-lwcs.${wcslib_major_version}/' ${worksrcpath}/configure"
    }
  }
}

depends_lib     port:cext \
                port:cfitsio \
                port:fftw-3 \
                port:fftw-3-single \
                port:wcslib

configure.args  --disable-threads \
                --with-cext=${prefix} \
                --with-cfitsio=${prefix} \
                --with-fftw=${prefix} \
                --with-system-cext \
                --with-wcslib=${prefix}

use_parallel_build  no

test.run        yes
test.target     installcheck
