# $Id: Portfile 52537 2009-06-18 14:10:28Z pguyot@kallisys.net $

PortSystem 1.0
name		erlang
version		R13B01
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     b3db581de6c13e1ec93d74e54a7b4231 \
                    sha1    29d0e06dd351f31c70112454f8187e70ee75ca03 \
                    rmd160  f40ed0d6837f187f889a49c841a6615714b5ae96 \
                otp_doc_man_${version}.tar.gz \
                    md5     fa8f96159bd9a88aa2fb9e4d79d7affe \
                    sha1    528a4a95e09e0422256c1bd9a818c37a6ece0a14 \
                    rmd160  9cc398f8a648b6c0444831edd37b16ae88b18cb8 \
                otp_doc_html_${version}.tar.gz \
                    md5     42cb55bbfa5dc071fd56034615072f7a \
                    sha1    fdb2836af961745ded836f3dd465d3395c750cd5 \
                    rmd160  e0504ca360b806977d6613fab0b7bcd7512a8333

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

# http://www.erlang.org/pipermail/erlang-bugs/2008-October/001023.html
# http://www.erlang.org/pipermail/erlang-bugs/2008-October/001024.html
# http://www.erlang.org/pipermail/erlang-bugs/2009-January/001171.html
patchfiles	patch-toolbar.erl \
                patch-erts_emulator_Makefile.in \
                patch-lib_ssl_c_src_esock_openssl.c \
                patch-lib_ssl_c_src_Makefile.dist \
                patch-lib_ssl_c_src_Makefile.in \
                patch-decode_big.c.diff \
                patch-decode_fun.c.diff \
                patch-lib-erl_interface-src-connect-ei_connect.c.diff \
                patch-lib-erl_interface-include-ei.h.diff \
                patch-erts_configure.diff \
                patch-lib_wx_configure.in \
                patch-lib_wx_configure

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

variant ssl description {Build SSL support}	{
	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
}

depends_build   port:gawk \
                port:wxWidgets
depends_run     port:tk

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

        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"
}
