Sunday, 7 October 2012

Compiling a Wine WoW64 build on Ubuntu Precise AMD64

If the title of this post doesn't mean anything to you, you should probably stop reading.

I'm going to start by assuming you know what Wine is, and pretty much everything else I talk about throughout the post. This is simply intended to be instructional and not educational.

I noticed that there isn't really a full instruction set in the Wine Wiki for how to build a full WoW64 setup within Ubuntu 12.04 64-bit, so I thought I should try and figure these things out for myself. I don't consider this post suitable to be added to the Wiki as it's a bit of a jumble, but I may look into it later. (Feel free to give a helping hand!) It may take a few glances to realise what is being done and why.

The first steps are:
  1. Install all the build requirements on your machine.
  2. Install an i386 chroot (I used Precise again). A fakeroot installation failed miserably but you might have more luck.
  3. Install all the build requirements in the chroot.
Next, you should build Wine64 outside of the chroot.

The 32/64 build will require access to both 32- and 64-bit libraries. This is why it fails in the first place: Ubuntu have screwed up their multilib. You can copy all the files into their respective folder inside the chroot but this will use up more space, and they won't be updated when needed. Soft links won't work and hard links might create problems when running an update. Bind is your answer.

You will need to create the relevant directories inside your chroot:
(Some directories may already exist and be empty - that's fine).

mkdir /usr/lib/x86_64-linux-gnu
mkdir /lib64
mkdir /lib/x86_64-linux-gnu
mkdir ~/wine64
mkdir ~/wine3264

You then need to bind these directories so that the chroot can see them.
(In some cases it would be prudent to bind a directory read-only, unfortunately that fails and you have to mount -o remount,ro /foo/bar if you feel this necessary).

mount -B ~/wine-git /path/to/chroot/~/wine-git
mount -B /usr/lib/x86_64-linux-gnu /path/to/chroot/usr/lib/x86_64-linux-gnu
mount -B /lib64 /path/to/chroot/lib64
mount -B /lib/x86_64-linux-gnu /path/to/chroot/lib/x86_64-linux-gnu
mount -B ~/wine64 /path/to/chroot/~/wine64
mount -B /path/to/chroot/~/wine3264 ~/wine3264

Where you will need to expand the ~ to point to the correct directories.

The final mount being so that you can access the build from your host environment.

I also mounted /tmp as the /tmp inside the chroot will not be cleared on reboot.

mount -B /tmp /path/to/chroot/tmp

Now you can build the WoW64 Wine.
Inside the chroot:

cd ~/wine3264
~/wine-git/configure --with-wine64=~/wine64
make

Remember to add any other options you wish to add.

Once compiled you can run the whole setup from your host environment from the build tree (which has been bind-mounted), or make install and run that way. I highly recommend that you script as much as you can. If you're planning on rebuilding or running regression tests then you will spend a lot of time typing in the same commands over and over.
Similarly, you should consider ccache and distcc. You should read up on how to share your .ccache, and make sure that the distcc servers have the relevant libs too (you could use sshfs mount to work around any missing dependencies).
Also I have added the above mounts to my /etc/fstab so that I don't have to worry about mounting them all the time.

You should now have a working WoW64 build of Wine.

As I have said, this is a quickly thrown together instructional post, so if you get stuck then feel free to ask for help. I highly recommend using irc://irc.freenode.net/#winehq as the people on there are extremely knowledgeable on the subject. If the problem is a little more involved you should probably use the forums.