# -*- 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 106818 2013-06-08 23:25:32Z cal@macports.org $

PortSystem          1.0

name                ghc
set canonicalname   ghc
version             7.6.3
categories          lang haskell
maintainers         gmail.com:kitchen.andy cal openmaintainer
license             BSD
platforms           darwin

description The Glorious Glasgow Haskell Compilation System
long_description    \
        The Glasgow Haskell Compiler is a robust,       \
        fully-featured, optimising compiler and interactive \
        environment for Haskell 98, GHC compiles Haskell to \
        either native code or C.  It implements numerous    \
        experimental language extensions to Haskell 98,     \
        for example: concurrency, a foreign language interface, \
        multi-parameter type classes, scoped type variables,    \
        existential and universal quantification, unboxed   \
        types, exceptions, weak pointers, and so on.        \
        GHC comes with a generational garbage collector,    \
        and a space and time profiler.

homepage        http://haskell.org/${canonicalname}
master_sites    ${homepage}/dist/${version}/
distname        ${canonicalname}-${version}-src
worksrcdir      ${canonicalname}-${version}

use_bzip2       yes

distfiles       ${canonicalname}-${version}-src${extract.suffix} \
                ${canonicalname}-${version}-testsuite${extract.suffix}

checksums       ghc-7.6.3-src.tar.bz2 \
                rmd160  82a673ed38b7cf9a59afeb01057625fc761a822b \
                sha256  bd43823d31f6b5d0b2ca7b74151a8f98336ab0800be85f45bb591c9c26aac998 \
                ghc-7.6.3-testsuite.tar.bz2 \
                rmd160  e1d7536b1b0799a6c069eb89be41ceb56692b68d \
                sha256  870d8f50a1b569b0f93d0c7c6b80225280841988f1d779aafe847bcf02d76256

depends_build   port:ghc-bootstrap \
                port:libxslt

depends_lib     port:gmp           \
                port:ncurses       \
                port:libiconv

patchfiles      patch-configure-disable-docbook-ps-and-pdf.diff


livecheck.type  none
test.run        yes
use_parallel_build no

# -- BEGIN gcc variants

variant gcc43 conflicts gcc44 gcc45 gcc46 gcc47 description {Compile with gcc 4.3} {
    configure.compiler      macports-gcc-4.3
    depends_lib-append      port:gcc43
    configure.args-append   --with-gcc=${configure.cc}
}

variant gcc44 conflicts gcc43 gcc45 gcc46 gcc47 description {Compile with gcc 4.4} {
    configure.compiler      macports-gcc-4.4
    depends_lib-append      port:gcc44
    configure.args-append   --with-gcc=${configure.cc}
}

variant gcc45 conflicts gcc43 gcc44 gcc46 gcc47 description {Compile with gcc 4.5} {
    configure.compiler      macports-gcc-4.5
    depends_lib-append      port:gcc45
    configure.args-append   --with-gcc=${configure.cc}
}

variant gcc46 conflicts gcc43 gcc44 gcc45 gcc47 description {Compile with gcc 4.6} {
    configure.compiler      macports-gcc-4.6
    depends_lib-append      port:gcc46
    configure.args-append   --with-gcc=${configure.cc}
}

variant gcc47 conflicts gcc43 gcc44 gcc45 gcc46  description {Compile with gcc 4.7} {
    configure.compiler      macports-gcc-4.7
    depends_lib-append      port:gcc47
    configure.args-append   --with-gcc=${configure.cc}
}

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

# -- END gcc variants

set bootstraproot ${prefix}/share/ghc-bootstrap
configure.args  --with-ghc=${bootstraproot}/bin/ghc     \
                --with-iconv-includes=${prefix}/include \
                --with-iconv-libraries=${prefix}/lib    \
                --with-gmp-includes=${prefix}/include   \
                --with-gmp-libraries=${prefix}/lib

# OK so because the bootstrap binary has been prebuilt for libraries
# in /usr/lib we search these before macports stuff to prevent
# link errors, ghc _should_ actually compile itself in stage2
# using paths from the command line arguments
compiler.cpath /usr/include
compiler.library_path /usr/lib

post-destroot {
    set prefixlib ${prefix}/lib/${worksrcdir}
    set destlib   ${destroot}/${prefixlib}
    set libver    ${canonicalname}${version}

    variable libs [ list                               \
                    libHSrts-${libver}.dylib           \
                    libHSrts_debug-${libver}.dylib     \
                    libHSrts_thr-${libver}.dylib       \
                    libHSrts_thr_debug-${libver}.dylib ]

    system "install_name_tool -id ${prefixlib}/libffi.dylib ${destlib}/libffi.dylib"

    foreach lib $libs {
      regexp -line {[^[:space:]]*/libffi.*\.dylib} [exec otool -L ${destlib}/${lib}] oldlib
      system "install_name_tool -change ${oldlib} ${prefixlib}/libffi.dylib ${destlib}/$lib"
    }
}

pre-activate {
    # Legacy port deactivation hack added 2012-12-08
    if { ![catch {set platform_ghc_installed [lindex [registry_active hs-platform-ghc] 0]}] } {
        # hs-platform-ghc is installed and active
        # force deactivation
        registry_deactivate_composite hs-platform-ghc "" [list ports_nodepcheck 1]
    }
}
