forked from pypa/manylinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_utils.sh
executable file
·99 lines (84 loc) · 2.92 KB
/
build_utils.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
#!/bin/bash
# Helper utilities for build
PYTHON_DOWNLOAD_URL=https://www.python.org/ftp/python
OPENSSL_DOWNLOAD_URL=http://www.openssl.org/source
GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py
function check_var {
if [ -z "$1" ]; then
echo "required variable not defined"
exit 1
fi
}
function lex_pyver {
# Echoes Python version string padded with zeros
# Thus:
# 3.2.1 -> 003002001
# 3 -> 003000000
echo $1 | awk -F "." '{printf "%03d%03d%03d", $1, $2, $3}'
}
function do_python_build {
local py_ver=$1
check_var $py_ver
local soabi_flags=$2
check_var $soabi_flags
mkdir -p /opt/python/${py_ver}${soabi_flags}/lib
if [ $(lex_pyver $py_ver) -lt $(lex_pyver 3.3) ]; then
if [ $soabi_flags = "mu" ]; then
local unicode_flags="--enable-unicode=ucs4"
else
local unicode_flags="--enable-unicode=ucs2"
fi
fi
# -Wformat added for https://bugs.python.org/issue17547 on Python 2.6
CFLAGS="-Wformat" ./configure --prefix=/opt/python/${py_ver}${soabi_flags} --disable-shared $unicode_flags > /dev/null
make -j2 > /dev/null
make install > /dev/null
}
function build_python {
local py_ver=$1
check_var $py_ver
local py_ver2="$(echo $py_ver | cut -d. -f 1,2)"
check_var $PYTHON_DOWNLOAD_URL
wget -q $PYTHON_DOWNLOAD_URL/$py_ver/Python-$py_ver.tgz
if [ $(lex_pyver $py_ver) -lt $(lex_pyver 3.3) ]; then
local soabi_flags_list="mu m"
fi
for soabi_flags in ${soabi_flags_list:-m}; do
tar -xzf Python-$py_ver.tgz
(cd Python-$py_ver && do_python_build $py_ver $soabi_flags)
if [ $(lex_pyver $py_ver) -ge $(lex_pyver 3) ]; then \
ln -s /opt/python/${py_ver}${soabi_flags}/bin/python3 /opt/python/${py_ver}${soabi_flags}/bin/python;
fi;
ln -s /opt/python/${py_ver}${soabi_flags}/ /opt/${py_ver2}${soabi_flags}
/opt/python/${py_ver}${soabi_flags}/bin/python get-pip.py
/opt/python/${py_ver}${soabi_flags}/bin/pip install wheel
rm -rf Python-$py_ver
done
rm -f Python-$py_ver.tgz
}
function build_pythons {
check_var $GET_PIP_URL
curl -sLO $GET_PIP_URL
for py_ver in $@; do
build_python $py_ver
done
rm get-pip.py
}
function do_openssl_build {
./config no-ssl2 no-shared -fPIC --prefix=/usr/local/ssl > /dev/null
make > /dev/null
make install > /dev/null
}
function build_openssl {
local openssl_fname=$1
check_var $openssl_fname
local openssl_sha256=$2
check_var $openssl_sha256
check_var $OPENSSL_DOWNLOAD_URL
echo "${openssl_sha256} ${openssl_fname}.tar.gz" > ${openssl_fname}.tar.gz.sha256
curl -sLO $OPENSSL_DOWNLOAD_URL/${openssl_fname}.tar.gz
sha256sum -c ${openssl_fname}.tar.gz.sha256
tar -xzf ${openssl_fname}.tar.gz
(cd ${openssl_fname} && do_openssl_build)
rm -rf ${openssl_fname} ${openssl_fname}.tar.gz ${openssl_fname}.tar.gz.sha256
}