# Depends on static-perl

# Exit on error:
set -e

wget ftp://ftp.openssl.org/source/old/1.0.1/openssl-1.0.1i.tar.gz
tar xf openssl-1.0.1i.tar.gz
cd openssl-1.0.1i

# https://rt.openssl.org/Ticket/Display.html?id=2823&user=guest&pass=guest
sed -e '193 s/#if defined(linux) && !defined(TERMIO)/#if defined(linux)/'\
    -e '194 s/# undef  TERMIOS/# define TERMIOS/' \
    -e '195 s/# define TERMIO/# undef  TERMIO/' \
    -i crypto/ui/ui_openssl.c

PERL=/static/bin/perl \
    CC=/static/bin/musl-gcc \
    LDFLAGS='-s -L/static/lib -static -static-libgcc' \
    ./config --prefix=/static \
    --openssldir=/static/etc/ssl

PERL=/static/bin/perl \
    make -j1

make install_sw
cd ..
rm -rf openssl-1.0.1i
rm openssl-1.0.1i.tar.gz

exit 0
