SUMMARY="The programming language Erlang/OTP"
DESCRIPTION="Erlang is a programming language used to build massively \
scalable soft real-time systems with requirements on high availability. \
Some of its uses are in telecoms, banking, e-commerce, computer telephony \
and instant messaging. Erlang's runtime system has built-in support for \
concurrency, distribution and fault tolerance."
HOMEPAGE="https://www.erlang.org/"
COPYRIGHT="1997-2017 Ericsson AB"
LICENSE="EPL"
REVISION="5"
SOURCE_URI="http://www.erlang.org/download/otp_src_$portVersion.tar.gz"
CHECKSUM_SHA256="fe4a00651db39b8542b04530a48d24b2f2e7e0b77cbe93d728c9f05325bdfe83"
SOURCE_DIR="otp_src_$portVersion"
PATCHES="erlang-19.3.patchset"

ARCHITECTURES="all !x86_gcc2"

PROVIDES="
	erlang = $portVersion
	cmd:ct_run = $portVersion
	cmd:dialyzer = $portVersion
	cmd:epmd = $portVersion
	cmd:erl = $portVersion
	cmd:erlc = $portVersion
	cmd:escript = $portVersion
	cmd:run_erl = $portVersion
	cmd:to_erl = $portVersion
	cmd:typer = $portVersion
	"
REQUIRES="
	haiku
	cmd:libtool
	cmd:gcc
	cmd:perl
	#cmd:wx_config
	lib:libcrypto
	lib:libgl
	lib:libglu
	lib:libncurses
	lib:libssl
	lib:libz
	"

BUILD_REQUIRES="
	haiku_devel
	devel:libcrypto
	devel:libgl
	devel:libglu
	devel:libncurses
	devel:libssl
	devel:libz
	"

BUILD_PREREQUIRES="
	cmd:bison
	cmd:find
	cmd:flex
	cmd:gcc
	cmd:make
	cmd:perl
	cmd:pkg_config
	cmd:tar
	cmd:uname
	#cmd:wx_config
	cmd:yacc
	"

ERLANG_CFLAGS="-DETHR_X86_OUT_OF_ORDER \
				-DHAVE_NET_IF_DL_H \
				-DETHR_HAVE_ETHREAD_DEFINES \
				-DETHR_PTHREADS \
				-DHAVE_CONFIG_H \
				-D_BSD_SOURCE=1 \
				-I../${effectiveTargetMachineTriple} \
				-I../../${effectiveTargetMachineTriple} \
				-I../include/internal \
				-I../../include/internal \
				-I../../emulator/sys/unix \
				-I../../include/${effectiveTargetMachineTriple} \
				-I../../emulator/beam \
				-I../../../erts/include/internal/${effectiveTargetMachineTriple} \
				-I../../../erts/${effectiveTargetMachineTriple} \
				-Imisc \
				-I../include \
				-Iepmd \
				-Iconnect \
				-I../../../erts/emulator/beam \
				-I../../../erts/include/${effectiveTargetMachineTriple} \
				-I../../../../erts/emulator/beam \
				-I../../../../erts/include/${effectiveTargetMachineTriple} \
				-I../../../../erts/${effectiveTargetMachineTriple}"

BUILD()
{
	rm -rf `finddir B_SYSTEM_SETTINGS_DIRECTORY`/network
	mkdir -p `finddir B_SYSTEM_SETTINGS_DIRECTORY`/network
	touch `finddir B_SYSTEM_SETTINGS_DIRECTORY`/network/hostname

	runConfigure --omit-dirs "docDir dataRootDir" configure \
		--prefix="$prefix" \
		--disable-ipv6 \
		--enable-dynamic-ssl-lib \
		--with-ssl="`finddir B_SYSTEM_DEVELOP_DIRECTORY`" \
		--disable-hipe \
		--enable-threads \
		CFLAGS="-I`finddir B_SYSTEM_HEADERS_DIRECTORY`" \
		LDFLAGS="-lnetwork"

	echo "#undef ERTS_SMP" >> erts/${effectiveTargetMachineTriple}/config.h
	echo "#undef USE_THREADS" >> erts/${effectiveTargetMachineTriple}/config.h
	echo "Skip" > lib/megaco/SKIP

	HOME=$HOME make CFLAGS="$ERLANG_CFLAGS"
}

INSTALL()
{
	HOME=$HOME make CFLAGS="$ERLANG_CFLAGS" install
}
