Aha, the big question.
So far I only have loose notes, but basically it comes down to the
instructions below.
I used SWIG (
http://www.swig.org/) to build the DLL of the Python module.
My setup had Python 2.4 installed in C:\Prog\Python24. Of course the
required C dependancies where also already met on my system (including
libxen).
I have quite some experience in porting *nix stuff to Windows/win32
using MinGW/MSYS, but Python was new to me.
Nevertheless it took my days (well, nights mostly) to get this result,
but the instructions below aren't too long. So I believe it shouldn't
require that many changes to sources and autoconf/automake stuff to
incorporate the MinGW/MSYS port.
I'm afraid there is still some work ahead meeting all the Python
dependancies. If we're lucky they will exist for Windows. Otherwise they
will need porting too (hopefully easier than libvirt).
Here goes:
wget -c
http://downloads.sourceforge.net/swig/swigwin-1.3.33.zip
unzip -oqj swigwin-1.3.33.zip -d /C/Prog/Python24 swigwin-1.3.33/swig.exe
wget -c
http://libvirt.org/sources/libvirt-cvs-snapshot.tar.gz
tar xfz libvirt-cvs-snapshot.tar.gz
cd libvirt-0.4.0
mkdir linux
touch linux/param.h
mv src/internal.h src/internal.h.bak
echo "#include <pthread.h>" > src/internal.h
sed -e 's/^\(#define VIR_DEBUG(.*) *\)$/\1 \\/' src/internal.h.bak >>
src/internal.h
mv qemud/remote_protocol.c qemud/remote_protocol.c.bak
echo "#include <winsock2.h>" > qemud/remote_protocol.c
cat qemud/remote_protocol.c.bak >> qemud/remote_protocol.c
mv configure configure.bak
sed -e "s?/include/python\${PYTHON_VERSION}?/include?;
s?/lib/python\${PYTHON_VERSION}/site-packages?$/Lib/site-packages?;
s?-lpython\\\${PYTHON_VERSION}?-lpython\`echo \\\$PYTHON_VERSION|sed -e
's/\\\.//'\`?" configure.bak > configure
./configure --prefix=$INSTALLPREFIX --disable-rpath --enable-debug=no
--enable-compile-warnings=minimum --with-xen --without-xen-proxy
--without-qemu --without-openvz --without-test --without-libvirtd
--without-remote --with-init-scripts=none --with-depends --without-sasl
--without-polkit --with-python=/C/Prog/Python24/python.exe
PYTHON=/C/Prog/Python24/python.exe
PYTHON_INCLUDES="/C/Prog/Python24/include" CFLAGS="-Drestrict=__restrict
-DWSAAPI=" LDFLAGS="-no-undefined -lportablexdr -lwsock32 -lintl"
# don't build tests
mv tests/Makefile tests/Makefile.bak
cat > tests/Makefile << EOF
all:
install:
EOF
make install
cd python
mv Makefile Makefile.bak
sed -e "s?^\(PYTHON_INCLUDES *= *.*\)?\1/C/Prog/Python24/include?;
s?^\(PYTHON_SITE_PACKAGES *=
*.*\)?\1/C/Prog/Python24/Lib/site-packages?" Makefile.bak > Makefile
/C/Prog/Python24/python.exe generator.py
make libvirtmod_la-libvir.lo libvirtmod_la-types.lo
libvirtmod_la-libvirt-py.lo
# use SWIG to create Python wrapper
cat > libvirtmod.i << EOF
%module libvirtmod
%{
#include "../include/libvirt/libvirt.h"
%}
EOF
sed -e "s/^\(.*libvirt.*\)$/extern \1/" libvirt-py.h >> libvirtmod.i
../../swigwin-1.3.33/swig -python -I../../swigwin-1.3.33/Lib
-I../../swigwin-1.3.33/Lib/python/ libvirtmod.i
gcc -shared libvirtmod_wrap.c libvirtmod_la-libvir.o
libvirtmod_la-types.o libvirtmod_la-libvirt-py.o -lportablexdr -lws2_32
-I/C/Prog/Python24/include -L/C/Prog/Python24/libs -lpython24
-L../src/.libs/ -lvirt -Wl,--export-all-symbols -o _libvirtmod.dll
# test it
/C/Prog/Python24/python.exe -c "import libvirt"
cp libvirt.py libvirtmod.py _libvirtmod.dll
/C/Prog/Python24/Lib/site-packages
Richard W.M. Jones wrote:
Brecht Sanders wrote:
> Hi Richard,
> I have finally compiled a libvirt Python module.
> Attached are the files that need to go into <python 2.4
> home>lib/site-packages, in case you want to try this.
How did you build _libvirtmod though?
Rich.