Created
April 9, 2019 16:47
-
-
Save Wizermil/a4d111fdd8966f78d4093897d0fe1b9a to your computer and use it in GitHub Desktop.
Script to compile openssl + curl static library for emscripten
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
CURRENT_ARCH="emscripten" | |
CURL_VERSION="7.64.1" | |
OPENSSL_VERSION="1.1.1b" | |
ROOT_DIR=$(pwd) | |
WORKER=$(getconf _NPROCESSORS_ONLN) | |
BUILD_DIR_OPENSSL="build/emscripten/openssl" | |
BUILD_DIR_CURL="build/emscripten/curl" | |
LOG_FILE="$ROOT_DIR/$BUILD_DIR_OPENSSL/build.log" | |
COLOR_GREEN="\033[38;5;48m" | |
COLOR_END="\033[0m" | |
#Clean up stale build... | |
if [ -d "$BUILD_DIR_OPENSSL/tar" ]; then | |
rm -rf "$BUILD_DIR_OPENSSL/tar" | |
fi | |
if [ -d "$BUILD_DIR_OPENSSL/src" ]; then | |
rm -rf "$BUILD_DIR_OPENSSL/src" | |
fi | |
if [ -d "$BUILD_DIR_OPENSSL/install" ]; then | |
rm -rf "$BUILD_DIR_OPENSSL/install" | |
fi | |
if [ -f "$LOG_FILE" ]; then | |
rm "$LOG_FILE" | |
touch "$LOG_FILE" | |
fi | |
mkdir -p "$BUILD_DIR_OPENSSL/tar" | |
mkdir -p "$BUILD_DIR_OPENSSL/src" | |
mkdir -p "$BUILD_DIR_OPENSSL/install" | |
error() { | |
echo -e "$@" 1>&2 | |
} | |
fail() { | |
error "$@" | |
exit 1 | |
} | |
# OpenSSL | |
echo "Downloading OpenSSL..." | |
curl -Lo "$BUILD_DIR_OPENSSL/tar/openssl-$OPENSSL_VERSION.tar.gz" "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz" >> "$LOG_FILE" 2>&1 || fail "Couldn't download openssl." | |
echo "Uncompressing OpenSSL..." | |
tar xzf "${BUILD_DIR_OPENSSL}/tar/openssl-$OPENSSL_VERSION.tar.gz" -C "$BUILD_DIR_OPENSSL/src" || fail "Couldn't uncompress openssl" | |
cd "$BUILD_DIR_OPENSSL/src/openssl-$OPENSSL_VERSION" | |
echo "Building OpenSSL for $CURRENT_ARCH build..." | |
emmake make clean 1>& /dev/null || true | |
echo "-> Configuring OpenSSL for $CURRENT_ARCH build..." | |
export LDFLAGS="-s\ USE_ZLIB=1 -Os" | |
export CFLAGS="-D__STDC_NO_ATOMICS__=1 -s\ USE_ZLIB=1 -m32 -Os" | |
export CPPFLAGS="$CFLAGS" | |
export CXXFLAGS="${CFLAGS} -fno-exceptions -fno-rtti" | |
emconfigure ./Configure darwin-i386-cc no-ssl2 no-ssl3 no-comp no-hw no-engine no-shared no-tests no-ui no-deprecated zlib no-asm no-threads "$CFLAGS" >> "$LOG_FILE" 2>&1 | |
sed -i "" -e "s~^CNF_CFLAGS=.*$~CNF_CFLAGS=~g" "Makefile" || exit 1 | |
sed -i "" -e "s~^LDFLAGS=.*$~LDFLAGS=$LDFLAGS~g" "Makefile" || exit 1 | |
sed -i "" -e "s~^CFLAGS=.*$~CFLAGS=$CFLAGS~g" "Makefile" || exit 1 | |
sed -i "" -e "s~^CPPFLAGS=.*$~CPPFLAGS=$CPPFLAGS~g" "Makefile" || exit 1 | |
sed -i "" -e "s~^CXXFLAGS=.*$~CXXFLAGS=$CXXFLAGS~g" "Makefile" || exit 1 | |
sed -i "" -e "s~^CROSS_COMPILE.*$~CROSS_COMPILE=~g" "Makefile" || exit 1 | |
echo "-> Configured OpenSSL for $CURRENT_ARCH" | |
echo "-> Compiling OpenSSL for $CURRENT_ARCH..." | |
emmake make -j "$WORKER" >> "$LOG_FILE" 2>&1 | |
echo "-> Compiled OpenSSL for $CURRENT_ARCH" | |
echo "-> Installing OpenSSL for $CURRENT_ARCH to $ROOT_DIR/$BUILD_DIR_OPENSSL/install/openssl/$CURRENT_ARCH..." | |
emmake make install DESTDIR="$ROOT_DIR/$BUILD_DIR_OPENSSL/install/openssl/$CURRENT_ARCH" >> "$LOG_FILE" 2>&1 | |
echo "-> Installed OpenSSL for $CURRENT_ARCH" | |
echo "Successfully built OpenSSL for $CURRENT_ARCH" | |
echo -e "${COLOR_GREEN}OpenSSL Built Successfully.$COLOR_END" | |
# cURL | |
cd "$ROOT_DIR" | |
LOG_FILE="$ROOT_DIR/$BUILD_DIR_CURL/build.log" | |
if [ -d "$BUILD_DIR_CURL/tar" ]; then | |
rm -rf "$BUILD_DIR_CURL/tar" | |
fi | |
if [ -d "$BUILD_DIR_CURL/src" ]; then | |
rm -rf "$BUILD_DIR_CURL/src" | |
fi | |
if [ -d "$BUILD_DIR_CURL/install" ]; then | |
rm -rf "$BUILD_DIR_CURL/install" | |
fi | |
if [ -f "$LOG_FILE" ]; then | |
rm "$LOG_FILE" | |
touch "$LOG_FILE" | |
fi | |
mkdir -p "$BUILD_DIR_CURL/tar" | |
mkdir -p "$BUILD_DIR_CURL/src" | |
mkdir -p "$BUILD_DIR_CURL/install" | |
echo "Downloading curl..." | |
curl -Lo "$BUILD_DIR_CURL/tar/curl-$CURL_VERSION.tar.gz" "https://curl.haxx.se/download/curl-$CURL_VERSION.tar.gz" >> "$LOG_FILE" 2>&1 || fail "Couldn't download curl." | |
echo "Uncompressing curl..." | |
tar xzf "$BUILD_DIR_CURL/tar/curl-$CURL_VERSION.tar.gz" -C "$BUILD_DIR_CURL/src" || fail "Couldn't uncompress curl." | |
cd "$BUILD_DIR_CURL/src/curl-$CURL_VERSION" | |
echo "Building curl for $CURRENT_ARCH build..." | |
emmake make clean 1>& /dev/null || true | |
echo "-> Configuring curl for $CURRENT_ARCH build..." | |
export LDFLAGS="-arch=i686 -s USE_ZLIB=1 -Os" | |
export CFLAGS="-D__STDC_NO_ATOMICS__=1 -s USE_ZLIB=1 -arch=i686 -m32 -Os" | |
export CPPFLAGS="$CFLAGS" | |
export CXXFLAGS="${CFLAGS} -fno-exceptions -fno-rtti" | |
emconfigure ./configure --host=i386-apple-darwin \ | |
--prefix="$ROOT_DIR/$BUILD_DIR_CURL/install/curl/$CURRENT_ARCH" \ | |
--with-ssl="$ROOT_DIR/$BUILD_DIR_OPENSSL/install/openssl/$CURRENT_ARCH/usr/local" \ | |
--enable-static \ | |
--disable-shared \ | |
--disable-debug \ | |
--disable-curldebug \ | |
--enable-symbol-hiding \ | |
--enable-optimize \ | |
--disable-ares \ | |
--disable-threaded-resolver \ | |
--disable-pthreads \ | |
--disable-manual \ | |
--disable-ipv6 \ | |
--enable-proxy \ | |
--enable-http \ | |
--disable-rtsp \ | |
--disable-ftp \ | |
--disable-file \ | |
--disable-ldap \ | |
--disable-ldaps \ | |
--disable-rtsp \ | |
--disable-dict \ | |
--disable-telnet \ | |
--disable-tftp \ | |
--disable-pop3 \ | |
--disable-imap \ | |
--disable-smtp \ | |
--disable-gopher \ | |
--without-libssh2 \ | |
--without-librtmp \ | |
--without-libidn \ | |
--without-ca-bundle \ | |
--without-ca-path \ | |
--without-winidn \ | |
--without-nghttp2 \ | |
--without-cyassl \ | |
--without-polarssl \ | |
--without-gnutls \ | |
--without-winssl \ | |
--with-zlib >> "$LOG_FILE" 2>&1 || fail "-> Error Configuring for $CURRENT_ARCH" | |
# sed -i '' -e 's~#define HAVE_STRDUP~//#define HAVE_STRDUP~g' configure | |
echo "-> Configured curl for $CURRENT_ARCH" | |
echo "-> Compiling curl for $CURRENT_ARCH..." | |
emmake make -j "$WORKER" >> "$LOG_FILE" 2>&1 || fail "-> Error Compiling for $CURRENT_ARCH" | |
echo "-> Compiled curl for $CURRENT_ARCH" | |
echo "-> Installing curl for $CURRENT_ARCH to $ROOT_DIR/$BUILD_DIR_CURL/install/curl/$CURRENT_ARCH..." | |
emmake make install >> "$LOG_FILE" 2>&1 || fail "-> Error Installing for $CURRENT_ARCH" | |
echo "-> Installed curl for $CURRENT_ARCH" | |
echo "Successfully built curl for $CURRENT_ARCH" | |
echo -e "${COLOR_GREEN}curl built successfully.${COLOR_END}" | |
cd "$ROOT_DIR" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment