-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·234 lines (210 loc) · 6.91 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
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
#!/bin/bash
set -e
NAME="PythonDotApp"
IDENTIFIER="com.github.bit.PythonDotApp"
OSXVERSION=10.9
APPLICATION=application
VERSION=`git tag | head -1 | sed "s/$NAME-//"`
BASE=`pwd`
PREFIX="$BASE/dist"
BREW=/usr/local
brew update
function brew_install {
pkg=$1
brew list | grep -q $pkg || brew install $pkg
brew outdated $pkg || brew upgrade $pkg
}
brew_install openssl
brew_install sqlite
brew_install xz
brew_install readline
# add lxml dependencies
brew_install libxml2
brew_install libxslt
# Python
CPPFLAGS="-I$BREW/opt/openssl/include/openssl"
LDFLAGS=""
for pkg in openssl sqlite readline xz; do
CPPFLAGS="$CPPFLAGS -I$BREW/opt/$pkg/include"
LDFLAGS="$LDFLAGS -L$BREW/opt/$pkg/lib"
done
export CPPFLAGS
export LDFLAGS
version=3.5.2
url="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
name=`basename $url .tar.xz`
tar=`basename $url`
test -e $tar || curl -O $url
test -e $name || tar xf $tar
cd $name
./configure MACOSX_DEPLOYMENT_TARGET=$OSXVERSION --prefix="$PREFIX"
make -j8
make altinstall
unset CPPFLAGS
unset LDFLAGS
ln -sf pip3.5 "$PREFIX/bin/pip"
ln -sf pip3.5 "$PREFIX/bin/pip3"
ln -sf python3.5 "$PREFIX/bin/python3"
PATH="$PREFIX/bin:$PATH"
cd "$BASE"
test -e requirements.txt && pip3.5 install -r requirements.txt
chmod -R +rw "$PREFIX/lib"
# make self contained
for lib in \
opt/libxml2/lib/libxml2.2.dylib \
opt/libxslt/lib/libexslt.0.dylib \
opt/libxslt/lib/libxslt.1.dylib \
opt/openssl/lib/libcrypto.1.0.0.dylib \
opt/openssl/lib/libssl.1.0.0.dylib \
opt/readline/lib/libreadline.6.dylib \
opt/readline/lib/libreadline.6.3.dylib \
opt/sqlite/lib/libsqlite3.0.dylib \
opt/xz/lib/liblzma.5.dylib \
; do
target="$PREFIX/lib/`basename "$lib"`"
rm -f "$target"
cp -a "$BREW/$lib" "$target"
done
chmod -R +rw "$PREFIX/lib"
mkdir -p "$PREFIX/etc/openssl/certs"
cp /usr/local/etc/openssl/cert.pem "$PREFIX/etc/openssl"
# cleanup
rm -rf \
"$PREFIX/lib/python3.5/test" \
"$PREFIX/bin/openssl" \
"$PREFIX/etc/openssl/man" \
"$PREFIX/bin/c_rehash" \
"$PREFIX/bin/2to3-3.5" \
"$PREFIX/bin/easy_install-3.5" \
"$PREFIX/bin/idle3.5" \
"$PREFIX/bin/pyvenv-3.5" \
"$PREFIX/bin/c_rehash" \
"$PREFIX/bin/pydoc3.5"
for bin in $PREFIX/bin/pip3.5 $PREFIX/bin/python3.5m-config; do
sed "s#$PREFIX/bin/python3.5#/usr/bin/env python3.5#g" "$bin" > "$bin.t"
mv "$bin.t" "$bin"
chmod +x "$bin"
done
find "$PREFIX" -d -name "__pycache__" -type d -exec rm -r "{}" \;
find "$PREFIX" -name "*.pyc" -exec rm "{}" \;
find "$PREFIX" -name "*.a" -exec rm -f "{}" \;
for plib in \
$PREFIX/lib/python3.5/site-packages/lxml/etree.cpython-35m-darwin.so \
$PREFIX/lib/python3.5/site-packages/lxml/objectify.cpython-35m-darwin.so \
$PREFIX/lib/python3.5/lib-dynload/_hashlib.cpython-35m-darwin.so \
$PREFIX/lib/python3.5/lib-dynload/_lzma.cpython-35m-darwin.so \
$PREFIX/lib/python3.5/lib-dynload/_sqlite3.cpython-35m-darwin.so \
$PREFIX/lib/python3.5/lib-dynload/_ssl.cpython-35m-darwin.so \
$PREFIX/lib/python3.5/lib-dynload/readline.cpython-35m-darwin.so \
; do
if [ -e "$plib" ]; then
for lib in \
$BREW/Cellar/libxslt/1.1.28_1/lib/libxslt.1.dylib \
$BREW/Cellar/openssl/1.0.2d_1/lib/libcrypto.1.0.0.dylib \
$BREW/opt/libxml2/lib/libxml2.2.dylib \
$BREW/opt/libxslt/lib/libexslt.0.dylib \
$BREW/opt/libxslt/lib/libxslt.1.dylib \
$BREW/opt/openssl/lib/libcrypto.1.0.0.dylib \
$BREW/opt/openssl/lib/libssl.1.0.0.dylib \
$BREW/opt/readline/lib/libreadline.6.dylib \
$BREW/opt/readline/lib/libreadline.6.3.dylib \
$BREW/opt/sqlite/lib/libsqlite3.0.dylib \
$BREW/opt/xz/lib/liblzma.5.dylib \
$PREFIX/lib/libcrypto.1.0.0.dylib \
$PREFIX/lib/libexslt.0.dylib \
$PREFIX/lib/liblzma.5.dylib \
$PREFIX/lib/libreadline.6.dylib \
$PREFIX/lib/libreadline.6.3.dylib \
$PREFIX/lib/libsqlite3.0.dylib \
$PREFIX/lib/libssl.1.0.0.dylib \
$PREFIX/lib/libxml2.2.dylib \
$PREFIX/lib/libxslt.1.dylib \
/usr/lib/libexslt.0.dylib \
/usr/lib/libreadline.6.dylib \
/usr/lib/libreadline.6.3.dylib \
/usr/lib/libxml2.2.dylib \
/usr/lib/libxslt.1.dylib \
; do
name=`basename $lib`
otool -L "$plib" | grep -q "$lib" && install_name_tool -change "$lib" "@executable_path/../lib/$name" "$plib"
done
otool -L "$plib"
fi
done
mkdir -p "${NAME}.app/Contents/MacOS"
mv $PREFIX "${NAME}.app/Contents/Python"
cat > "$NAME.app/Contents/MacOS/$NAME" << EOF
#!/bin/bash
cd "\$(dirname "\$0")"
PREFIX="\$(dirname "\$(pwd)")/Python"
export SSL_CERT_FILE="\$PREFIX/etc/openssl/cert.pem"
export SSL_CERT_DIR="\$PREFIX/etc/openssl/certs"
"\$PREFIX/bin/python3.5" -m $APPLICATION
EOF
chmod +x "$NAME.app/Contents/MacOS/$NAME"
test -e Resources && cp -r Resources "${NAME}.app/Contents/Resources"
cat > "$NAME.app/Contents/Info.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>15C50</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${NAME}</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>CFBundleIdentifier</key>
<string>${IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTPlatformBuild</key>
<string>7C68</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>15C43</string>
<key>DTSDKName</key>
<string>macosx10.10</string>
<key>DTXcode</key>
<string>0720</string>
<key>DTXcodeBuild</key>
<string>7C68</string>
<key>LSMinimumSystemVersion</key>
<string>${OSXVERSION}</string>
<key>LSUIElement</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>No Copyright</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
EOF
test -e test.py && "${NAME}.app/Contents/Python/bin/python3.5" test.py
find "${NAME}.app" -d -name "__pycache__" -type d -exec rm -r "{}" \;
find "${NAME}.app" -name "*.pyc" -exec rm "{}" \;
mkdir dmg
ln -s /Applications "dmg/Applications"
mv "${NAME}.app" dmg/
hdiutil create -srcfolder "dmg" -volname "${NAME}" -format UDZO "${NAME}.tmp.dmg"
hdiutil convert -format UDZO -imagekey zlib-level=9 -o "${NAME}.dmg" "${NAME}.tmp.dmg"
rm "${NAME}.tmp.dmg"