set -e

export HOME=${BOSH_INSTALL_DIR}

cpus="$(grep -c ^processor /proc/cpuinfo)"

VERSION="25.3.2.13"
MAJOR_VERSION="25"
echo "$MAJOR_VERSION" > "$BOSH_INSTALL_TARGET/erlang_version"

if grep -Fxq jammy /etc/lsb-release; then
	jit_flags="--enable-jit"
else
	jit_flags=""
fi

tar xzf erlang-25/otp_src_oss_${VERSION}.tgz
cd otp_src_oss_${VERSION}
./configure \
	--disable-hipe \
	--disable-sctp \
	--disable-silent-rules \
	--enable-dynamic-ssl-lib \
	$jit_flags \
	--enable-clock-gettime \
	--enable-dynamic-ssl \
	--enable-hybrid-heap \
	--enable-kernel-poll \
	--enable-shared-zlib \
	--enable-smp-support \
	--enable-threads \
	--enable-lock-counter \
	--with-microstate-accounting=extra \
	--without-common_test \
	--without-debugger \
	--without-dialyzer \
	--without-diameter \
	--without-edoc \
	--without-erl_docgen \
	--without-et \
	--without-eunit \
	--without-ftp \
	--without-hipe \
	--without-jinterface \
	--without-megaco \
	--without-observer \
	--without-odbc \
	--without-reltool \
	--without-ssh \
	--without-tftp \
	--without-wx \
	--prefix=${BOSH_INSTALL_TARGET}

make -j$cpus
make install
