forked from andrew-d/static-binaries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·149 lines (119 loc) · 4.21 KB
/
build.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
#!/bin/bash
set -e
set -o pipefail
set -x
ZLIB_VERSION=1.2.8
TERMCAP_VERSION=1.3.1
READLINE_VERSION=6.3
OPENSSL_VERSION=1.0.2c
PYTHON_VERSION=2.7.10
function build_zlib() {
cd /build
# Download
curl -LO http://zlib.net/zlib-${ZLIB_VERSION}.tar.gz
tar zxvf zlib-${ZLIB_VERSION}.tar.gz
cd zlib-${ZLIB_VERSION}
# Build
CC='/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-gcc -static -fPIC' \
./configure \
--static
make -j4
}
function build_termcap() {
cd /build
# Download
curl -LO http://ftp.gnu.org/gnu/termcap/termcap-${TERMCAP_VERSION}.tar.gz
tar zxvf termcap-${TERMCAP_VERSION}.tar.gz
cd termcap-${TERMCAP_VERSION}
# Build
CC='/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-gcc -static -fPIC' \
./configure \
--disable-shared \
--enable-static
make -j4
}
function build_readline() {
cd /build
# Download
curl -LO ftp://ftp.cwru.edu/pub/bash/readline-${READLINE_VERSION}.tar.gz
tar xzvf readline-${READLINE_VERSION}.tar.gz
cd readline-${READLINE_VERSION}
# Build
CC='/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-gcc -static -fPIC' \
./configure \
--disable-shared \
--enable-static
make -j4
# Note that things look for readline in <readline/readline.h>, so we need
# that directory to exist.
ln -s /build/readline-${READLINE_VERSION} /build/readline-${READLINE_VERSION}/readline
}
function build_openssl() {
cd /build
# Download
curl -LO https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
tar zxvf openssl-${OPENSSL_VERSION}.tar.gz
cd openssl-${OPENSSL_VERSION}
# Configure
CC='/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-gcc -static' ./Configure no-shared linux-x86_64
# Build
make
echo "** Finished building OpenSSL"
}
function build_python() {
cd /build
# Download
curl -LO https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
unxz Python-${PYTHON_VERSION}.tar.xz
tar -xvf Python-${PYTHON_VERSION}.tar
cd Python-${PYTHON_VERSION}
# Set up modules
cp Modules/Setup.dist Modules/Setup
MODULES="_bisect _collections _csv _datetime _elementtree _functools _heapq _io _md5 _posixsubprocese _random _sha _sha256 _sha512 _socket _struct _weakref array binascii cmath cStringIO cPickle datetime fcntl future_builtins grp itertools math mmap operator parser readline resource select spwd strop syslog termios time unicodedata zlib"
for mod in $MODULES;
do
sed -i -e "s/^#${mod}/${mod}/" Modules/Setup
done
echo '_json _json.c' >> Modules/Setup
echo '_multiprocessing _multiprocessing/multiprocessing.c _multiprocessing/semaphore.c _multiprocessing/socket_connection.c' >> Modules/Setup
# Enable static linking
sed -i '1i\
*static*' Modules/Setup
# Set dependency paths for zlib, readline, etc.
sed -i \
-e "s|^zlib zlibmodule.c|zlib zlibmodule.c -I/build/zlib-${ZLIB_VERSION} -L/build/zlib-${ZLIB_VERSION} -lz|" \
-e "s|^readline readline.c|readline readline.c -I/build/readline-${READLINE_VERSION} -L/build/readline-${READLINE_VERSION} -L/build/termcap-${TERMCAP_VERSION} -lreadline -ltermcap|" \
Modules/Setup
# Enable OpenSSL support
patch --ignore-whitespace -p1 < /build/cpython-enable-openssl.patch
sed -i \
-e "s|^SSL=/build/openssl-TKTK|SSL=/build/openssl-${OPENSSL_VERSION}|" \
Modules/Setup
# Configure
CC='/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-gcc -static -fPIC' \
CXX='/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-g++ -static -static-libstdc++ -fPIC' \
LD=/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-ld \
./configure \
--disable-shared
# Build
make -j4
/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-strip python
}
function doit() {
build_zlib
build_termcap
build_readline
build_openssl
build_python
# Copy to output
if [ -d /output ]
then
OUT_DIR=/output/`uname | tr 'A-Z' 'a-z'`/`uname -m`
mkdir -p $OUT_DIR
cp python $OUT_DIR/
echo "** Finished **"
else
echo "** /output does not exist **"
fi
}
doit