mozilla

Revision 121882 of Building PyXPCOM

  • Revision slug: Building_PyXPCOM
  • Revision title: Building PyXPCOM
  • Revision id: 121882
  • Created:
  • Creator: Ronan
  • Is current revision? No
  • Comment /* Compiling Mozilla */

Revision Content

Installing Python

PyXPCOM requires access to a shared Python library. The official Python installer for Windows installs this library automatically, so Windows users can simply install Python and skip to Compiling Mozilla.

For non-Windows users, if you already have Python installed and you have the file libpython2.*.so.* in /usr/lib/python2.*/config, you meet the shared library requirement and can skip to the Compiling Mozilla section. If you have that file but it's located in /usr/lib (or whatever your system's library path is) instead, then create the proper symlink to the library as instructed below for Gentoo systems. If you don't have that file at all then you'll need to compile Python with --enable-shared as outlined in this section.

Gentoo systems

Python 2.2 and earlier

A shared Python library seems to only be possible with python-2.3* or later, so you'll need to upgrade if you're using python-2.2* or earlier.


Python 2.3 and later

If your installed Python ebuild is python-2.3* or later then the shared library was already built by default.


Symlinking to the shared library

As of this writing even the latest Python ebuilds fail to properly symlink to the shared library, so if for instance you're using python-2.4.2 then you'll need to create the symlink manually:

ln -s /usr/lib/libpython2.4.so /usr/lib/python2.4/config/libpython2.4.so

Other systems

If you don't use Windows or Gentoo, get the latest stable Python source tarball from python.org and do:

tar xjf Python-2.4.2.tar.bz2
cd Python-2.4.2
./configure --enable-shared --prefix=/usr  # Adjust --prefix to install over your current Python
make
sudo make install


Compiling Mozilla

Check out Mozilla from DOM_AGNOSTIC2_BRANCH in CVS and build it:

cvs -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot co -r DOM_AGNOSTIC2_BRANCH mozilla/client.mk
cd mozilla
make -f client.mk checkout MOZ_CO_PROJECT=suite
cat > .mozconfig << "EOF"
mk_add_options MOZ_CO_PROJECT=suite
ac_add_options --enable-application=suite
ac_add_options --enable-default-toolkit=gtk2
ac_add_options --enable-xft
ac_add_options --enable-extensions=python/xpcom,python/dom,default
ac_add_options --disable-optimize
ac_add_options --enable-debug
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/suite-debug
EOF
autoconf
make -f client.mk build

Testing PyXPCOM

To test your fresh PyXPCOM build from within Mozilla's runtime environment:

cd suite-debug/dist/bin
export PYTHONPATH=$PYTHONPATH:$HOME/mozilla/suite-debug/dist/bin/python # Adjust this to your PyXPCOM build path
./run-mozilla.sh ./seamonkey -chrome chrome://pyxultest/content

In the same directory, perform this simple test of the Python XPCOM module from a standalone Python environment:

python -c 'from xpcom import components; print components.classes["@mozilla.org/file/local;1"]'

If this standalone test fails, make sure $PYTHONPATH is still set the same as in the first test.

Revision Source

<h3 name="Installing_Python"> Installing Python </h3>
<p>PyXPCOM requires access to a shared Python library. The official Python installer for Windows installs this library automatically, so Windows users can simply install Python and skip to <a href="en/Building_PyXPCOM#Compiling_Mozilla">Compiling Mozilla</a>.
</p><p>For non-Windows users, if you already have Python installed and you have the file <code>libpython2.*.so.*</code> in <code>/usr/lib/python2.*/config</code>, you meet the shared library requirement and can skip to the <a href="en/Building_PyXPCOM#Compiling_Mozilla">Compiling Mozilla</a> section. If you have that file but it's located in <code>/usr/lib</code> (or whatever your system's library path is) instead, then create the proper symlink to the library as instructed below for Gentoo systems. If you don't have that file at all then you'll need to compile Python with <code>--enable-shared</code> as outlined in this section.
</p>
<h4 name="Gentoo_systems"> Gentoo systems </h4>
<p><b> Python 2.2 and earlier </b>
</p><p>A shared Python library seems to only be possible with <code>python-2.3*</code> or later, so you'll need to upgrade if you're using <code>python-2.2*</code> or earlier.
</p><p><br>
<b> Python 2.3 and later </b>
</p><p>If your installed Python ebuild is <code>python-2.3*</code> or later then the shared library was already built by default.
</p><p><br>
<b> Symlinking to the shared library </b>
</p><p>As of this writing even the latest Python ebuilds fail to properly symlink to the shared library, so if for instance you're using <code>python-2.4.2</code> then you'll need to create the symlink manually:
</p>
<pre>ln -s /usr/lib/libpython2.4.so /usr/lib/python2.4/config/libpython2.4.so
</pre>
<h4 name="Other_systems"> Other systems </h4>
<p>If you <i>don't</i> use Windows or Gentoo, get the latest stable Python source tarball from <a class="external" href="http://python.org/download/">python.org</a> and do:
</p>
<pre>tar xjf Python-2.4.2.tar.bz2
cd Python-2.4.2
./configure --enable-shared --prefix=/usr  # Adjust --prefix to install over your current Python
make
sudo make install
</pre>
<p><br>
</p>
<h3 name="Compiling_Mozilla"> Compiling Mozilla </h3>
<p>Check out Mozilla from <a class="external" href="http://wiki.mozilla.org/Breaking_the_grip_JS_has_on_the_DOM">DOM_AGNOSTIC2_BRANCH</a> in CVS and build it:
</p>
<pre>cvs -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot co -r DOM_AGNOSTIC2_BRANCH mozilla/client.mk
cd mozilla
make -f client.mk checkout MOZ_CO_PROJECT=suite
cat &gt; .mozconfig &lt;&lt; "EOF"
mk_add_options MOZ_CO_PROJECT=suite
ac_add_options --enable-application=suite
ac_add_options --enable-default-toolkit=gtk2
ac_add_options --enable-xft
ac_add_options --enable-extensions=python/xpcom,python/dom,default
ac_add_options --disable-optimize
ac_add_options --enable-debug
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/suite-debug
EOF
autoconf
make -f client.mk build
</pre>
<h3 name="Testing_PyXPCOM"> Testing PyXPCOM </h3>
<p>To test your fresh PyXPCOM build from within Mozilla's runtime environment:
</p>
<pre>cd suite-debug/dist/bin
export PYTHONPATH=$PYTHONPATH:$HOME/mozilla/suite-debug/dist/bin/python # Adjust this to your PyXPCOM build path
./run-mozilla.sh ./seamonkey -chrome chrome://pyxultest/content
</pre>
<p>In the same directory, perform this simple test of the Python XPCOM module from a standalone Python environment:
</p>
<pre>python -c 'from xpcom import components; print components.classes["@mozilla.org/file/local;1"]'
</pre>
<p>If this standalone test fails, make sure <code>$PYTHONPATH</code> is still set the same as in the first test.
</p>
Revert to this revision