Compiling Python: Modules/Setup

A little hint for Python developers who use it for embedded or unconventional platforms (like Cray supercomputers if you're lucky): it can be compiled and used without any dynamic libraries. I've got the problem with stripped - some Python shared object (like try to use it, but can't find anything because it's stripped. The only choice I had is using Python without these shared objects.

Fortunately, Python support it out of the box. After configuring it, you can use Modules/Setup file to set up which modules have to be compiled within the Python binary:
The build process works like this:
 1. Build all modules that are declared as static in Modules/Setup,
    combine them into libpythonxy.a, combine that into python.
 2. Build all modules that are listed as shared in Modules/Setup.
 3. Invoke That builds all modules that
    a) are not builtin, and
    b) are not listed in Modules/Setup, and
    c) can be build on the target
For example, if you want to embed _socket module to the Python binary, just uncomment this line in the Setup file:

#_socket socketmodule.c

After recompiling you'll get that you want. Feel the power of Python portability :-)

In the near future I'll give an update about another techniques for tuning up the Python installation (like stripping and packing the binary, using standard libraries as zip-archive of pyc-files). Keep in touch.


Popular posts from this blog

DIY: Business cards in LaTeX

Python vs JS vs PHP for embedded systems

Shellcode detection using libemu