# -*- 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        xcodeversion 1.0
PortGroup        compilers 1.0

# Miriad releases are very infrequent, so our ports will be based on
# distributions made from CVS snapshots.  We add a sub-version number
# based on the snapshot date to distinguish things.

name             miriad
conflicts        pgplot
set relver       4.3.8
set tardate      20160322
version          ${relver}.${tardate}
revision         3
platforms        darwin
categories       science
maintainers      {newton.cx:peter @pkgw} openmaintainer
description      MIRIAD, an analysis package for radio astronomical data
long_description MIRIAD, the Multichannel Imaging, Reconstruction, Analysis, \
                 and Display package, is a suite of tools for analyzing radio \
                 astronomical observations, from raw data to imaging.
homepage         https://www.cfa.harvard.edu/~pwilliam/miriad-macport/

# Based on the DISCLAIMER shipped with ATNF miriad:
license          GPL-2+

# Files

master_sites     ${homepage}
checksums        rmd160  f715f3b7afae75c8707733c23d023ce0566a51de \
                 sha256  dadb1df981a4d636e82cdda3bb5bfe1caa7c733e7f997ea0fd5e769b93a10eb9

# Telescope/buffer size selection.

variant ant256 conflicts ata carma sma wsrt description {use buffer sizes appropriate for a 256-antenna array} {}
variant ata conflicts ant256 carma sma wsrt description {use buffer sizes appropriate to ATA data} {}
variant carma conflicts ant256 ata sma wsrt description {use buffer sizes appropriate to CARMA data} {}
variant sma conflicts ant256 ata carma wsrt description {use buffer sizes appropriate to SMA data} {}
variant wsrt conflicts ant256 ata carma sma description {use buffer sizes appropriate to WSRT data} {}

if {[variant_isset ant256]} {
    set thescope big1
} elseif {[variant_isset ata]} {
    set thescope ata
} elseif {[variant_isset wsrt]} {
    set thescope wsrt
} elseif {[variant_isset sma]} {
    set thescope sma
} else {
    set thescope carma
    default_variants +carma
}

# We need Fortran support, which the Apple version of GCC doesn't offer.
# So we force the use of a specified MacPorts-built GCC. Some users want
# to build with better-optimizing proprietary compilers, which we allow
# via the gcc_select mechanism.

compilers.choose     fc f77
compilers.set_variants_conflict   gcc_select
compilers.setup

variant gcc_select conflicts ${compilers.variants} description {Build with compilers chosen via gcc_select -- experts only} {
    configure.compiler  macports-gcc
}

if {![fortran_variant_isset] && ![variant_isset gcc_select]} {
    default_variants-append  +${compilers.gcc_default}
}

universal_variant    no

depends_lib-append   port:libpng \
                     port:readline \
                     port:xorg-libice \
                     port:xorg-libsm \
                     port:xorg-libX11 \
                     port:xorg-libXau \
                     port:xorg-libXaw \
                     port:xorg-libXdmcp \
                     port:zlib

# The Xcode 3.0 linker has a bug that prevents successful execution of
# Miriad tasks.

minimum_xcodeversions {9 3.1}

# We've hacked in the tarball date into the version number, so
# we tell the build system what directory the files in the
# tarball actually live in.

worksrcdir      ${name}-${relver}

patch.pre_args-replace  -p0 -p1
patchfiles      gcc-8-fixes.patch

# Configure settings. Keep the binaries out of ${prefix}/bin to avoid
# possible conflicts. The automiriad scripts will deal with this correctly.

configure.args  --bindir=${prefix}/libexec/miriad \
                --with-telescope=${thescope} \
                --disable-docs

# The telescope configuration is important, so make sure the user is
# told which setup is being used.

pre-configure {
    ui_msg "Configuring MIRIAD with telescope parameter of \"${thescope}\"."
    ui_msg "Consult the port variants to use a different setting. If there's"
    ui_msg "no variant for your desired telescope, contact the port maintainer"
    ui_msg "and one will be quickly added."
}

# Little helpful message. We could consider adding a patch to install
# a little program named "use_miriad" or something that would do the
# .profile munging automatically, but I don't want to worry about having
# to get that right.

notes "
MIRIAD programs are not in your \$PATH by default. Type 'source\
${prefix}/lib/miriad/automiriad.sh' in your shell to set it up to use\
MIRIAD. If you use csh or tcsh, 'source ${prefix}/lib/miriad/automiriad.csh'\
instead. The 'source' keyword is important! You can put this command in\
your .profile or other shell initialization files to make this setup automatic.
"

# Miscellaneous variants.

variant debug description {Build with debugging support -- tasks will be very slow} {
    configure.optflags -g -O0
    configure.args-append --enable-warnings
}
