Skip to content

Instantly share code, notes, and snippets.

@nde1
Created January 9, 2021 02:08
Show Gist options
  • Save nde1/6b98acf138e1faa2bff772c276207723 to your computer and use it in GitHub Desktop.
Save nde1/6b98acf138e1faa2bff772c276207723 to your computer and use it in GitHub Desktop.
erlang r15b02 + openssl 1.0.1c + zlib on smartos
#!/bin/sh
set -e
if [ "$1" = "-d" ] || [ "$1" = "--debug" ]; then
DEBUG=1
fi
[ "$DEBUG" = "1" ] && set -x
#ENABLE_JAVA=1 # comment out to disable
ENABLE_COMPILE_ZLIB=1 # comment out to disable
ENABLE_COMPILE_OPENSSL=1 # comment out to disable
#ENABLE_ERLANG_MAN_PAGES=1 # comment out to disable
#TEST_SUITES=1 # comment out to not run test suites in various compiled libs/apps.
export CC=gcc
export CXX=g++
export MAKE=gmake
export CPPFLAGS=''
export CFLAGS='-fPIC -m64'
export CXXFLAGS="$CFLAGS"
export LDFLAGS='-m64'
######################
ERLANG_VERSION=R15B02
ERLANG_SHA512=65efaa986c6764e6e6db8a9f19eda6ea3920962ec4274979ffc267b0b25a69261265474fb6c25ad7df9e77e0545bf8cb211b3fd10699000285b56f9dc68fb76c
ERLANG_MAN_PAGES_SHA512=f76bfadb543f3fa6b0fb2362a230e285a232f0239f97f599c980221015e98cbd0fac5b5cb3bc7d1ac0fbf13e121d4e8d374d75218cc4ed6dbc945731c74c19cc
OPENSSL_VERSION=1.0.1c
OPENSSL_SHA512=14f766daab0828a2f07c65d6da8469a4a5a2b839ff3da188538c4e2db3e3e2f37217fb37e269617fb438463b75fb77dab0b155f36831ff48edbc9e7f2903ebd3
ZLIB_VERSION=1.2.7
ZLIB_SHA512=b1c073ad26684e354f7c522c14655840592e03872bc0a94690f89cae2ff88f146fce1dad252ff27a889dac4a32ff9f8ab63ba940671f9da89e9ba3e19f1bf58d
JAVA_VER=6; JAVA_UPD=35
JDK32_SHA512=6f696ea49fd249e2999a9b5d0edb88838a0b5a452f96aa30a89cc0b03cf0209c1fd368c60753b606c7c2dedcd8b97e468b690e5df50002e31982c0dca9539744
JDK64_SHA512=8e217250399bfa292737d3be3472b6f5741351e4e230d82820f6dd7e9455848d7a4e90e6d131c36e736615069d9bd27ccca800882daa180a6c6494898323bb40
######################
JAVA_HOME="/opt/jdk/sun/${JAVA_VER}/${JAVA_UPD}"
ERLANG_HOME="/opt/erlang/$ERLANG_VERSION"
BUILD_DIR="/tmp/erlang/sources"
TARBALL_DIR="/tmp/erlang/tarballs"
######################
if [ ! x"$1" = x'--force' ] && [ "`/usr/bin/zonename`" = 'global' ]; then
echo "This should probably not be run in a bare box." >&2
echo >&2
echo "Rerun with --force to continue anyhow." >&2
exit 1
fi
# $1 url
# $2 filename
# $3 sha512
download() {
tries=5
url="$1" ; shift
filename="$1" ; shift
hash="$1" ; shift
while [ ! "$tries" = 0 ]; do
if sha512sum "$filename" 2>/dev/null | grep "$hash" >/dev/null; then
return 0
elif [ -e "$filename" ]; then
rm -f "$filename"
fi
curl -kL "$url" -o "$filename" "$@"
tries=$((tries-1))
done
return 1
}
pkgin -y in gcc-compiler gcc-runtime gcc-tools-0 autoconf automake bison flex m4 gmake perl unixodbc libxslt libxml2
pkgin -y rm openssl # insecure, old junk
# binutils <--- die flaming stabby death with A1 sauce
rm -rf "$ERLANG_HOME" 2>/dev/null || true
mkdir -p "$ERLANG_HOME" "$BUILD_DIR" "$TARBALL_DIR"
######################
##
## ZLIB
##
if [ "$ENABLE_COMPILE_ZLIB" = "1" ]; then
download http://zlib.net/zlib-$ZLIB_VERSION.tar.gz "$TARBALL_DIR/zlib-$ZLIB_VERSION.tar.gz" "$LIB_SHA512"
rm -rf "$BUILD_DIR/zlib-$ZLIB_VERSION" 2>/dev/null || true
tar xf "$TARBALL_DIR/zlib-$ZLIB_VERSION.tar.gz" -C "$BUILD_DIR"
cd "$BUILD_DIR/zlib-$ZLIB_VERSION"
#./configure --static --64 --prefix="$ERLANG_HOME"
[ "$DEBUG" = "1" ] && env
./configure --64 --prefix="$ERLANG_HOME"
$MAKE
[ "$TEST_SUITES" = "1" ] && $MAKE test
$MAKE install
# export CFLAGS="-rpath=\"$ERLANG_HOME/lib\" $CFLAGS"
# export CXXFLAGS="-rpath=\"$ERLANG_HOME/lib\" $CXXFLAGS"
#export CFLAGS="-I\"$ERLANG_HOME/include\" -L\"$ERLANG_HOME/lib\" -lz $CFLAGS"
#export CXXFLAGS="$CFLAGS"
# export LDFLAGS="-L\"$ERLANG_HOME/lib\" -rpath=\"$ERLANG_HOME/lib\" -lz $LDFLAGS"
export LDFLAGS="-L\"$ERLANG_HOME/lib\" -lz $LDFLAGS"
OPENSSL_CONFIGURE_OPTIONS="--with-zlib-lib=\"$ERLANG_HOME/lib\" --with-zlib-include=\"$ERLANG_HOME/include\""
fi # ENABLE_COMPILE_ZLIB
########################## Java
##
## Joyent's Java (6u32) is insecure.
##
## Further details: http://www.oracle.com/technetwork/java/javase/releasenotes-136954.html
##
##
if [ "$ENABLE_JAVA" = "1" ]; then
JDK32="jdk-${JAVA_VER}u${JAVA_UPD}-solaris-i586.sh"
JDK64="jdk-${JAVA_VER}u${JAVA_UPD}-solaris-x64.sh"
download "http://download.oracle.com/otn-pub/java/jdk/${JAVA_VER}u${JAVA_UPD}-b10/$JDK32" "$TARBALL_DIR/$JDK32" "$JDK32_SHA512" -H "Cookie: oraclelicensejdk-${JAVA_VER}u${JAVA_UPD}-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com"
download "http://download.oracle.com/otn-pub/java/jdk/${JAVA_VER}u${JAVA_UPD}-b10/$JDK64" "$TARBALL_DIR/$JDK64" "$JDK64_SHA512" -H "Cookie: oraclelicensejdk-${JAVA_VER}u${JAVA_UPD}-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com"
cd "$BUILD_DIR"
rm -rf "jdk1.${JAVA_VER}.0_${JAVA_UPD}"
sh "$TARBALL_DIR/$JDK32" -noregister
sh "$TARBALL_DIR/$JDK64" -noregister
rm -rf "${JAVA_HOME}" 2>/dev/null || true
mkdir -p "${JAVA_HOME}"
cp -r "jdk1.${JAVA_VER}.0_${JAVA_UPD}"/* "${JAVA_HOME}"
ERLANG_CONFIGURE_OPTIONS="--with-javac=\"${JAVA_HOME}\""
else # ! ENABLE_JAVA
ERLANG_CONFIGURE_OPTIONS="--without-javac"
fi # ENABLE_JAVA
########################## OpenSSL
##
## Joyent's OpenSSL (0.9.8w) is insecure (CVE-2012-2333).
##
if [ "$ENABLE_COMPILE_OPENSSL" = "1" ]; then
download https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz "$TARBALL_DIR/openssl-$OPENSSL_VERSION.tar.gz" "$OPENSSL_SHA512" --cacert <(cat /opt/local/etc/openssl/certs/*.pem)
rm -rf "$BUILD_DIR/openssl-$OPENSSL_VERSION" 2>/dev/null || true
[ "$DEBUG" = "1" ] && env
tar xf "$TARBALL_DIR/openssl-$OPENSSL_VERSION.tar.gz" -C "$BUILD_DIR"
cd "$BUILD_DIR/openssl-$OPENSSL_VERSION"
./Configure \
no-sctp \
no-krb5 \
threads\
shared \
zlib-dynamic \
$OPENSSL_CONFIGURE_OPTIONS \
--openssldir="$ERLANG_HOME/ssl" \
solaris64-x86_64-gcc
# no-shared \
# no-dso \
$MAKE
[ "$TEST_SUITES" = "1" ] && $MAKE test
$MAKE install
# export CFLAGS="-rpath=\"$ERLANG_HOME/ssl/lib\" $CFLAGS"
# export CXXFLAGS="-rpath=\"$ERLANG_HOME/ssl/lib\" $CXXFLAGS"
export CPPFLAGS="$CPPFLAGS -I\"$ERLANG_HOME/include\" -I\"$ERLANG_HOME/ssl/include\""
# [ "$ENABLE_COMPILE_ZLIB" = "1" ] && export LDFLAGS="$LDFLAGS -L\"$ERLANG_HOME/lib\""
export LDFLAGS="$LDFLAGS -L\"$ERLANG_HOME/ssl/lib\""
# export CFLAGS="$CPPFLAGS $LDFLAGS"
export CXXFLAGS="$CFLAGS"
# export CFLAGS="-rpath=\"$ERLANG_HOME/lib\" $CFLAGS"
# export CXXFLAGS="-rpath=\"$ERLANG_HOME/lib\" $CXXFLAGS"
#export STATIC_CFLAGS="$CFLAGS"
export LIBDIR="$ERLANG_HOME/ssl/lib:$ERLANG_HOME/lib"
ERLANG_CONFIGURE_OPTIONS="$ERLANG_CONFIGURE_OPTIONS --with-ssl=$ERLANG_HOME/ssl"
fi # ENABLE_COMPILE_OPENSSL
##########################
##
## Erlang
##
download http://www.erlang.org/download/otp_src_$ERLANG_VERSION.tar.gz "$TARBALL_DIR/otp_src_$ERLANG_VERSION.tar.gz" "$ERLANG_SHA512"
rm -rf "$BUILD_DIR/otp_src_$ERLANG_VERSION" 2>/dev/null || true
tar xf "$TARBALL_DIR/otp_src_$ERLANG_VERSION.tar.gz" -C "$BUILD_DIR"
cd "$BUILD_DIR/otp_src_$ERLANG_VERSION"
# Erlang's zlib is old.
if [ "$ENABLE_COMPILE_ZLIB" = "1" ]; then
# lazy hack, should overwrite even if not compiling for openssl.
cp "$BUILD_DIR/zlib-$ZLIB_VERSION"/*.c "$BUILD_DIR/otp_src_$ERLANG_VERSION/erts/emulator/zlib"
cp "$BUILD_DIR/zlib-$ZLIB_VERSION"/*.h "$BUILD_DIR/otp_src_$ERLANG_VERSION/erts/emulator/zlib"
fi
[ "$DEBUG" = "1" ] && env
./configure \
--prefix="$ERLANG_HOME" \
--enable-m64-build \
--enable-smp-support \
--enable-threads \
--enable-dynamic-ssl-lib \
--disable-sctp \
$ERLANG_CONFIGURE_OPTIONS \
--with-dynamic-trace=dtrace \
--enable-vm-probes
$MAKE
$MAKE install
# man pages
if [ "$ERLANG_MAN_PAGES" = "1" ]; then
download http://www.erlang.org/download/otp_doc_man_$ERLANG_VERSION.tar.gz "$TARBALL_DIR/otp_doc_man_$ERLANG_VERSION.tar.gz" "$ERLANG_MAN_PAGES_SHA512"
tar xf "$TARBALL_DIR/otp_doc_man_$ERLANG_VERSION.tar.gz" -C "$ERLANG_HOME"
fi
# ---- cleanup
rm -rf "$BUILD_DIR" "$TARBALL_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment