<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RandomSplat &#187; PowerPC</title>
	<atom:link href="http://randomsplat.com/idcategory/powerpc/feed" rel="self" type="application/rss+xml" />
	<link>http://randomsplat.com</link>
	<description>Software Commentary</description>
	<lastBuildDate>Sat, 21 Jan 2012 12:26:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Cross Compiling Python for Embedded Linux</title>
		<link>http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html</link>
		<comments>http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html#comments</comments>
		<pubDate>Wed, 16 Nov 2011 04:48:14 +0000</pubDate>
		<dc:creator>Paul Gibson</dc:creator>
				<category><![CDATA[arm]]></category>
		<category><![CDATA[Cross-Compiling]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PowerPC]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Embedded]]></category>

		<guid isPermaLink="false">http://randomsplat.com/?p=5</guid>
		<description><![CDATA[This article details how to cross compile Python for the ARM and PowerPC platforms.  It should apply equally to other platforms just plug in the correct cross-compiler.  The article supports Python versions 2.6.6, 2.7.2 and 3.1.1, 3.1.2, 3.1.3, 3.2.2.]]></description>
			<content:encoded><![CDATA[<p>This article details how to cross compile Python for the ARM and PowerPC platforms.  It should apply equally to other platforms as well, just plug-in the correct cross-compiler.  The article supports Python versions, 2.6.6 (Thanks to evadeflow), 2.7.2 and 3.1.1, 3.1.2, 3.1.3, 3.2.2.<span id="more-5"></span></p>
<p>Firstly, download the Python that you want to use from <a href="http://www.python.org">http://www.python.org/</a></p>
<p>Unpack the Python package using tar:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span> Python-2.7.2.tgz</div></div>
<p>This will create a directory called Python-2.7.2.  Goto the directory:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> Python-2.7.2</div></div>
<p>Then run these commands to build the host components:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color: #000000; font-weight: bold;">/</span>configure<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> python Parser<span style="color: #000000; font-weight: bold;">/</span>pgen<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">mv</span> python hostpython<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">mv</span> Parser<span style="color: #000000; font-weight: bold;">/</span>pgen Parser<span style="color: #000000; font-weight: bold;">/</span>hostpgen<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> distclean</div></div>
<p>Download the correct patch for your version of Python:</p>
<ul>
<li><a href="../wp-content/uploads/2010/10/Python-2.6.6-xcompile.patch">Python-2.6.6-xcompile.patch</a></li>
<li><a href="http://randomsplat.com/wp-content/uploads/2011/10/Python-2.7.2-xcompile.patch">Python-2.7.2-xcompile.patch</a> (With ctypes thanks to Jaux (<a title="http://jaux.net" href="http://jaux.net/">jaux.net</a>)</li>
<li><a href="http://randomsplat.com/wp-content/uploads/2009/08/Python-3.1.1-xcompile.patch">Python-3.1.1-xcompile.patch</a></li>
<li><a href="../wp-content/uploads/2010/04/Python-3.1.2-xcompile.patch">Python-3.1.2-xcompile.patch</a></li>
<li><a href="../wp-content/uploads/2011/01/Python-3.1.3-xcompile.patch">Python-3.1.3-xcompile.patch</a></li>
<li><a href="http://randomsplat.com/wp-content/uploads/2011/10/Python-3.2.2-xcompile.patch">Python-3.2.2-xcompile.patch</a></li>
</ul>
<p>Then apply the patch:</p>
<p><code class="codecolorer text blackboard"><span class="text">patch -p1 &lt; Python-2.7.2-xcompile.patch</span></code></p>
<p>Then run this (where ~/Python-2.7.2/_install/ is your desired installation path).  Note also that you must replace all instances of the cross compiler and the host build system in the lines below.  If you are on an x86_64 machine, then you should use x86_64-linux-gnu as the host.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">CC</span>=ppc_6xx-gcc <span style="color: #007800;">CXX</span>=ppc_6xx-g++ <span style="color: #007800;">AR</span>=ppc_6xx-ar <span style="color: #007800;">RANLIB</span>=ppc_6xx-ranlib .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--host</span>=ppc-linux <span style="color: #660033;">--build</span>=x86_64-linux-gnu <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>python<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #007800;">HOSTPYTHON</span>=.<span style="color: #000000; font-weight: bold;">/</span>hostpython <span style="color: #007800;">HOSTPGEN</span>=.<span style="color: #000000; font-weight: bold;">/</span>Parser<span style="color: #000000; font-weight: bold;">/</span>hostpgen <span style="color: #007800;">BLDSHARED</span>=<span style="color: #ff0000;">&quot;ppc_6xx-gcc -shared&quot;</span> <span style="color: #007800;">CROSS_COMPILE</span>=ppc_6xx- <span style="color: #007800;">CROSS_COMPILE_TARGET</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span> <span style="color: #007800;">HOSTARCH</span>=ppc-linux <span style="color: #007800;">BUILDARCH</span>=x86_64-linux-gnu<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #007800;">HOSTPYTHON</span>=.<span style="color: #000000; font-weight: bold;">/</span>hostpython <span style="color: #007800;">BLDSHARED</span>=<span style="color: #ff0000;">&quot;ppc_6xx-gcc -shared&quot;</span> <span style="color: #007800;">CROSS_COMPILE</span>=ppc_6xx- <span style="color: #007800;">CROSS_COMPILE_TARGET</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span> <span style="color: #007800;">prefix</span>=~<span style="color: #000000; font-weight: bold;">/</span>Python-2.7.2<span style="color: #000000; font-weight: bold;">/</span>_install</div></div>
<p>This will install all your python binaries and libraries in ~/Python-2.7.2/_install.</p>
<p>Copy the entire _install directory to the device, setup the PATH environment variable to include the path the Python executable and run:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">python lib<span style="color: #000000; font-weight: bold;">/</span>Python-<span style="color: #000000;">2.7</span><span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span>test___all___.py</div></div>
<p>&#8230;and hopefully all the tests will run correctly.</p>
<p>To speed up the importing of Python modules on the target, I recommend to zip up the lib directory to make a file called python27.zip.  This means that we do not have to copy all the Python files to the target, just the one zip file.  This technique might also save space, but that depends on your file system.  On the host machine:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> _install<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>python2.7<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">zip</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">-y</span> python27.zip .</div></div>
<p>Delete libpythonxxx.a site-packages, lib-dynload, config and anything else you do not need from the python27.zip file.</p>
<p>Copy the _install/bin/python to the /usr/bin directory on the target:</p>
<p>Copy the python27.zip file to the /usr/lib directory on the target:</p>
<p>Create a directory on the target called python2.7 in the /usr/lib directory and copy the following directories to that directory:</p>
<ul>
<li>./lib/python2.7/config</li>
<li>./lib/python2.7/lib-dynload</li>
<li>./lib/python2.7/site-packages</li>
</ul>
<p>Your directory structure on the target must be as follows:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib <span style="color: #666666; font-style: italic;"># ls</span><br />
<br />
python2.7 python27.zip<br />
<br />
<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>python2.7 <span style="color: #666666; font-style: italic;"># ls</span><br />
<br />
config lib-dynload site-packages</div></div>
<p>Set the PYTHONHOME environment variable to /usr/ and you are ready to run Python on the target.</p>
<p>The above patches are based on Chris Lambacher&#8217;s patches for Python 2.5 here:</p>
<p><a href="http://whatschrisdoing.com/blog/2006/10/06/howto-cross-compile-python-25/">http://whatschrisdoing.com/blog/2006/10/06/howto-cross-compile-python-25/</a></p>
<p>Other links and credits:</p>
<p><a href="http://www.ailis.de/~k/archives/19-ARM-cross-compiling-howto.html">http://www.ailis.de/~k/archives/19-ARM-cross-compiling-howto.html</a></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 570px; width: 1px; height: 1px;"><a href="http://randomsplat.com/wp-content/uploads/2009/08/Python-2.6.2-xcompile.patch">Python-2.6.2-xcompile.patch</a></div>
]]></content:encoded>
			<wfw:commentRss>http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html/feed</wfw:commentRss>
		<slash:comments>76</slash:comments>
		</item>
	</channel>
</rss>

