# -*- 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: Portfile 91698 2012-04-08 10:53:03Z ryandesign@macports.org $

PortSystem       1.0
PortGroup        xcodeversion 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.2.3
set tardate      20120407
version          ${relver}.${tardate}
platforms        darwin
categories       science
maintainers      newton.cx:peter
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         http://astro.berkeley.edu/~pkwill/miriad-macport/

# The license to MIRIAD is somewhat indeterminate, since it has had
# many contributors working at many academic institutions with various
# copyright assignment and licensing policies. It's pretty important
# to straighten this out at some point.

license          unknown

# Files

master_sites http://astro.berkeley.edu/~pkwill/miriad-macport/
checksums    rmd160  aaa0e49f24050a1c00451d544d4172dada9a1574 \
             sha256  9b7c71017e6f0f7d2b4e755ff35da3e2909ad8f2ff4156ca6931e4db36e0f6ff

# Telescope/buffer size selection.

variant ata conflicts carma sma wsrt description {use buffer sizes appropriate to ATA data} {}
variant carma conflicts ata sma wsrt description {use buffer sizes appropriate to CARMA data} {}
variant sma conflicts ata carma wsrt description {use buffer sizes appropriate to SMA data} {}
variant wsrt conflicts ata carma sma description {use buffer sizes appropriate to WSRT data} {}

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

# 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.

variant gcc44 conflicts gcc45 gcc46 gcc_select description {Build with gcc/gfortran 4.4} {
    configure.compiler  macports-gcc-4.4
    depends_lib-append  port:gcc44
}

variant gcc45 conflicts gcc44 gcc46 gcc_select description {Build with gcc/gfortran 4.5} {
    configure.compiler  macports-gcc-4.5
    depends_lib-append  port:gcc45
}

variant gcc46 conflicts gcc44 gcc45 gcc_select description {Build with gcc/gfortran 4.6} {
    configure.compiler  macports-gcc-4.6
    depends_lib-append  port:gcc46
}

variant gcc_select conflicts gcc44 gcc45 gcc46 description {Build with compilers chosen via gcc_select -- experts only} {
    # Setting the compiler to vanilla "gcc" prevents MacPorts from
    # trying to get fancy with the flags, which probably won't work
    # with the user's special compiler.
    configure.compiler  gcc
    configure.cc        ${prefix}/bin/gcc
    configure.cpp       ${prefix}/bin/cpp
    configure.cxx       ${prefix}/bin/g++
    configure.f77       ${prefix}/bin/gfortran
    configure.f90       ${prefix}/bin/gfortran
    configure.fc        ${prefix}/bin/gfortran
    depends_lib-append  port:gcc_select
}

if {![variant_isset gcc44] && ![variant_isset gcc45] && ![variant_isset gcc46] && ![variant_isset gcc_select]} {
    default_variants +gcc45
}

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}

# 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." \
      "You need to run 'source ${prefix}/lib/miriad/automiriad.sh' to set up" \
      "your shell environment to use MIRIAD. (Source ${prefix}/lib/miriad/automiriad.csh" \
      "if you use csh or tcsh.) *** The 'source' keyword is important here! ***" \
      "You can put this command in your .profile or other shell initialization " \
      "files to have your shells automatically set up to use MIRIAD."

# Miscellaneous variants.

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