Erlang R13A for MacPorts

UPDATE: Just selfupdate MacPorts if it isn't showing R12B (which is now released) and update erlang instead.

UPDATE: I have rewritten this article after reading Jim's comment on how to set up a local MacPorts repository.

Since there is not yet a Portfile for Erlang R13A in MacPorts I built one myself. MacPorts makes this remarkably easy since the Portfile format is so easy to read and write.

Save the following as ~/Desktop/Portfile:

# $Id$

PortSystem 1.0
name  erlang
version  R13A
revision        1
categories lang erlang
maintainers gmail.com:alain.odea
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://www3.erlang.org/download/                        \
                http://www.csd.uu.se/ftp/mirror/erlang/download/        \
                http://www1.erlang.org/download/
                

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

checksums       otp_src_R13A.tar.gz \
                    md5     76804ff9c18710184cf0c0230a0443fc \
                    sha1    9fa0db27611559d697fe269c3fb9a405ae24d147 \
                    rmd160  42ba3c4815fa702d19281f1d42faaec72a75c703 \
                otp_doc_man_R13A.tar.gz \
                    md5     883e097796abd2cda4727fe3527dc1b6 \
                    sha1    98ce2fbc2daf7ec88ca38334412b9e85ca9cd53c \
                    rmd160  c082bda26b85cd6bd2ede8dd2c538e2ef50bbd2c \
                otp_doc_html_R13A.tar.gz \
                    md5     2bbecc1c5537e0cd1c0fc406082b6c56 \
                    sha1    fb3ed9c0d619d8bbd70af5c6b0e4e90c49771e0d \
                    rmd160  873b30cd8c5f2617c62aba0314197c54097a27cf

extract.only    otp_src_${version}${extract.suffix}

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://support.process-one.net/browse/EUNIT-13
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-eunit_xml.diff

configure.args  --prefix=${destroot}${prefix} \
                --enable-kernel-poll            \
                --disable-smp-support           \
                --enable-hipe

variant smp description {enable symmetric multiprocessing} {
 configure.args-delete --disable-smp-support
}

variant ssl description {enable SSL/TLS encryption} {
 configure.args-append    --with-ssl=${prefix}
 configure.ldflags-append -lz
 depends_build-append     port:openssl
 depends_run-append       port:openssl
}

variant no_hipe description {disable HiPE native compilation support} {
 # Currently produces bus errors in 10.5.3 due to changes in
 # signal handling
 configure.args-delete   --enable-hipe
}


platform i386 {
   pre-configure {
      file copy ${filespath}/mach_override.h ${workpath}/${name}-${version}/erts/emulator/hipe
      file copy ${filespath}/mach_override.c ${workpath}/${name}-${version}/erts/emulator/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

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

Save the following script to ~/Desktop/mkerlangport.sh:

#!/usr/bin/env bash
macports_repo=/opt/local/var/macports/sources/rsync.macports.org
local_repo=/opt/local/var/macports/sources/local
sources=/opt/local/etc/macports/sources.conf
port=lang/erlang
cat ${sources} | grep file://${local_repo} > /dev/null
if [ ! $? ]
then
    tmpfile=`mktemp -t sources.conf`
    cat ${sources} > ${tmpfile}
    echo "file://${local_repo} [nosync]" | cat ${tmpfile} > ${sources}
fi
mkdir -p ${local_repo}/${port}/files
cp ${macports_repo}/release/ports/${port}/files/* ${local_repo}/${port}/files
cp ~/Desktop/Portfile ${local_repo}/${port}/Portfile
portindex ${local_repo}

Run this script in terminal as sudo bash ~/Desktop/mkerlangport.sh. It should report

Creating software index in /opt/local/var/macports/sources/local
Adding port lang/erlang

Total number of ports parsed: 1 
Ports successfully parsed: 1  
Ports failed:   0

Once you have created the Portfile and installed it as instructed above you can sudo port install erlang @R13A +smp +ssl to get R13A. If you have R12B already installed you should sudo port deactivate erlang first. I am not sure if upgrade works since I haven't tried it.