#!/bin/bash
# erlang
# ------
# This is a recipe for installing erlang from source.
PACKAGE_VERSION=${1-R15B03-1}
PACKAGE_SOURCE=http://www.erlang.org/download/otp_src_$PACKAGE_VERSION.tar.gz

require packages build-essential ncurses-dev libicu-dev libssl-dev

# if we don't have the latest node version, then install
log "Checking Erlang version $PACKAGE_VERSION installed";
if [ ! -e $BASHINATE_INSTALL/erlang/$PACKAGE_VERSION ]
then
	local primary_version=`echo $PACKAGE_VERSION | sed -re 's/^(.*)(-[0-9])$/\1/'`
	log "Installing Erlang version $PACKAGE_VERSION (primary version $primary_version)"

	fetchSource $PACKAGE_SOURCE
	cd otp_src_$primary_version

	# don't bother compiling odbc or wx
	touch lib/odbc/SKIP lib/wx/SKIP

	# configure 
	log "- configuring"
	./configure --prefix=$BASHINATE_INSTALL/erlang/$PACKAGE_VERSION ||
		abort "!!! Unable to configure erlang"

	# make and install
	log "- compiling and installing"
	make && make install ||
		abort "!!! Unable to make erlang $PACKAGE_VERSION"
fi