-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-cmd.sh
executable file
·348 lines (294 loc) · 14.1 KB
/
build-cmd.sh
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/usr/bin/env bash
cd "$(dirname "$0")"
# turn on verbose debugging output for parabuild logs.
exec 4>&1; export BASH_XTRACEFD=4; set -x
# make errors fatal
set -e
# complain about unreferenced environment variables
set -u
if [ -z "$AUTOBUILD" ] ; then
exit 1
fi
if [ "$OSTYPE" = "cygwin" ] ; then
autobuild="$(cygpath -u $AUTOBUILD)"
else
autobuild="$AUTOBUILD"
fi
# Restore all .sos
restore_sos ()
{
for solib in "${stage}"/packages/lib/{debug,release}/*.so*.disable; do
if [ -f "$solib" ]; then
mv -f "$solib" "${solib%.disable}"
fi
done
}
# Restore all .dylibs
restore_dylibs ()
{
for dylib in "$stage/packages/lib"/{debug,release}/*.dylib.disable; do
if [ -f "$dylib" ]; then
mv "$dylib" "${dylib%.disable}"
fi
done
}
top="$(pwd)"
stage="$top/stage"
[ -f "$stage"/packages/include/zlib-ng/zlib.h ] || \
{ echo "You haven't yet run 'autobuild install'." 1>&2; exit 1; }
# load autobuild provided shell functions and variables
source_environment_tempfile="$stage/source_environment.sh"
"$autobuild" source_environment > "$source_environment_tempfile"
. "$source_environment_tempfile"
OPENSSL_SOURCE_DIR="openssl"
raw_version=$(perl -ne 's/#\s*define\s+OPENSSL_VERSION_NUMBER\s+([\d]+)/$1/ && print' "${OPENSSL_SOURCE_DIR}/include/openssl/opensslv.h")
major_version=$(echo ${raw_version:2:1})
minor_version=$((10#$(echo ${raw_version:3:2})))
build_version=$((10#$(echo ${raw_version:5:2})))
patch_level_hex=$(echo $raw_version | cut -c 8-9)
patch_level_dec=$((16#$patch_level_hex))
str="abcdefghijklmnopqrstuvwxyz"
patch_level_version=$(echo ${str:patch_level_dec-1:1})
version_str=${major_version}.${minor_version}.${build_version}${patch_level_version}
build=${AUTOBUILD_BUILD_ID:=0}
echo "${version_str}.${build}" > "${stage}/VERSION.txt"
pushd "$OPENSSL_SOURCE_DIR"
case "$AUTOBUILD_PLATFORM" in
windows*)
load_vsvars
mkdir -p "$stage/lib/release"
if [ "$AUTOBUILD_ADDRSIZE" = 32 ]
then
targetname=VC-WIN32
else
# might require running vcvars64.bat from VS studio
targetname=VC-WIN64A
fi
# configre won't work with VC-* builds undex cygwin's perl, use window's one
# Set CFLAG directly, rather than on the Configure command line.
# Configure promises to pass through -switches, but is completely
# confounded by /switches. If you change /switches to -switches
# using bash string magic, Configure does pass them through --
# only to have cl.exe ignore them with extremely verbose warnings!
# CFLAG can accept /switches and correctly pass them to cl.exe.
export CFLAG="$LL_BUILD_RELEASE"
# disable idea cypher per Phoenix's patent concerns (DEV-22827)
# no-asm disables the need for NASM
/cygdrive/c/Strawberry/perl/bin/perl Configure "$targetname" no-idea zlib threads -DNO_WINDOWS_BRAINDEATH \
--with-zlib-include="$(cygpath -w "$stage/packages/include/zlib")" \
--with-zlib-lib="$(cygpath -w "$stage/packages/lib/release/zlib.lib")"
# We've observed some weird failures in which the PATH is too big
# to be passed into cmd.exe! When that gets munged, we start
# seeing errors like failing to understand the 'perl' command --
# which we *just* successfully used. Thing is, by this point in
# the script we've acquired a shocking number of duplicate
# entries. Dedup the PATH using Python's OrderedDict, which
# preserves the order in which you insert keys.
# We find that some of the Visual Studio PATH entries appear both
# with and without a trailing slash, which is pointless. Strip
# those off and dedup what's left.
# Pass the existing PATH as an explicit argument rather than
# reading it from the environment to bypass the fact that cygwin
# implicitly converts PATH to Windows form when running a native
# executable. Since we're setting bash's PATH, leave everything in
# cygwin form. That means splitting and rejoining on ':' rather
# than on os.pathsep, which on Windows is ';'.
# Use python -u, else the resulting PATH will end with a spurious '\r'.
export PATH="$(python -u -c "import sys
from collections import OrderedDict
print(':'.join(OrderedDict((dir.rstrip('/'), 1) for dir in sys.argv[1].split(':'))))" "$PATH")"
# Define PERL for nmake to use
PERL="c:/Strawberry/perl/bin"
nmake
# Publish headers
mkdir -p "$stage/include/openssl"
# These files are symlinks in the SSL dist but just show up as text files
# on windows that contain a string to their source. So run some perl to
# copy the right files over.
perl ../copy-windows-links.pl \
"include/openssl" "$(cygpath -w "$stage/include/openssl")"
#nmake test
# move dlls and libs
# It appears that libssl_static.lib is for integration and
# libssl.lib is for dll import. We probably don't care about
# _static variant since we need a dll, include just in case
if [ "$AUTOBUILD_ADDRSIZE" = 32 ]
then
mv libssl-1_1.dll $stage/lib/release/.
mv libssl-1_1.pdb $stage/lib/release/.
mv libssl_static.lib $stage/lib/release/.
mv libssl.lib $stage/lib/release/.
mv libcrypto-1_1.dll $stage/lib/release/.
mv libcrypto-1_1.pdb $stage/lib/release/.
mv libcrypto_static.lib $stage/lib/release/.
mv libcrypto.lib $stage/lib/release/.
else
mv libssl-1_1-x64.dll $stage/lib/release/.
mv libssl-1_1-x64.pdb $stage/lib/release/.
mv libssl_static.lib $stage/lib/release/.
mv libssl.lib $stage/lib/release/.
mv libcrypto-1_1-x64.dll $stage/lib/release/.
mv libcrypto-1_1-x64.pdb $stage/lib/release/.
mv libcrypto_static.lib $stage/lib/release/.
mv libcrypto.lib $stage/lib/release/.
fi
;;
darwin*)
# workaround for finding makedepend on OS X
export PATH="$PATH":/usr/X11/bin/
# Install name for dylibs based on major version number
# Not clear exactly why Configure/make generates lib*.1.0.0.dylib
# for ${major_version}.${minor_version}.${build_version} == 1.0.1,
# but obviously we must correctly predict the dylib filenames.
crypto_target_name="libcrypto.${major_version}.${minor_version}.dylib"
crypto_install_name="@executable_path/../Resources/${crypto_target_name}"
ssl_target_name="libssl.${major_version}.${minor_version}.dylib"
ssl_install_name="@executable_path/../Resources/${ssl_target_name}"
# Force static linkage by moving .dylibs out of the way
trap restore_dylibs EXIT
for dylib in "$stage/packages/lib"/{debug,release}/*.dylib; do
if [ -f "$dylib" ]; then
mv "$dylib" "$dylib".disable
fi
done
# Normally here we'd insert -arch $AUTOBUILD_CONFIGURE_ARCH before
# $LL_BUILD_RELEASE. But the way we must pass these $opts into
# Configure doesn't seem to work for -arch: we get tons of:
# clang: warning: argument unused during compilation: '-arch=x86_64'
# Anyway, selection of $targetname (below) appears to handle the
# -arch switch implicitly.
opts="${TARGET_OPTS:-$LL_BUILD_RELEASE}"
# As of 2017-09-08:
# clang: error: unknown argument: '-gdwarf-with-dsym'
opts="${opts/-gdwarf-with-dsym/-gdwarf-2}"
export CFLAG="$opts"
export LDFLAGS="-Wl,-headerpad_max_install_names"
if [ "$AUTOBUILD_ADDRSIZE" = 32 ]
then
targetname='darwin-i386-cc 386'
else
targetname='darwin64-x86_64-cc'
fi
# It seems to be important to Configure to pass (e.g.)
# "-iwithsysroot=/some/path" instead of just glomming them on
# as separate arguments. So make a pass over $opts, collecting
# switches with args in that form into a bash array.
packed=()
pack=()
function flush {
local IFS="="
# Flush 'pack' array to the next entry of 'packed'.
# ${pack[*]} concatenates all of pack's entries into a single
# string separated by the first char from $IFS.
packed[${#packed[*]}]="${pack[*]:-}"
pack=()
}
for opt in $opts $LDFLAGS
do
if [ "${opt#-}" != "$opt" ]
then
# 'opt' does indeed start with dash.
flush
fi
# append 'opt' to 'pack' array
pack[${#pack[*]}]="$opt"
done
# When we exit the above loop, we've got one more pending entry in
# 'pack'. Flush that too.
flush
# We always have an extra first entry in 'packed'. Get rid of that.
unset packed[0]
# Release
./Configure zlib threads no-idea shared no-gost $targetname \
--prefix="$stage" --libdir="lib/release" --openssldir="share" \
--with-zlib-include="$stage/packages/include/zlib" \
--with-zlib-lib="$stage/packages/lib/release" \
"${packed[@]}"
make depend
make
# Avoid plain 'make install' because, at least on Yosemite,
# installing the man pages into the staging area creates problems
# due to the number of symlinks. Thanks to Cinder for suggesting
# this make target.
make install_sw
# Modify .dylib path information. Do this after install
# to the copies rather than built or the dylib's will be
# linked again wiping out the install_name.
crypto_stage_name="${stage}/lib/release/${crypto_target_name}"
ssl_stage_name="${stage}/lib/release/${ssl_target_name}"
chmod u+w "${crypto_stage_name}" "${ssl_stage_name}"
install_name_tool -id "${ssl_install_name}" "${ssl_stage_name}"
install_name_tool -id "${crypto_install_name}" "${crypto_stage_name}"
install_name_tool -change "${crypto_stage_name}" "${crypto_install_name}" "${ssl_stage_name}"
# conditionally run unit tests
if [ "${DISABLE_UNIT_TESTS:-0}" = "0" ]; then
make test
fi
make clean
;;
linux*)
# Linux build environment at Linden comes pre-polluted with stuff that can
# seriously damage 3rd-party builds. Environmental garbage you can expect
# includes:
#
# DISTCC_POTENTIAL_HOSTS arch root CXXFLAGS
# DISTCC_LOCATION top branch CC
# DISTCC_HOSTS build_name suffix CXX
# LSDISTCC_ARGS repo prefix CFLAGS
# cxx_version AUTOBUILD SIGN CPPFLAGS
#
# So, clear out bits that shouldn't affect our configure-directed build
# but which do nonetheless.
#
# unset DISTCC_HOSTS CC CXX CFLAGS CPPFLAGS CXXFLAGS
# Default target per AUTOBUILD_ADDRSIZE
opts="${TARGET_OPTS:--m$AUTOBUILD_ADDRSIZE $LL_BUILD_RELEASE}"
# Handle any deliberate platform targeting
if [ -z "${TARGET_CPPFLAGS:-}" ]; then
# Remove sysroot contamination from build environment
unset CPPFLAGS
else
# Incorporate special pre-processing flags
export CPPFLAGS="${TARGET_CPPFLAGS:-}"
fi
# Force static linkage to libz by moving .sos out of the way
trap restore_sos EXIT
for solib in "${stage}"/packages/lib/debug/*.so* "${stage}"/packages/lib/release/*.so*; do
if [ -f "$solib" ]; then
mv -f "$solib" "$solib".disable
fi
done
if [ "$AUTOBUILD_ADDRSIZE" = 32 ]
then
targetname='linux-generic32'
else
targetname='linux-x86_64'
fi
# '--libdir' functions a bit different than usual. Here it names
# a part of a directory path, not the entire thing. Same with
# '--openssldir' as well.
# "shared" means build shared and static, instead of just static.
./Configure zlib threads shared no-idea "$targetname" -fno-stack-protector "$opts" \
--prefix="$stage" --libdir="lib/release" --openssldir="share" \
--with-zlib-include="$stage/packages/include/zlib-ng" \
--with-zlib-lib="$stage"/packages/lib/release/
make depend
make
make install
# conditionally run unit tests (disabled for now, it always fails during the tests)
#if [ "${DISABLE_UNIT_TESTS:-0}" = "0" ]; then
# make test
#fi
make clean
# By default, 'make install' leaves even the user write bit off.
# This causes trouble for us down the road, along about the time
# the consuming build tries to strip libraries. It's easier to
# make writable here than fix the viewer packaging.
chmod u+w "$stage"/lib/release/lib{crypto,ssl}.so*
;;
esac
mkdir -p "$stage/LICENSES"
cp -a LICENSE "$stage/LICENSES/openssl.txt"
popd
mkdir -p "$stage"/docs/openssl/
cp -a README.Linden "$stage"/docs/openssl/