blob: 9a6a2b241002532e06206420828a329e764b950e [file] [log] [blame]
Ilya Shipitsin054a5b82019-05-03 14:31:20 +05001#!/bin/sh
2set -eux
3
4download_openssl () {
5 if [ ! -f "download-cache/openssl-${OPENSSL_VERSION}.tar.gz" ]; then
Ilya Shipitsin6e18f922020-04-07 23:35:49 +05006
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 Shipitsin054a5b82019-05-03 14:31:20 +050015 wget -P download-cache/ \
Ilya Shipitsin6e18f922020-04-07 23:35:49 +050016 "https://www.openssl.org/source/old/${OPENSSL_VERSION%[a-z]}/openssl-${OPENSSL_VERSION}.tar.gz"
Ilya Shipitsin054a5b82019-05-03 14:31:20 +050017 fi
18}
19
20build_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
28build_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
37build_openssl () {
38 if [ "$(cat ${HOME}/opt/.openssl-version)" != "${OPENSSL_VERSION}" ]; then
39 tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz"
Ilya Shipitsin47e09dd2020-02-11 14:36:23 +050040 case `uname` in
41 'Darwin')
42 build_openssl_osx
43 ;;
44 'Linux')
45 build_openssl_linux
46 ;;
47 esac
Ilya Shipitsin054a5b82019-05-03 14:31:20 +050048 echo "${OPENSSL_VERSION}" > "${HOME}/opt/.openssl-version"
49 fi
50}
51
52download_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 Shipitsin054a5b82019-05-03 14:31:20 +050059build_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 Shipitsina088d3d2019-06-05 02:16:51 +050071download_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 Shipitsin054a5b82019-05-03 14:31:20 +050082if [ ! -z ${LIBRESSL_VERSION+x} ]; then
83 download_libressl
84 build_libressl
85fi
86
87if [ ! -z ${OPENSSL_VERSION+x} ]; then
88 download_openssl
89 build_openssl
90fi
91
Ilya Shipitsin35d20af2019-05-09 01:15:59 +050092if [ ! -z ${BORINGSSL+x} ]; then
93 (
Ilya Shipitsin8abf0262019-09-16 16:13:10 +050094
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 Shipitsina088d3d2019-06-05 02:16:51 +050098 download_boringssl
99 cd download-cache/boringssl
100 if [ -d build ]; then rm -rf build; fi
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500101 mkdir build
102 cd build
Ilya Shipitsinaaa34ea2020-06-21 16:39:30 +0500103 cmake -GNinja -DCMAKE_BUILD_TYPE=release -DBUILD_SHARED_LIBS=1 ..
104 ninja
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500105
Ilya Shipitsin6b736b42020-10-11 23:42:51 +0500106 rm -rf ${HOME}/opt/lib || exit 0
107 rm -rf ${HOME}/opt/include || exit 0
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500108
Ilya Shipitsin6b736b42020-10-11 23:42:51 +0500109 mkdir -p ${HOME}/opt/lib
110 cp crypto/libcrypto.so ssl/libssl.so ${HOME}/opt/lib
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500111
Ilya Shipitsin6b736b42020-10-11 23:42:51 +0500112 mkdir -p ${HOME}/opt/include
113 cp -r ../include/* ${HOME}/opt/include
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500114 )
115fi
Ilya Shipitsin054a5b82019-05-03 14:31:20 +0500116