forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-openssl.sh
More file actions
executable file
·159 lines (135 loc) · 4.48 KB
/
build-openssl.sh
File metadata and controls
executable file
·159 lines (135 loc) · 4.48 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
#!/bin/bash
source "${BASEDIR}/scripts/platform.inc"
source "${BASEDIR}/scripts/lib_versions.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"
curl http://www.openssl.org/source/openssl-${OpenSSL_VERSION}.tar.gz -o "${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 SUBPLATFORM_INDEX=$1
for ARCH in ${ARCHS}
do
# 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"
else
SPEC="linux-generic32"
fi
;;
android)
if [ "${ARCH}" == "armv6" ] ; then
SPEC="android"
else
SPEC="android-armv7"
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_INDEX}" ] ; then
local SUBPLATFORM="${IOS_SUBPLATFORM[$SUBPLATFORM_INDEX]}${IOS_VERSION[$SUBPLATFORM_INDEX]}"
local NAME="${PLATFORM}/${SUBPLATFORM}/${ARCH}"
local PLATFORM_NAME=${SUBPLATFORM}
else
local NAME="${PLATFORM}/${ARCH}"
local PLATFORM_NAME=${PLATFORM}
fi
OPENSSL_ARCH_SRC="${OPENSSL_SRC}-${PLATFORM_NAME}-${ARCH}"
OPENSSL_ARCH_CONFIG="no-idea no-rc5 no-hw shared --prefix=${INSTALL_DIR}/${NAME} ${SPEC}"
OPENSSL_ARCH_LOG="${OPENSSL_ARCH_SRC}.log"
# 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
# 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}"
echo "Configuring OpenSSL for ${NAME}"
setCCForArch "${ARCH}" "${SUBPLATFORM_INDEX}"
./Configure ${OPENSSL_ARCH_CONFIG} > "${OPENSSL_ARCH_LOG}" 2>&1
# 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
# Ensure that variables get exported as functions
echo "#define OPENSSL_EXPORT_VAR_AS_FUNCTION 1" >> crypto/opensslconf.h
echo "Building OpenSSL for ${NAME}"
make clean >> "${OPENSSL_ARCH_LOG}" 2>&1 && make ${MAKEFLAGS} >> "${OPENSSL_ARCH_LOG}" 2>&1 && make install_sw >> "${OPENSSL_ARCH_LOG}" 2>&1
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
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
done
# Create the universal libraries
if [ "${PLATFORM}" == "mac" -o "${PLATFORM}" == "ios" ] ; then
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=
fi
}
# If building for iOS, a number of sub-platforms need to be build
if [ "${PLATFORM}" == "ios" ] ; then
for (( INDEX=0; INDEX<$IOS_COUNT; INDEX++ ))
do
setArchs ${INDEX}
buildOpenSSL ${INDEX}
done
else
buildOpenSSL
fi