# $Id: Portfile 85594 2011-10-15 00:25:59Z ryandesign@macports.org $

PortSystem 1.0

name		mercury
version		11.01
categories	lang
maintainers	nomaintainer
platforms	darwin
license		GPL-2 LGPL-2

description	The Mercury Programming Language
long_description	\
		Mercury is a new logic/functional programming	\
		language, which combines the clarity and	\
		expressiveness of declarative programming with	\
		advanced static analysis and error detection	\
		features. Its highly optimized execution	\
		algorithm delivers efficiency far in excess of	\
		existing logic programming systems, and close	\
		to conventional programming systems. Mercury	\
		addresses the problems of large-scale program	\
		development, allowing modularity, separate	\
		compilation, and numerous optimization/time	\
		trade-offs.

homepage	http://www.${name}.cs.mu.oz.au/
master_sites	${homepage}download/files/

distname	${name}-compiler-${version}

checksums           md5     5d7dc00ab06f87ee5ddfb8dca088be56 \
                    sha1    508f9fbebdf061f706a44db5c77868cb4e769066 \
                    rmd160  bee82b6037fa1f14f27b43d6f7d751d232941bc7

worksrcdir	${name}-compiler-${version}

depends_lib \
    port:readline

patchfiles \
    asm.patch \
    nolibgcc.patch

post-patch {
    reinplace "s:\*gcc\*:*gcc*|*clang*:" ${worksrcpath}/scripts/ml.in ${worksrcpath}/scripts/mgnuc.in
}

# Release notes state that gcc-4.0 generates a broken mercury compiler
# llvm-gcc-4.2 fails to build
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
    }
} elseif {${configure.compiler} == "llvm-gcc-4.2"} {
    configure.compiler clang
}

# mercury doesn't honor $CFLAGS
configure.cc ${configure.cc} -std=gnu89

# mercury's bootstrapping doesn't work with DESTDIR, so do it an ugly way...
configure.pre_args-delete --prefix=${prefix}
configure.pre_args-append --prefix=${destroot}${prefix}
destroot.destdir ""

post-destroot {
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.memprof/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.prof/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.gc.trseg/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.par.gc/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.par.gc/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.par.gc/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.par.gc/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.par.gc/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.par.gc/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.par.gc/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.par.gc/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.par.gc/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.par.gc/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.par.gc/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.par.gc/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/hlc.par.gc/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/hlc.par.gc/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/libgc.dylib ${destroot}${prefix}/lib/mercury/lib/libgc.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/libgc_prof.dylib ${destroot}${prefix}/lib/mercury/lib/libgc_prof.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/libpar_gc.dylib ${destroot}${prefix}/lib/mercury/lib/libpar_gc.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.debug/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.debug/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.debug/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.debug/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.debug/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.debug/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.debug/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.debug/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.debug/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.debug/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.debug/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.debug/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.debug/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.debug/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.decldebug/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.prof/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.prof/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.prof/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.prof/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.prof/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.prof/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.prof/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.prof/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.prof/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.prof/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.prof/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.prof/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.prof/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.prof/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/none.gc.profdeep/libmer_trace.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.par.gc/libmer_browser.dylib ${destroot}${prefix}/lib/mercury/lib/none.par.gc/libmer_browser.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.par.gc/libmer_eventspec.dylib ${destroot}${prefix}/lib/mercury/lib/none.par.gc/libmer_eventspec.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.par.gc/libmer_mdbcomp.dylib ${destroot}${prefix}/lib/mercury/lib/none.par.gc/libmer_mdbcomp.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.par.gc/libmer_rt.dylib ${destroot}${prefix}/lib/mercury/lib/none.par.gc/libmer_rt.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.par.gc/libmer_ssdb.dylib ${destroot}${prefix}/lib/mercury/lib/none.par.gc/libmer_ssdb.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.par.gc/libmer_std.dylib ${destroot}${prefix}/lib/mercury/lib/none.par.gc/libmer_std.dylib"
    system "install_name_tool -id ${prefix}/lib/mercury/lib/none.par.gc/libmer_trace.dylib ${destroot}${prefix}/lib/mercury/lib/none.par.gc/libmer_trace.dylib"

    file delete ${destroot}${prefix}/var/macports/build
}
