Deeply embedded Python still alive?

trevor t_list at vtnet.ca
Thu Apr 4 10:22:10 EST 2002


in the following i assume you're using gcc-3.0.4. i also assume you're 
using uClibc-0.9.10, that you've setup your install to be put at 
/usr/local/device/ and that you're building your target filesystem at 
/home/me/device (if you look at uClibc you'll know what i'm talking about 
if this isn't clear right now).

[uClibc-0.9.10]
in uClibc's configuration file i've set:
        KERNEL_SOURCE
        DO_C99_MATH = true [not sure if needed or not]
        HAS_LONG_LONG = true
        DOLFS = true [this one is important]
        INCLUDE_THREADS = true
        turned on the shared stuff
        DEVEL_PREFIX = /usr/local/device/$(TARGET_ARCH)-linux-uclibc
# make
# make install
# make PREFIX=/home/me/device install_target

[python-2.2]
unpack python-2.2 somewhere, create a build directory. cd into that build 
directory.
# PATH=/usr/local/device/i386-linux-uclibc/bin:$PATH
# export PATH
# ../path/to/python/source/configure --prefix=/some/where/else
edit pyconfig.h:
        - change "#define LARGEFILESUPPORT 1" -> 0
        - change "#define _FILE_OFFSET_BITS 64" -> 32
edit Modules/Setup
        - uncomment "_socket socketmodule.c" to compile socket w/o SSL
edit source code: Modules/getaddrinfo.c:
*** start of diff ***
diff -urN Python-2.2/Modules/getaddrinfo.c 
SmallPython-2.2/Modules/getaddrinfo.c
--- Python-2.2/Modules/getaddrinfo.c    Sun Dec  2 05:15:37 2001
+++ SmallPython-2.2/Modules/getaddrinfo.c       Wed Apr  3 13:28:18 2002
@@ -198,7 +198,7 @@
 
 #define ERR(err) { error = (err); goto bad; }
 
-char *
+const char *
 gai_strerror(ecode)
        int ecode;
 {
*** end of diff ***
edit Makefile
        search for LIBSUBDIRS string at start of line
        i removed the test* and tk* directories
# make
# make install

you'll notice that some of the modules won't build and other that will 
build will be discarded since they can't be loaded. if you wanted the expat 
module to build (for xml stuff) for example, you'll need to download and 
install (--prefix=/usr/local/device/i386-linux-uclibc) expat-1.95.2.

now you need to go into where you're creating your target device's 
filesystem and re-create the python directories (i.e. 
/home/me/device/some/where/else) you need to re-create this file layout 
since the python executable will look for it when it tries to load modules 
(i don't know how to change this behaviour).

starting at /home/me/device/some/where/else create "bin" and "lib" 
directories. put the python executable into "bin" and create a "python2.2" 
directory in "lib".

you'll notice that the /some/where/else/lib (the place you installed your 
complete python build to) directory is massive. you don't need to copy all 
the modules found there to your target device's filesystem, only the ones 
you need. through experimentation i've discovered that the following 
minimum are required to be able to run the interpreter and do some basic 
stuff. the following are put into the $TARGET/some/where/else/lib/python2.2 
directory:
        create a directory called lib-dynload
        os.py
        UserDict.py
        posixpath.py
        site.py
        stat.py

note that i'm only copying the *.py files. this was done to save disk space 
since on average the *.py files are smaller than the *.pyc or *.pyo files. 
however, the first time these files are opened, python will convert them 
into *.pyc files giving you a really slow first-time startup time. in this 
environment disk space is really tight (4MB). the *.pyc files will be 
created in the RAM filesystem and will live there until the next reboot. if 
you can spare the space then you only need to copy the *.pyc files to the 
above modules.

as you write programs that require different modules you'll need to include 
them. starting python with the "-v" option will tell you which ones you're 
missing.

hope this helps. best regards,
        trevor
-- 
remove underscore if you want to email me



More information about the Python-list mailing list