Ilya Shipitsin | 054a5b8 | 2019-05-03 14:31:20 +0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | set -eux |
| 3 | |
| 4 | download_openssl () { |
| 5 | if [ ! -f "download-cache/openssl-${OPENSSL_VERSION}.tar.gz" ]; then |
Ilya Shipitsin | 6e18f92 | 2020-04-07 23:35:49 +0500 | [diff] [blame] | 6 | |
| 7 | # |
| 8 | # OpenSSL has different links for latest and previous releases |
| 9 | # since we want to download several versions, let us try to treat |
| 10 | # current version as latest, if it fails, follow with previous |
| 11 | # |
| 12 | |
| 13 | wget -P download-cache/ \ |
| 14 | "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz" || \ |
Ilya Shipitsin | 054a5b8 | 2019-05-03 14:31:20 +0500 | [diff] [blame] | 15 | wget -P download-cache/ \ |
Ilya Shipitsin | 6e18f92 | 2020-04-07 23:35:49 +0500 | [diff] [blame] | 16 | "https://www.openssl.org/source/old/${OPENSSL_VERSION%[a-z]}/openssl-${OPENSSL_VERSION}.tar.gz" |
Ilya Shipitsin | 054a5b8 | 2019-05-03 14:31:20 +0500 | [diff] [blame] | 17 | fi |
| 18 | } |
| 19 | |
| 20 | build_openssl_linux () { |
| 21 | ( |
| 22 | cd "openssl-${OPENSSL_VERSION}/" |
| 23 | ./config shared --prefix="${HOME}/opt" --openssldir="${HOME}/opt" -DPURIFY |
| 24 | make all install_sw |
| 25 | ) |
| 26 | } |
| 27 | |
| 28 | build_openssl_osx () { |
| 29 | ( |
| 30 | cd "openssl-${OPENSSL_VERSION}/" |
| 31 | ./Configure darwin64-x86_64-cc shared \ |
| 32 | --prefix="${HOME}/opt" --openssldir="${HOME}/opt" -DPURIFY |
| 33 | make depend all install_sw |
| 34 | ) |
| 35 | } |
| 36 | |
| 37 | build_openssl () { |
| 38 | if [ "$(cat ${HOME}/opt/.openssl-version)" != "${OPENSSL_VERSION}" ]; then |
| 39 | tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz" |
Ilya Shipitsin | 47e09dd | 2020-02-11 14:36:23 +0500 | [diff] [blame] | 40 | case `uname` in |
| 41 | 'Darwin') |
| 42 | build_openssl_osx |
| 43 | ;; |
| 44 | 'Linux') |
| 45 | build_openssl_linux |
| 46 | ;; |
| 47 | esac |
Ilya Shipitsin | 054a5b8 | 2019-05-03 14:31:20 +0500 | [diff] [blame] | 48 | echo "${OPENSSL_VERSION}" > "${HOME}/opt/.openssl-version" |
| 49 | fi |
| 50 | } |
| 51 | |
| 52 | download_libressl () { |
| 53 | if [ ! -f "download-cache/libressl-${LIBRESSL_VERSION}.tar.gz" ]; then |
| 54 | wget -P download-cache/ \ |
| 55 | "https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${LIBRESSL_VERSION}.tar.gz" |
| 56 | fi |
| 57 | } |
| 58 | |
Ilya Shipitsin | 054a5b8 | 2019-05-03 14:31:20 +0500 | [diff] [blame] | 59 | build_libressl () { |
| 60 | if [ "$(cat ${HOME}/opt/.libressl-version)" != "${LIBRESSL_VERSION}" ]; then |
| 61 | tar zxf "download-cache/libressl-${LIBRESSL_VERSION}.tar.gz" |
| 62 | ( |
| 63 | cd "libressl-${LIBRESSL_VERSION}/" |
| 64 | ./configure --prefix="${HOME}/opt" |
| 65 | make all install |
| 66 | ) |
| 67 | echo "${LIBRESSL_VERSION}" > "${HOME}/opt/.libressl-version" |
| 68 | fi |
| 69 | } |
| 70 | |
Ilya Shipitsin | a088d3d | 2019-06-05 02:16:51 +0500 | [diff] [blame] | 71 | download_boringssl () { |
| 72 | if [ ! -d "download-cache/boringssl" ]; then |
| 73 | git clone --depth=1 https://boringssl.googlesource.com/boringssl download-cache/boringssl |
| 74 | else |
| 75 | ( |
| 76 | cd download-cache/boringssl |
| 77 | git pull |
| 78 | ) |
| 79 | fi |
| 80 | } |
| 81 | |
Ilya Shipitsin | 054a5b8 | 2019-05-03 14:31:20 +0500 | [diff] [blame] | 82 | if [ ! -z ${LIBRESSL_VERSION+x} ]; then |
| 83 | download_libressl |
| 84 | build_libressl |
| 85 | fi |
| 86 | |
| 87 | if [ ! -z ${OPENSSL_VERSION+x} ]; then |
| 88 | download_openssl |
| 89 | build_openssl |
| 90 | fi |
| 91 | |
Ilya Shipitsin | 35d20af | 2019-05-09 01:15:59 +0500 | [diff] [blame] | 92 | if [ ! -z ${BORINGSSL+x} ]; then |
| 93 | ( |
Ilya Shipitsin | 8abf026 | 2019-09-16 16:13:10 +0500 | [diff] [blame] | 94 | |
| 95 | # travis-ci comes with go-1.11, while boringssl requires go-1.13 |
| 96 | eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=1.13 bash)" |
| 97 | |
Ilya Shipitsin | a088d3d | 2019-06-05 02:16:51 +0500 | [diff] [blame] | 98 | download_boringssl |
| 99 | cd download-cache/boringssl |
| 100 | if [ -d build ]; then rm -rf build; fi |
Ilya Shipitsin | 35d20af | 2019-05-09 01:15:59 +0500 | [diff] [blame] | 101 | mkdir build |
| 102 | cd build |
| 103 | cmake -DCMAKE_BUILD_TYPE=release -DBUILD_SHARED_LIBS=1 .. |
| 104 | make |
| 105 | |
| 106 | rm -rf ${SSL_LIB} || exit 0 |
| 107 | rm -rf ${SSL_INC} || exit 0 |
| 108 | |
| 109 | mkdir -p ${SSL_LIB} |
| 110 | cp crypto/libcrypto.so ssl/libssl.so ${SSL_LIB} |
| 111 | |
| 112 | mkdir -p ${SSL_INC} |
Ilya Shipitsin | a088d3d | 2019-06-05 02:16:51 +0500 | [diff] [blame] | 113 | cp -r ../include/* ${SSL_INC} |
Ilya Shipitsin | 35d20af | 2019-05-09 01:15:59 +0500 | [diff] [blame] | 114 | ) |
| 115 | fi |
Ilya Shipitsin | 054a5b8 | 2019-05-03 14:31:20 +0500 | [diff] [blame] | 116 | |