# $Id: Portfile 64916 2010-03-17 18:20:13Z pguyot@kallisys.net $

PortSystem 1.0
name            erlang
version         R13B04
categories      lang erlang
maintainers     bfulgham
platforms       darwin
description     The Erlang Programming Language
long_description                                                        \
                Erlang is a programming language designed at the        \
                Ericsson Computer Science Laboratory. Open-source       \
                Erlang is being released to help encourage the spread   \
                of Erlang outside Ericsson.                             \
                                                                        \
                We are releasing free of charge:                        \
                    The entire source code of the current Erlang        \
                    system.                                             \
                    Extensive libraries of code for building robust     \
                    fault-tolerant distributed applications.            \
                    All with documentation.                             \
                                                                        \
                All the above software has been battle tested in a      \
                number of Ericsson products, for example the new        \
                Ericsson ATM switch.

homepage        http://www.erlang.org/
master_sites    http://www.erlang.org/download/ \
                http://www.erlang.org/download/patches/:patches

# Parallel build doesn't work as per R13B01
use_parallel_build  no

distfiles       otp_src_${version}${extract.suffix}                    \
                otp_doc_man_${version}${extract.suffix}                \
                otp_doc_html_${version}${extract.suffix}

checksums       otp_src_${version}.tar.gz \
                md5     ca6da4921e438891967900aa6a084341 \
                sha1    fe785833a8029cbb3aee188bdb417f4da33fbd06 \
                rmd160  5546431e710814da2089d70d5d02c658a1a2f79b \
                otp_doc_man_${version}.tar.gz \
                md5     681aaef70affc64743f4e8c0675034af \
                sha1    660e52302d270138f8e9f2f2b6a562026998012c \
                rmd160  3046e54a71bf6e114c9208f263caef831782d090 \
                otp_doc_html_${version}.tar.gz \
                md5     d69ce51bfabbdd0808461d86dfc95689 \
                sha1    dc0e68cb1dd6f45cbd5ea792260b16f91eaa0e2f \
                rmd160  7257fad19ecfeee69b1c7021692374d1e29aba79

pre-patch       { file rename ${workpath}/otp_src_${version} ${workpath}/${name}-${version} }

# http://www.erlang.org/pipermail/erlang-bugs/2009-January/001171.html
patchfiles	patch-toolbar.erl \
                patch-erts_emulator_Makefile.in \
                patch-erts_emulator_hipe_hipe_amd64_asm.m4.diff \
                patch-erts_emulator_hipe_hipe_amd64.c.diff \
                patch-erts_emulator_sys_unix_sys_float.c.diff \
                patch-erts_configure.diff \
		        patch-lib_ssl_c_src_esock_openssl.c \
                patch-lib_wx_configure.in \
                patch-lib_wx_configure

configure.args  --prefix=${prefix}	            \
                --enable-kernel-poll            \
                --enable-threads                \
                --enable-dynamic-ssl-lib        \
                --enable-smp-support            \
                --enable-hipe                   \
                --disable-ssl

depends_build   port:gawk

post-destroot	{
	system "tar -C ${destroot}${prefix}/lib/erlang -zxvf ${distpath}/otp_doc_html_${version}${extract.suffix}"
	system "tar -C ${destroot}${prefix}/lib/erlang -zxvf ${distpath}/otp_doc_man_${version}${extract.suffix}"
 
        set erts_dir   erts-5.7.5

        reinplace s|${destroot}|| ${destroot}${prefix}/lib/erlang/bin/erl
        reinplace s|${destroot}|| ${destroot}${prefix}/lib/erlang/bin/start
        reinplace s|${destroot}|| ${destroot}${prefix}/lib/erlang/${erts_dir}/bin/erl
        reinplace s|${destroot}|| ${destroot}${prefix}/lib/erlang/${erts_dir}/bin/start

	foreach x {dialyzer ear ecc elink epmd erl erlc escript run_erl start to_erl typer} { file delete -force ${destroot}${prefix}/bin/${x} }
	foreach x {dialyzer erl erlc escript run_erl start to_erl typer} { system "ln -s ../lib/erlang/bin/${x} ${destroot}${prefix}/bin/${x}" }

	file delete -force ${destroot}${prefix}/lib/erlang/bin/epmd
	system "ln -s ../${erts_dir}/bin/epmd ${destroot}${prefix}/lib/erlang/bin/epmd"
}

platform darwin 10 {
    # 10.6 comes with wxWidgets and since it requires libsdl, which
    # current doesn't compile (bug #20235), we can avoid it here.
    depends_build-delete    port:wxWidgets

    patchfiles-delete	patch-lib_ssl_c_src_esock_openssl.c
    
    # 10.6 (and 10.6.1) has a bad bug related to using dlopen in a thread.
    # rdar://7209349 - http://www.openradar.appspot.com/7209349
    # This is a workaround.
    patchfiles-append   patch-erts_emulator_sys_unix_ddll.c.diff
    configure.ldflags-append -framework CoreFoundation
}

variant wxwidgets description {Build wxWidgets support}	{
	depends_build-append     port:wxWidgets
	depends_run-append       port:tk
}

variant ssl description {Build SSL support}	{
        configure.args-delete    --disable-ssl
	configure.args-append    --with-ssl=${prefix}
	configure.ldflags-append -lz
	depends_build-append     port:openssl
	depends_run-append       port:openssl
}

variant nohipe description {Disable HiPE (native-code bytecode compiler)}   {
	configure.args-delete   --enable-hipe
}

# Livecheck 
livecheck.type     regex
livecheck.version  ${version}
livecheck.url      ${homepage}download/
livecheck.regex    "otp_src_(R\[0-9\]+\[AB\]\[0-9\]*(-\[0-9\])?)\\.tar\\.gz"
