<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>RandomSplat</title>
	
	<link>http://randomsplat.com</link>
	<description>Software Commentary</description>
	<lastBuildDate>Mon, 05 Apr 2010 14:30:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Randomsplatcom" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="randomsplatcom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><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>Mon, 05 Apr 2010 14:17:14 +0000</pubDate>
		<dc:creator>Paul Gibson</dc:creator>
				<category><![CDATA[Cross-Compiling]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PowerPC]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://randomsplat.com/?p=5</guid>
		<description><![CDATA[This article details how to cross compile Python for the PowerPC platform.  It should apply equally to other platforms such as ARM, just plug in the correct cross-compiler.  The article supports Python versions 2.6.1, 2.6.2, 2.6.3, 2.6.4, 2.6.5 and 3.1.1, 3.1.2


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This article details how to cross compile  Python for the PowerPC platform.  It should apply equally to other platforms such as ARM, just plug in the correct cross-compiler.  The article supports Python versions, 2.6.1, 2.6.2, 2.6.3, 2.6.4, 2.6.5 and 3.1.1, 3.1.2.</p>
<p>Firstly, download the version of Python that you want to use from <a href="http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz">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;width:575px;"><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.6.5.tgz</div></div>
<p>This will create a directory called Python-2.6.5.  Goto the directory:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:575px;"><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.6.5</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;width:575px;"><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="http://randomsplat.com/wp-content/uploads/2009/08/Python-2.6.1-xcompile.patch">Python-2.6.1-xcompile.patch</a></li>
<li><a href="http://randomsplat.com/wp-content/uploads/2009/08/Python-2.6.2-xcompile.patch">Python-2.6.2-xcompile.patch</a></li>
<li><a href="../wp-content/uploads/2009/10/Python-2.6.3-xcompile.patch">Python-2.6.3-xcompile.patch</a></li>
<li><a href="../wp-content/uploads/2009/12/Python-2.6.4-xcompile.patch">Python-2.6.4-xcompile.patch</a></li>
<li><a href="../wp-content/uploads/2010/04/Python-2.6.5-xcompile.patch">Python-2.6.5-xcompile.patch</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>
</ul>
<p>Then apply the patch:</p>
<p><code class="codecolorer text blackboard"><span class="text">patch -p1 &lt; Python-2.6.5-xcompile.patch</span></code></p>
<p>Then run this (where ~/Python-2.6.5/_install/ is your desired installation path)</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:575px;"><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>=i686-pc-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-linux-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><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> &nbsp;<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-linux-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.6.5<span style="color: #000000; font-weight: bold;">/</span>_install</div></div>
<p>This will install all your python binaries and libraries in ~/Python-2.6.5/_install.</p>
<p>Copy the entire _install directory to the device, setup the PATH environment variable to include the location of the Python executable and run:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:575px;"><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.6</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, it is recommended to zip up the lib directory to make a file called python26.zip.  This means that we do not have to copy all the individual 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;width:575px;"><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.6<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">zip</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">-y</span> python26.zip .</div></div>
<p>Delete libpythonxxx.a site-packages, lib-dynload, config and anything else you do not require from the python26.zip file.</p>
<p>Copy the _install/bin/python to the /usr/bin directory on the target:</p>
<p>Copy the python26.zip file to the /usr/lib directory on the target:</p>
<p>Create a directory on the target called python2.6 in the /usr/lib directory and copy the following directories to that directory:</p>
<ul>
<li>./lib/python2.6/config</li>
<li>./lib/python2.6/lib-dynload</li>
<li>./lib/python2.6/site-packages</li>
</ul>
<p>Your directory structure on the target should be as follows:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:575px;"><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.6 &nbsp;python26.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.6 <span style="color: #666666; font-style: italic;"># ls</span><br />
<br />
config &nbsp;lib-dynload &nbsp;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>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
