# Template file for 'erlang'
pkgname=erlang
version=18.0
revision=2
wrksrc=otp_src_${version}
build_style=gnu-configure
configure_args="--enable-smp-support"
hostmakedepends="perl libxslt"
makedepends="ncurses-devel unixodbc-devel libressl-devel zlib-devel
 $(vopt_if x11 'wxGTK-devel glu-devel')"
short_desc="Concurrent functional programming language developed by Ericsson"
maintainer="Christian Neukirchen <chneukirchen@gmail.com>"
license="Apache-2.0"
homepage="http://www.erlang.org/"
distfiles="http://www.erlang.org/download/otp_src_${version}.tar.gz
 http://www.erlang.org/download/otp_doc_man_${version}.tar.gz"
checksum="a0b69da34b4f218eb7d63d9e96fc120aa7257bb6c37a0f40fb388e188b4111aa
 e44f0ec36ee0683867bc2aa9cc7fbb020d9dfd57338f37b98dcd0771f5b95673"

build_options="x11"

post_extract() {
	sed -i 's/__uint32_t/uint32_t/' erts/emulator/sys/common/erl_poll.h
	sed -i 's/__ANDROID__/__linux__/' lib/erl_interface/src/connect/ei_resolve.c
	sed -i -e 's/#if __GLIBC__ == 2 && (__GLIBC_MINOR__ >= 3)/& || __linux__/' \
		-e '/!defined(__GLIBC__) && !defined(__DARWIN__) && !defined(__NetBSD__)/s/__GLIBC__/__linux__/' \
		-e '/#define _NSIG NSIG/d' \
		erts/emulator/hipe/hipe_x86_signal.c
}
pre_configure() {
	if [ "$CROSS_BUILD" ]; then
		# Build the bootstrap compiler for the host platform.
		env - PATH=/usr/bin:/usr/sbin ./configure --enable-bootstrap-only
		env - PATH=/usr/bin:/usr/sbin HOME=$HOME make ${makejobs}
		configure_args+=" --build=$(erts/autoconf/config.guess)"
		export erl_xcomp_sysroot=/usr/${XBPS_CROSS_TRIPLET}
	fi
}

post_install() {
	vmkdir usr/share/man
	vmkdir usr/lib/erlang/man
	vcopy ../man/man1 usr/share/man
	vcopy ../man/man3 usr/lib/erlang/man
	vcopy ../man/man4 usr/lib/erlang/man
	vcopy ../man/man7 usr/lib/erlang/man
}
