How to cross compile libsipe for win32 using docker containers

Developers
sfuser
2014-01-12
2014-01-12
  • sfuser
    sfuser
    2014-01-12

    Disclaimer: I'm just a guy who has played around with things. I've found the below works for me and figured i'd share my findings with the developer community.

    Having had trouble in the past trying to cross compile libsipe using ubuntu (i could never get the right dependencies). I saw Stefan suggest using gcc-mingw32 in a recent post, this seems to do the trick.

    I started playing with docker containers (http://docker.io) recently and decided to try and script a build using a docker container - essentially allowing you to build using a consistent environment provided you've got docker installed.

    Setup
    1) Make sure you have a working install of docker - http://docker.io/
    2) Copy the build script (below) to a writable directory on your system (I'm going to assume /home/dev/docker)
    3) Make sure you have the ubuntu docker repository (you should already have this if you followed the getting started guide for docker)

    $ docker pull ubuntu
    

    4) Start up a docker container using the ubuntu 12.10 quantal image. We're going to share the folder from the host with the build script (build.sh) and change to the directory and make sure it's executable.

    docker run -t -i -v /home/dev/docker:/root/docker:rw ubuntu:12.10 /bin/bash
    root@b8bdaabfa558:/# cd /root/docker
    root@b8bdaabfa558:/root/docker# ls -alh
    total 12K
    drwxr-xr-x 2 root root 4.0K Jan 12 13:43 .
    drwx------ 3 root root 4.0K Jan 12 13:44 ..
    -rw-r--r-- 1 root root 2.8K Jan 12 13:43 build.sh
    root@b8bdaabfa558:/root/docker# chmod +x build.sh
    

    5) Finally, kick off the setup/build by executing the build.sh script

    root@b8bdaabfa558:/root/docker# ./build.sh
    

    6) Once the build has completed you should end up with something like the following:

    rm -rf ../win32-install-dir
    make: Leaving directory `/root/docker/libsipe-buildroot/build-2.10.7/pidgin-2.10.7/pidgin-sipe-1.17.3'
    NSIS package built and moved to /root/docker/libsipe-buildroot/pidgin-sipe-1.17.3.exe
    

    You can grab a copy of the NSIS installer package from your host machine in /home/dev/docker/libsipe-buildroot/ (assuming /home/dev/docker was the volume you shared when running the container).

    The build script (assumed it's called build.sh)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    #!/bin/bash
    # Script to build libsipe via a docker container (http://docker.io) using the ubuntu 12.10 image.
    
    # The version of libsipe to build (based off the source tarballs)
    LIBSIPE_VERSION=1.17.3
    BUILD_ROOT=`pwd`/libsipe-buildroot
    SETUP_DONE=${BUILD_ROOT}/.done
    
    set -e
    
    if [ ! -e ${SETUP_DONE} ]; then
    # Use the closest mirror
    echo Updating /etc/apt/sources.list to use the closest mirror
    DISTRO=`grep CODENAME /etc/lsb-release | sed 's/.*=//g'`
    cat << EOF > /etc/apt/sources.list
    deb mirror://mirrors.ubuntu.com/mirrors.txt ${DISTRO} main restricted universe multiverse
    deb mirror://mirrors.ubuntu.com/mirrors.txt ${DISTRO}-updates main restricted universe multiverse
    deb mirror://mirrors.ubuntu.com/mirrors.txt ${DISTRO}-backports main restricted universe multiverse
    deb mirror://mirrors.ubuntu.com/mirrors.txt ${DISTRO}-security main restricted universe multiverse
    EOF
    
    # dpkg divert for upstart
    dpkg-divert --local --rename --add /sbin/initctl
    ln -sf /bin/true /sbin/initctl
    
    # Package pre-requisites
    echo Installing required packages
    apt-get update
    apt-get install -yq xz-utils wget ca-certificates make gcc-mingw32 gettext unzip nsis #12.10
    
    # Setting up
    mkdir -p $BUILD_ROOT
    touch $SETUP_DONE
    fi
    
    # Download libsipe
    cd $BUILD_ROOT
    echo Downloading the libsipe source version $LIBSIPE_VERSION
    wget -nv http://sourceforge.net/projects/sipe/files/sipe/pidgin-sipe-${LIBSIPE_VERSION}/pidgin-sipe-${LIBSIPE_VERSION}.tar.gz
    tar xzf pidgin-sipe-${LIBSIPE_VERSION}.tar.gz
    
    # Run the libsipe fetch script to get our dependencies
    PIDGIN_VERSION=`grep 'export PIDGIN_VERSION' pidgin-sipe-${LIBSIPE_VERSION}/contrib/mingw-cross-compile/fetch.sh | sed 's/.*=//'`
    echo Fetching pre-requisites via libsipe fetch.sh pidgin version $PIDGIN_VERSION
    ${BUILD_ROOT}/pidgin-sipe-${LIBSIPE_VERSION}/contrib/mingw-cross-compile/fetch.sh
    
    # Remeber to copy the local.mak
    echo Copying local.mak to pidgin root
    cp pidgin-sipe-${LIBSIPE_VERSION}/contrib/mingw-cross-compile/local.mak build-${PIDGIN_VERSION}/pidgin-${PIDGIN_VERSION}/
    mv pidgin-sipe-${LIBSIPE_VERSION} build-${PIDGIN_VERSION}/pidgin-${PIDGIN_VERSION}/
    
    # Okies, lets build libsipe.dll
    echo Building libsipe.dll
    cd build-${PIDGIN_VERSION}/pidgin-${PIDGIN_VERSION}
    make -C pidgin-sipe-${LIBSIPE_VERSION}/src/core -f Makefile.mingw
    
    # Create the nsis package
    echo Creating installer package
    PIDGIN_TREE_TOP=.. make -C pidgin-sipe-${LIBSIPE_VERSION} -f Makefile.mingw cross-compile-nsis
    
    # Finish up and do a final sanity check
    if [ -e pidgin-sipe-${LIBSIPE_VERSION}.exe ]; then
      mv pidgin-sipe-${LIBSIPE_VERSION}.exe ${BUILD_ROOT}/pidgin-sipe-${LIBSIPE_VERSION}.exe
      echo NSIS package built and moved to ${BUILD_ROOT}/pidgin-sipe-${LIBSIPE_VERSION}.exe
    else
      echo Could not find pidgin-sipe-${LIBSIPE_VERSION}.exe check the output for errors :\(
      echo `pwd`
    fi
    

    Conclusion
    I realise i could use a Dockerfile for this/whack something up on github. I think docker is very powerful and it'd be great if we could band together and come up with a version that works on the 12.04 LTS image (as well as possibly supporting checking out from git etc).

    A big thanks to the libsipe dev team, your work is greatly appreciated.

     
    Last edit: sfuser 2014-01-12