blob: 1a1d04a67142072961d13f67cfff59f61a677d3b [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
Willy Tarreaucbc0c232021-06-17 15:39:30 +020020# recent openssl versions support parallel builds and skipping the docs,
21# while older ones require to build everything sequentially.
Ilya Shipitsin054a5b82019-05-03 14:31:20 +050022build_openssl_linux () {
23 (
24 cd "openssl-${OPENSSL_VERSION}/"
25 ./config shared --prefix="${HOME}/opt" --openssldir="${HOME}/opt" -DPURIFY
Willy Tarreaucbc0c232021-06-17 15:39:30 +020026 if [ -z "${OPENSSL_VERSION##1.*}" ]; then
27 make all
28 else
29 make -j$(nproc) build_sw
30 fi
Willy Tarreauc6f14982021-06-10 07:52:23 +020031 make install_sw
Ilya Shipitsin054a5b82019-05-03 14:31:20 +050032 )
33}
34
35build_openssl_osx () {
36 (
37 cd "openssl-${OPENSSL_VERSION}/"
38 ./Configure darwin64-x86_64-cc shared \
39 --prefix="${HOME}/opt" --openssldir="${HOME}/opt" -DPURIFY
Willy Tarreauf4b98012021-06-10 07:52:23 +020040 make depend build_sw install_sw
Ilya Shipitsin054a5b82019-05-03 14:31:20 +050041 )
42}
43
44build_openssl () {
45 if [ "$(cat ${HOME}/opt/.openssl-version)" != "${OPENSSL_VERSION}" ]; then
46 tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz"
Ilya Shipitsin47e09dd2020-02-11 14:36:23 +050047 case `uname` in
48 'Darwin')
49 build_openssl_osx
50 ;;
51 'Linux')
52 build_openssl_linux
53 ;;
54 esac
Ilya Shipitsin054a5b82019-05-03 14:31:20 +050055 echo "${OPENSSL_VERSION}" > "${HOME}/opt/.openssl-version"
56 fi
57}
58
59download_libressl () {
60 if [ ! -f "download-cache/libressl-${LIBRESSL_VERSION}.tar.gz" ]; then
61 wget -P download-cache/ \
62 "https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${LIBRESSL_VERSION}.tar.gz"
63 fi
64}
65
Ilya Shipitsin054a5b82019-05-03 14:31:20 +050066build_libressl () {
67 if [ "$(cat ${HOME}/opt/.libressl-version)" != "${LIBRESSL_VERSION}" ]; then
68 tar zxf "download-cache/libressl-${LIBRESSL_VERSION}.tar.gz"
69 (
70 cd "libressl-${LIBRESSL_VERSION}/"
71 ./configure --prefix="${HOME}/opt"
72 make all install
73 )
74 echo "${LIBRESSL_VERSION}" > "${HOME}/opt/.libressl-version"
75 fi
76}
77
Ilya Shipitsina088d3d2019-06-05 02:16:51 +050078download_boringssl () {
79 if [ ! -d "download-cache/boringssl" ]; then
80 git clone --depth=1 https://boringssl.googlesource.com/boringssl download-cache/boringssl
81 else
82 (
83 cd download-cache/boringssl
84 git pull
85 )
86 fi
87}
88
Ilya Shipitsin054a5b82019-05-03 14:31:20 +050089if [ ! -z ${LIBRESSL_VERSION+x} ]; then
90 download_libressl
91 build_libressl
92fi
93
94if [ ! -z ${OPENSSL_VERSION+x} ]; then
95 download_openssl
96 build_openssl
97fi
98
Ilya Shipitsin35d20af2019-05-09 01:15:59 +050099if [ ! -z ${BORINGSSL+x} ]; then
100 (
Ilya Shipitsin8abf0262019-09-16 16:13:10 +0500101
102 # travis-ci comes with go-1.11, while boringssl requires go-1.13
103 eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=1.13 bash)"
104
Ilya Shipitsina088d3d2019-06-05 02:16:51 +0500105 download_boringssl
106 cd download-cache/boringssl
107 if [ -d build ]; then rm -rf build; fi
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500108 mkdir build
109 cd build
Ilya Shipitsinaaa34ea2020-06-21 16:39:30 +0500110 cmake -GNinja -DCMAKE_BUILD_TYPE=release -DBUILD_SHARED_LIBS=1 ..
111 ninja
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500112
Ilya Shipitsin6b736b42020-10-11 23:42:51 +0500113 rm -rf ${HOME}/opt/lib || exit 0
114 rm -rf ${HOME}/opt/include || exit 0
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500115
Ilya Shipitsin6b736b42020-10-11 23:42:51 +0500116 mkdir -p ${HOME}/opt/lib
117 cp crypto/libcrypto.so ssl/libssl.so ${HOME}/opt/lib
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500118
Ilya Shipitsin6b736b42020-10-11 23:42:51 +0500119 mkdir -p ${HOME}/opt/include
120 cp -r ../include/* ${HOME}/opt/include
Ilya Shipitsin35d20af2019-05-09 01:15:59 +0500121 )
122fi
Ilya Shipitsin054a5b82019-05-03 14:31:20 +0500123