Bundle-python

Version 2 (Saúl Ibarra Corretgé, 05/27/2013 02:12 pm)

1 1 Saúl Ibarra Corretgé
h1. Building a Python Framework to bundle inside Blink
2 1 Saúl Ibarra Corretgé
3 1 Saúl Ibarra Corretgé
In order to avoid using the system Python a custom Framework build is needed. Using a bundled Python version will make the package bigger in size, but all package versions are controlled and not up to the environment. Also, we can use the latest Python version, with latest bugfixes and features, since Apple only updates the system Python version on every major OS release.
4 1 Saúl Ibarra Corretgé
5 1 Saúl Ibarra Corretgé
h2. Building the Python Framework itself
6 1 Saúl Ibarra Corretgé
7 1 Saúl Ibarra Corretgé
* Download the desired Python version, at the time of this writing, 2.7.5
8 1 Saúl Ibarra Corretgé
9 1 Saúl Ibarra Corretgé
<pre>
10 1 Saúl Ibarra Corretgé
wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
11 1 Saúl Ibarra Corretgé
</pre>
12 1 Saúl Ibarra Corretgé
13 1 Saúl Ibarra Corretgé
* Uncompress and get ready to compile
14 1 Saúl Ibarra Corretgé
15 1 Saúl Ibarra Corretgé
<pre>
16 1 Saúl Ibarra Corretgé
tar jxvf Python-2.7.5.tar.bz2
17 1 Saúl Ibarra Corretgé
cd Python-2.7.5
18 1 Saúl Ibarra Corretgé
</pre>
19 1 Saúl Ibarra Corretgé
20 1 Saúl Ibarra Corretgé
* Create a temporary directory for the build result
21 1 Saúl Ibarra Corretgé
22 1 Saúl Ibarra Corretgé
<pre>
23 1 Saúl Ibarra Corretgé
mkdir -p /tmp/py
24 1 Saúl Ibarra Corretgé
</pre>
25 1 Saúl Ibarra Corretgé
26 1 Saúl Ibarra Corretgé
* Compile Python (Framework build) in 32 bits mode and with compatibility for OSX >= 10.6
27 1 Saúl Ibarra Corretgé
28 1 Saúl Ibarra Corretgé
<pre>
29 1 Saúl Ibarra Corretgé
./configure --prefix=/tmp/py --enable-framework=/tmp/py MACOSX_DEPLOYMENT_TARGET=10.6 ARCHFLAGS="-arch i386" CFLAGS="-arch i386" CXXFLAGS="-arch i386" LDFLAGS="-arch i386"
30 1 Saúl Ibarra Corretgé
make
31 1 Saúl Ibarra Corretgé
make install
32 1 Saúl Ibarra Corretgé
</pre>
33 1 Saúl Ibarra Corretgé
34 1 Saúl Ibarra Corretgé
The resulting framework will be located in /tmp/py
35 1 Saúl Ibarra Corretgé
36 1 Saúl Ibarra Corretgé
* Change the dynamic link target in the main binary file of the Python Framework
37 1 Saúl Ibarra Corretgé
38 1 Saúl Ibarra Corretgé
<pre>
39 1 Saúl Ibarra Corretgé
cd /tmp/py/Python.framework/Versions/2.7
40 1 Saúl Ibarra Corretgé
chmod +w Python
41 1 Saúl Ibarra Corretgé
install_name_tool -id @executable_path/../Frameworks/Python.framework/Versions/2.7/Python Python
42 1 Saúl Ibarra Corretgé
chmod -w Python
43 1 Saúl Ibarra Corretgé
</pre>
44 1 Saúl Ibarra Corretgé
45 1 Saúl Ibarra Corretgé
The framework is now ready for inclusion on the project.
46 1 Saúl Ibarra Corretgé
47 2 Saúl Ibarra Corretgé
*NOTE*: Be careful when copying the framework around, it contains symlinks and if @cp -r@ is used the size will we doubled, use @cp -RH@ instead.
48 2 Saúl Ibarra Corretgé
49 1 Saúl Ibarra Corretgé
50 1 Saúl Ibarra Corretgé
* Reduce the size of the Python Framework:
51 1 Saúl Ibarra Corretgé
52 1 Saúl Ibarra Corretgé
TODO