# -*- 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 91373 2012-03-31 00:08:55Z ryandesign@macports.org $

PortSystem          1.0

name                healpix
version             2.20a
categories          science
maintainers         aronnax
description         Hierarchical Equal Area isoLatitude Pixelization of a sphere
long_description    Software for pixelization, hierarchical indexation, synthesis, \
                    analysis, and visualization of data on the sphere.
homepage            http://healpix.jpl.nasa.gov/
platforms           darwin
master_sites        sourceforge:project/${name}/Healpix_${version}
worksrcdir          Healpix_${version}
distname            Healpix_${version}_2011Feb09

checksums           md5     e4d534505cd91cfea60719f620584b2f \
                    sha1    f7a0fdab8e9fcfdf81e3e5e9a7d18912203d3803 \
                    rmd160  e15b14262591a679764665d4d1774c38786a7a00

universal_variant   yes

depends_lib         port:cfitsio

patchfiles          patch-src-cxx-cxxsupport-arr.h.diff
use_configure       no

# Find a compiler that supports OpenMP.  Courtesy of Adam Mercer.
if {${configure.compiler} == "clang"} {
   configure.compiler llvm-gcc-4.2
}

if {${configure.compiler} == "gcc-4.0"} {
   configure.compiler gcc-4.2
   if {![file executable ${configure.cc}]} {
       depends_build-append port:apple-gcc42
       configure.compiler apple-gcc-4.2
   }
}

build.post_args-append \
                    HEALPIX_TARGET=osx \
                    BINDIR=${worksrcpath}/bin \
                    LIBDIR=${worksrcpath}/lib \
                    INCDIR=${worksrcpath}/include \
                    EXTERNAL_CFITSIO=yes \
                    CFITSIO_INCDIR=${prefix}/include \
                    CFITSIO_LIBDIR=${prefix}/lib \
                    CFITSIO_EXT_LIB=${prefix}/lib/libcfitsio.a \
                    CFITSIO_EXT_INC=${prefix}/include \
                    CC="${configure.cc} [get_canonical_archflags cc]" \
                    CL="${configure.cc} [get_canonical_archflags ld]" \
                    CXX="${configure.cxx} [get_canonical_archflags cxx]" \
                    CXXL="${configure.cxx} [get_canonical_archflags ld]"

build {
    system -W ${worksrcpath}/src/cxx "${build.cmd} [join ${build.post_args}]"
    system -W ${worksrcpath}/src/C/subs "${build.cmd} static install AR=\"ar -rsv\" [join ${build.post_args}]"
}

post-build {
    # This file is just a copy of ${worksrcpath}/lib/libhpxgif.a
    # and conflicts with port:giflib.
    file delete ${worksrcpath}/lib/libgif.a
}

destroot {
    eval xinstall [glob ${worksrcpath}/include/*] ${destroot}${prefix}/include
    eval xinstall [glob ${worksrcpath}/lib/*] ${destroot}${prefix}/lib
    eval xinstall [glob ${worksrcpath}/bin/*] ${destroot}${prefix}/bin
}
