# dbus-python Build Instructions for Windows (x86) with MinGW ## Revision history r0.0.20120706 - First draft ## Overview These are instructions for building dbus-python [1], a binding to dbus [2] on a MS-Windows x86 system using MinGW [3]. ## Set up MinGW build environment 1. Download and install most recent version of mingw-get-inst [4] from sf.net, current version is 20120426. This only needs to be done once because afterwards you can just run ... $ mingw-get update $ mingw-get install mingw-get ... to get the latest version. During the install, which is an Inno-Setup GUI, select the option to install the "C compiler" and "MSYS Basic System" but leave other default install options. It should install MinGW in `C:\mingw` and MSYS in `C:\mingw\msys\1.0`. It doesn't change your path or add any environmental variables, but it does add a shortcut to the MSYS bash shell on your desktop and start menu, adn register mingw-get-inst so you can unistall it later. There is lots of rich material on MinGW and MSYS on the internet. Also take a look at Configuring and Using mingw-get [5]. 2. Start the MSYS shell, from the start menu, and install (or update) the developers toolkit. If you need to upgrade a component, use `mingw-get upgrade `. $ mingw-get update $ mingw-get install gcc $ mingw-get install g++ $ mingw-get install msys-make $ mingw-get install mingw32-make $ mingw-get install mingw-developer-toolkit 3. While still in the MSYS shell, install expat. $ mingw-get install expat $ mingw-get install libexpat $ mingw-get install msys-expat $ mingw-get install msys-libexpat 4. You also need libz and zlib. $ mingw-get install libz $ mingw-get install zlib $ mingw-get install msys-zlib ## Python Download and install the Python with the Python Windows Installer [6]. ## PyGTK or GTK+ 1. Download and install either the PyGTK all-in-one installer [7] for your Python version (e.g. 2.7) or the GTK-2.0 all-in-one installer [8]. If you're determined to build GLib from source see this post on Bootstrapping GLIB with MinGW [9]. 2. Make a GTK bash shell environment, by copying the MSYS/MinGW shell icon on the desktop (or making a shortcut to `c:\mingw\msys\1.0\msys.bat`) , right-click and select properties and editing the target to be `C:\WINDOWS\system32\cmd.exe /C ""C:\Python27\Lib\site-packages\gtk-2.0\runtime\bin\setenv.cmd"&&"C:\MinGW\msys\1.0\msys.bat"` and renaming it to GTK MinGW shell. If the icon gets screwed up, select properties again, Change Icon and point it to the same location as the original MSYS/MinGW shell shortcut's icon path. **Note you will still have to point `PKG_CONFIG` to the GTK runtime `pkgconfig.exe` and add `/usr/local/lib/pkgconfig` to your `PKG_CONFIG_PATH` in your `./configure` commands, but This will add all of the GTK and PKG_CONFIG paths and environmental variables you'll need, especially for dbus-glib. An alternative is to simply add the GTK runtime to the path of your bash shell. The library libgio-2.0-0.dll is used by dbus-glib during installation. $ export GTK_BASEPATH="/c/Python27/Lib/site-packages/gtk-2.0/runtime/" $ export PATH=$GTK_BASEPATH/bin:$PATH Another alternative is to start the PyGTK/GTK Command Prompt which executes setenv.cmd, creating several environmental variables in that shell such as PYTHON_PKGCONFIG, RUNTIME_PKGCONFIG, PKG_CONFIG_PATH and RUNTIME_BIN, thereby makeing sure that your GTK environment is correctly configured. Then type `c:\mingw\msys\1.0\msys.bat` to start an MSYS/MinGW shell which will also set up your MinGW/MSYS environment. _Note: you may have already added GTK to your path during installation, depending on what options you selected._ ## Build DBus 1. Download the tarball [10] or clone the git repository [2] a folder in `C:\`, e.g. `C:\DBus`. 2. Apply the MemoryBarrier macro patch. The location of this patch is debatable, and there have been some mailing list posts, tickets, forks and suggeted patches [11-18]. I applied it to `dbus\dbus-sysdeps-win.c` which is where the macro is used. I have no idea whether this works as intended, or even what the intent was, so use it at your own risk. The other options are to get rid of the MemoryBarrier() call or use a different compiler such as MSVC or MinGW-w64 [19]. --- a/dbus-1.6.0\dbus\dbus-sysdeps-win.c +++ b/dbus-1.6.0\dbus\dbus-sysdeps-win.c @@ -54,6 +54,13 @@ #include #include #include + +__CRT_INLINE VOID MemoryBarrier(VOID) +{ + LONG Barrier = 0; + __asm__ __volatile__("xchgl %%eax,%0 " + :"=r" (Barrier)); +} /* Declarations missing in mingw's headers */ extern BOOL WINAPI ConvertStringSidToSidA (LPCSTR StringSid, PSID *Sid); 3. configure, make and install $ ./configure PKG_CONFIG=/c/Python27/Lib/site-packages/gtk-2.0/runtime/bin/pkg-config.exe PYTHON=/c/Python27/python $ make $ make install 4. Check that it works by opening a daemon, and monitoring it using two msys shells. ### msys shell with daemon $ dbus-daemon --session --print-address > /home/dbus.txt ### msys shell with monitor $ export DBUS_SESSION_BUS_ADDRESS="" $ dbus-monitor --address $DBUS_SESSION_BUS_ADDRESS signal sender=org.freedesktop.DBus -> dest=:1.0 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired string ":1.0" method call sender=:1.0 -> dest=org.freedesktop.DBus serial=3 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch string "eavesdrop=true,type='method_call'" method call sender=:1.0 -> dest=org.freedesktop.DBus serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch string "eavesdrop=true,type='method_return'" method call sender=:1.0 -> dest=org.freedesktop.DBus serial=5 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch string "eavesdrop=true,type='error'" ## Buld dbus-glib 1. Download the tarball [20] or clone the git repository [1] on your hardrive, e.g. `c:\dbus-glib` 2. confgure, make and install $ ./configure PKG_CONFIG="C:\Python27\Lib\site-packages\gtk-2.0\runtime\bin\pkg-config.exe" PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/c/Python27/Lib/pkgconfig:/c/Python27/Lib/site-packages/gtk-2.0/runtime/lib/pkconfig" $ make $ make install ## Build dbus-python, finally! 1. Download the wip-windows tarball [21] or clone the git repository [1] and checkout wip-windows branch on your hardrive, e.g. `c:\dbus-python`. 2. configure, make and install $ ./configure PYTHON="/c/Python27/python" PYTHON_INCLUDES="-I/c/Python27/include/" PYTHON_LIBS="-L/c/Python27/Lib -lpython27" PKG_CONFIG="C:\Python27\Lib\site-packages\gtk-2.0\runtime\bin\pkg-config.exe" PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/c/Python27/Lib/pkgconfig:/c/Python27/Lib/site-packages/gtk-2.0/runtime/lib/pkconfig" am_cv_python_pythondir='${prefix}/Lib/site-packages' 3. Check that it works by starting Python by adding your MSYS environment site-packages folder to your Python path, starting Python and import dbus. $ export PYTHONPATH="c:\\mingw\\msys\\1.0\\local\\lib\\site-packages" $ python Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import dbus 4. There are still some issues to work out, but I think they are with dbus, _not_ dbus-python. returns the following traceback: >>> session_bus = dbus.SessionBus() Traceback (most recent call last): File "", line 1, in File "c:\mingw\msys\1.0\local\lib\site-packages\dbus\_dbus.py", line 211, in __new__ return Bus.__new__(cls, Bus.TYPE_SESSION, private=private, mainloop=mainloop) File "c:\mingw\msys\1.0\local\lib\site-packages\dbus\_dbus.py", line 100, in __new__ bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop) File "c:\mingw\msys\1.0\local\lib\site-packages\dbus\bus.py", line 122, in __new__ bus = cls._new_for_bus(address_or_type, mainloop=mainloop) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Failed: Failed to get autolaunch address from launched dbus-daemon Now you have to kill this daemon manually using task managerd. This is the same issue I have with dbus-daemon.exe, and I have to manually output the address to a file and copy it in to monitor the connection. Autolaunch is not working on my build, and I have seen threads and bugs about it before. [1] http://www.freedesktop.org/wiki/Software/DBusBindings [2] http://www.freedesktop.org/wiki/Software/dbus [3] http://www.mingw.org/ [4] https://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/ [5] https://docs.google.com/document/d/1z8P0ke7yF2yo05Jds4jW-GtAXcQKOr1Bfjn0vAwvVg4/edit?hl=en_US [6] http://www.python.org/download/ [7] http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/ [8] http://www.gtk.org/download/win32.php [9] http://www.mingw.org/wiki/Bootstrapping_GLIB_with_MinGW [10] http://dbus.freedesktop.org/releases/dbus/ [11] https://bitbucket.org/bradpitcher/mingw-cross-env/src/5f91fb4e0199/src/dbus-1-fixes.patch [12] https://sourceforge.net/tracker/?func=detail&atid=102435&aid=3420424&group_id=2435 [13] http://msdn.microsoft.com/en-us/library/ms684208%28VS.85%29.aspx [14] https://bugs.freedesktop.org/show_bug.cgi?id=41423 [15] https://sourceforge.net/mailarchive/message.php?msg_id=24260705 [16] http://lists.gnu.org/archive/html/mingw-cross-env-list/2011-09/msg00033.html [17] https://github.com/mxe/mxe/commit/d51ad53b664859b38c3cee61f18c4e8e8810fcef [18] https://bitbucket.org/vog/mingw-cross-env/changeset/8bfc6d601bb1 [19] http://mingw-w64.sourceforge.net/ [20] http://dbus.freedesktop.org/releases/dbus-glib/ [21] http://people.freedesktop.org/~smcv/dbus-python-1.1.1.20120704.tar.gz