0 Compiling from Source (Windows)
zhekae edited this page 2021-12-17 23:33:23 +03:00

Overview

The method described here uses MinGW to cross-compile from an Ubuntu host system.

Making a chroot

It's perfectly fine to compile Clementine on a real Ubuntu system, but you will end up installing files all over your system so it might be preferable to set up a chroot first. Full instructions can be found on the DebootstrapChroot page on the Ubuntu wiki, but here's an outline:

sudo apt-get install debootstrap schroot
sudo debootstrap --variant=buildd --arch i386 precise /var/chroot/mingw http://archive.ubuntu.com/ubuntu/
sudo mkdir /var/chroot/mingw/etc
sudo cp /etc/{passwd,shadow,group,sudoers} /var/chroot/mingw/etc/
sudo sh -c "echo /proc /var/chroot/mingw/proc none rbind 0 0 >> /etc/fstab"
sudo sh -c "echo mingw > /var/chroot/mingw/etc/debian_chroot"
sudo mkdir /var/chroot/mingw/proc
sudo mount /var/chroot/mingw/proc

Edit /var/chroot/mingw/etc/apt/sources.list and add the universe restricted multiverse repositories.

deb http://archive.ubuntu.com/ubuntu precise universe
deb http://archive.ubuntu.com/ubuntu precise restricted
deb http://archive.ubuntu.com/ubuntu precise multiverse

Now edit /etc/schroot/schroot.conf and add the following section at the bottom:

[mingw]
description=MinGW build environment
directory=/var/chroot/mingw
groups=chroot
personality=linux32

Ubuntu Trusty (on the host OS - the one with the schroot binary) and above don't create a chroot group by default. You might need to create this group and add yourself to it:

sudo groupadd -r chroot
sudo usermod -a -G chroot $USER
newgrp chroot

You can now log into your chroot by running schroot -c mingw. Follow the rest of this guide inside the chroot.

Installing the build tools

apt-get update
apt-get install yasm cmake qt4-dev-tools stow unzip autoconf libtool \
    bison flex pkg-config gettext libglib2.0-dev intltool wine git-core \
    sudo texinfo wget

Install natty's version of libtool from http://old-releases.ubuntu.com/ubuntu/pool/main/libt/libtool/ (get version 2.2.6b)

wget http://old-releases.ubuntu.com/ubuntu/pool/main/libt/libtool/libtool_2.2.6b-2ubuntu1_i386.deb
dpkg -i libtool_2.2.6b-2ubuntu1_i386.deb

Installing the compiler

We use mingw-w64 to compile Clementine. Download the latest version from SourceForge (mingw-w32-bin_i686-linux_20130523.tar.bz2 at the time of writing)

Extract it inside the chroot to the /mingw directory, and then put it on your $PATH:

cd /
mkdir mingw
cd mingw
tar -xvf mingw-w32-bin_i686-linux_20130523.tar.bz2
chmod +rx /root

export PATH=$PATH:/mingw/bin

Setting up wine

You have to do this each time you restart if you're using a chroot, it registers .exe files as being executable:

mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc 
echo ':DOSWin:M::MZ::/usr/bin/wine:' > /proc/sys/fs/binfmt_misc/register

Compiling dependencies

I've gathered up all the source packages that are required for Clementine and put them on Google Drive. There's a Makefile that downloads and builds them all in git. You can browse the build system here and the packages themselves here. We're going to check out the build system into /src (which downloads all the packages for you), and compile each package into /target (which is a symlink to /usr/i586-mingw32msvc).

You can do all this as root, or as a normal user if you chown -R /src and /target.

If /usr/i586-mingw32msvc doesn't exists, just create it.

mkdir /usr/i586-mingw32msvc
ln -s /usr/i586-mingw32msvc /target

mkdir /src /target/stow /target/bin
ln -s /mingw/i686-w64-mingw32/lib/libgcc_s_sjlj-1.dll /target/bin/

git clone https://github.com/clementine-player/Dependencies.git /src

Now you're ready to start compiling:

cd /src/windows
make

This will take some time - anywhere from 20 minutes to an hour depending on how many processors you have. Each package will get compiled with -j8, you can change that by editing the Makefile. You can compile different packages in parallel by passing -j when you call make, but we sometimes get the dependencies wrong so it might not always work.

When it's done there will be a /src/windows/clementine-deps folder with all the .dlls that get bundled with Clementine.

Compiling Clementine

Now that we've got all the dependencies this is quite simple:

git clone https://github.com/clementine-player/Clementine.git clementine-player
cd clementine-player/bin
PKG_CONFIG_LIBDIR=/target/lib/pkgconfig \
    cmake .. \
    -DCMAKE_TOOLCHAIN_FILE=/src/Toolchain-mingw32.cmake \
    -DQT_HEADERS_DIR=/target/include \
    -DQT_LIBRARY_DIR=/target/bin \
    -DPROTOBUF_PROTOC_EXECUTABLE=/target/bin/protoc
make

If you're lucky there should be a bin/clementine.exe

Making the installer

Creating the windows installer requires nsis:

sudo apt-get install nsis

cd clementine-player/dist/windows
ln -s /src/windows/clementine-deps/* .
ln -s ../../bin/clementine*.exe .
makensis clementine.nsi