forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-openssl.sh
More file actions
executable file
·198 lines (168 loc) · 5.72 KB
/
build-openssl.sh
File metadata and controls
executable file
·198 lines (168 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
set -e
source "${BASEDIR}/scripts/platform.inc"
source "${BASEDIR}/scripts/lib_versions.inc"
source "${BASEDIR}/scripts/util.inc"
# Grab the source for the library
OPENSSL_TGZ="openssl-${OpenSSL_VERSION}.tar.gz"
OPENSSL_SRC="openssl-${OpenSSL_VERSION}"
cd "${BUILDDIR}"
if [ ! -d "$OPENSSL_SRC" ] ; then
if [ ! -e "$OPENSSL_TGZ" ] ; then
echo "Fetching OpenSSL source"
fetchUrl "https://www.openssl.org/source/openssl-${OpenSSL_VERSION}.tar.gz" "${OPENSSL_TGZ}"
if [ $? != 0 ] ; then
echo " failed"
if [ -e "${OPENSSL_TGZ}" ] ; then
rm ${OPENSSL_TGZ}
fi
exit
fi
fi
echo "Unpacking OpenSSL source"
tar -xf "${OPENSSL_TGZ}"
fi
function buildOpenSSL {
local PLATFORM=$1
local ARCH=$2
local SUBPLATFORM=$3
# Each target type in OpenSSL is given a name
case "${PLATFORM}" in
mac)
if [ "${ARCH}" == "x86_64" -o "${ARCH}" == "ppc64" ] ; then
SPEC="darwin64-${ARCH}-cc"
else
SPEC="darwin-${ARCH}-cc"
fi
;;
linux)
if [ "${ARCH}" == "x86_64" ] ; then
SPEC="linux-x86_64"
elif [[ "${ARCH}" =~ (x|i[3-6])86 ]] ; then
SPEC="linux-x86"
elif [ "${ARCH}" == "arm64" ] ; then
SPEC="linux-aarch64"
elif [[ "${ARCH}" =~ .*64 ]] ; then
SPEC="linux-generic64"
else
SPEC="linux-generic32"
fi
;;
android)
if [ "${ARCH}" == "x86_64" ] ; then
SPEC="android64"
elif [[ "${ARCH}" =~ (x|i[3-6])86 ]] ; then
# Work around a linker crash using the i686 gold linker in Android NDK r14
EXTRA_CFLAGS="-fuse-ld=bfd"
SPEC="android-x86"
elif [ "${ARCH}" == "arm64" ] ; then
# Clang's integrated assembler is a bit broken so we need to force the use of GAS instead
EXTRA_CFLAGS="-fno-integrated-as"
SPEC="android64-aarch64"
elif [[ "${ARCH}" =~ armv(6|7) ]] ; then
# Clang's integrated assembler is a bit broken so we need to force the use of GAS instead
EXTRA_CFLAGS="-fno-integrated-as -U__clang__"
# When compiling with -mthumb, we need to link to libatomic
EXTRA_OPTIONS="-latomic"
SPEC="android-armeabi"
elif [[ "${ARCH}" =~ .*64 ]] ; then
SPEC="android64"
else
SPEC="android"
fi
;;
ios)
if [ "${ARCH}" == "x86_64" ] ; then
SPEC="darwin64-x86_64-cc"
else
SPEC="iphoneos-cross"
fi
;;
esac
# Utility for displaying platform name
if [ ! -z "${SUBPLATFORM}" ] ; then
local NAME="${PLATFORM}/${ARCH}/${SUBPLATFORM}"
local PLATFORM_NAME=${SUBPLATFORM}
else
local NAME="${PLATFORM}/${ARCH}"
local PLATFORM_NAME=${PLATFORM}
fi
CUSTOM_SPEC="${SPEC}-livecode"
OPENSSL_ARCH_SRC="${OPENSSL_SRC}-${PLATFORM_NAME}-${ARCH}"
OPENSSL_ARCH_CONFIG="no-rc5 no-hw shared -DOPENSSL_NO_ASYNC=1 --prefix=${INSTALL_DIR}/${NAME} ${CUSTOM_SPEC} ${EXTRA_OPTIONS}"
# Copy the source to a target-specific directory
if [ ! -d "${OPENSSL_ARCH_SRC}" ] ; then
echo "Duplicating OpenSSL source directory for ${NAME}"
cp -r "${OPENSSL_SRC}" "${OPENSSL_ARCH_SRC}"
fi
# Patch the main OpenSSL configuration script to remove a '-mandroid' flag that is incompatible with clang.
sed -i.bak -e "s/-mandroid//g" "${OPENSSL_ARCH_SRC}/Configurations/10-main.conf"
# Get the command used to build a previous copy, if any
if [ -e "${OPENSSL_ARCH_SRC}/config.cmd" ] ; then
OPENSSL_ARCH_CURRENT_CONFIG=`cat ${OPENSSL_ARCH_SRC}/config.cmd`
else
OPENSSL_ARCH_CURRENT_CONFIG=
fi
# Re-configure and re-build, if required
if [ "${OPENSSL_ARCH_CONFIG}" != "${OPENSSL_ARCH_CURRENT_CONFIG}" ] ; then
cd "${OPENSSL_ARCH_SRC}"
# Customise the OpenSSL configuration to ensure variables are exported as functions
cat > Configurations/99-livecode.conf << EOF
%targets = (
"${CUSTOM_SPEC}" => {
inherit_from => [ "${SPEC}" ],
bn_ops => sub { join(" ",(@_,"EXPORT_VAR_AS_FN")) },
},
);
EOF
echo "Configuring OpenSSL for ${NAME}"
setCCForTarget "${PLATFORM}" "${ARCH}" "${SUBPLATFORM}"
./Configure ${OPENSSL_ARCH_CONFIG}
# iOS requires some tweaks to the source when building for devices
if [ "${PLATFORM}" == "ios" -a "${ARCH}" != "i386 " ] ; then
sed -i "" -e "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
fi
# iOS SDKs don't work with makedepend
if [ "${PLATFORM}" == "ios" ] ; then
sed -i "" -e "s/MAKEDEPPROG=makedepend/MAKEDEPPROG=$\(CC\) -M/" Makefile
fi
echo "Building OpenSSL for ${NAME}"
make clean && make depend && make ${MAKEFLAGS} && make install_sw
RESULT=$?
cd ..
# Save the configuration for this build
if [ $RESULT == 0 ] ; then
echo "${OPENSSL_ARCH_CONFIG}" > "${OPENSSL_ARCH_SRC}/config.cmd"
else
echo " failed"
exit 1
fi
else
echo "Found existing OpenSSL build for ${NAME}"
fi
if [ "${PLATFORM}" == "mac" -o "${PLATFORM}" == "ios" ] ; then
CRYPTO_LIBS+="${INSTALL_DIR}/${NAME}/lib/libcrypto.a "
SSL_LIBS+="${INSTALL_DIR}/${NAME}/lib/libssl.a "
else
mkdir -p "${OUTPUT_DIR}/lib/${NAME}"
cp "${INSTALL_DIR}/${NAME}/lib/libcrypto.a" "${OUTPUT_DIR}/lib/${NAME}/libcustomcrypto.a"
cp "${INSTALL_DIR}/${NAME}/lib/libssl.a" "${OUTPUT_DIR}/lib/${NAME}/libcustomssl.a"
fi
mkdir -p "${OUTPUT_DIR}/include"
cp -R "${INSTALL_DIR}/${NAME}/include/openssl" "${OUTPUT_DIR}/include/openssl"
}
if [ "${ARCH}" == "universal" ] ; then
# perform build for universal architectures
for UARCH in ${UNIVERSAL_ARCHS} ; do
buildOpenSSL "${PLATFORM}" "${UARCH}" "${SUBPLATFORM}"
done
# Create the universal libraries
echo "Creating OpenSSL ${PLATFORM_NAME} universal libraries"
mkdir -p "${OUTPUT_DIR}/lib/${PLATFORM}/${SUBPLATFORM}"
lipo -create ${CRYPTO_LIBS} -output "${OUTPUT_DIR}/lib/${PLATFORM}/${SUBPLATFORM}/libcustomcrypto.a"
lipo -create ${SSL_LIBS} -output "${OUTPUT_DIR}/lib/${PLATFORM}/${SUBPLATFORM}/libcustomssl.a"
CRYPTO_LIBS=
SSL_LIBS=
else
buildOpenSSL "${PLATFORM}" "${ARCH}" "${SUBPLATFORM}"
fi