Mike Levin SEO

Future-proof your technology-skills with Linux, Python, vim & git... and me!

Now Compiling QEMU 1.6.1 From Source For Mac Levinux

by Mike Levin SEO & Datamaster, 10/29/2013

Okay as per my earlier experience when I was trying to make the original Levinux distro based on my own qemu compiles, Linux was the easiest platform to compile QEMU on with curses enabled. And unlike my earlier experiences when QEMU was version 1.2, I was able to do a static compile, baking the library dependencies right into the executable, reducing a mess of files that had to live in the Levinux package bundle. Clearly qemu is advancing fast, becoming a critical category-killing tool for Android development, a native-like cross-compiling alternative for ARM, Raspberry Pi and others… oh, and also the underpinnings of the popular and more polished-looking VirtualBox. In other words, Fabrice Bellard’s project just grew up and hit it big. I’m one of the beneficiaries of this. Things are MUCH nicer than they were a year go. I’m glad to be a first-mover in one of these portable install-less QEMU USB Linuxes. Nobody has any idea how cool things have become with keychain or thumbdrive Linux.

Now, it is time to do a static, curses enabled compile of QEMU on Mac OS X again. This time around, I have the benefit of having investigate fink, Macports and Homebrew already, and have actual experience with Macports and Homebrew. Homebrew won hands-down! Things may have changed over the past year, but I’m suspecting everything just got more-so: fink fading to obscurity, Macports heavyweight with nested unnecessary dependencies, and Homebrew lean, fast and pragmatic.

The challenge here is figuring out Homebrew enough to do a static compile, although it may actually not be very necessary. There were only 3 dynamic libraries required for Mac:

libz1.dylib libSystem.B.dylib libmx.A.dylib

And so, let me just jump in headfirst. I’m working off the popular, but aged Q project.

Okay, it’s time to just install brew, per http://brew.sh/

ruby -e “$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)” ==> This script will install: /usr/local/bin/brew /usr/local/Library/… /usr/local/share/man/man1/brew.1 ==> The following directories will be made group writable: /usr/local/. /usr/local/bin /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig ==> The following directories will have their group set to admin: /usr/local/. /usr/local/bin /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig

Press ENTER to continue or any other key to abort

==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/bin /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig Password: ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/. /usr/local/bin /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig ==> Downloading and installing Homebrew… remote: Finding bitmap roots… remote: Counting objects: 134442, done. remote: Compressing objects: 100% (44289/44289), done. remote: Total 134442 (delta 93059), reused 130341 (delta 89123) Receiving objects: 100% (134442/134442), 24.66 MiB | 10.47 MiB/s, done. Resolving deltas: 100% (93059/93059), done. From https://github.com/mxcl/homebrew * [new branch] master -> origin/master HEAD is now at a59e2ad Mac.prefer_64_bit?: fix conditional for 10.4 ==> Installation successful! You should run `brew doctor’ *before* you install anything. Now type: brew help Michaels-MacBook-Air:~ miklevin$ brew doctor Warning: Unbrewed dylibs were found in /usr/local/lib. If you didn’t put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted.

Unexpected dylibs: /usr/local/lib/libmacfuse_i32.2.dylib /usr/local/lib/libmacfuse_i64.2.dylib /usr/local/lib/libosxfuse_i32.2.dylib /usr/local/lib/libosxfuse_i64.2.dylib

Warning: Unbrewed .la files were found in /usr/local/lib. If you didn’t put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted.

Unexpected .la files: /usr/local/lib/libosxfuse_i32.la /usr/local/lib/libosxfuse_i64.la

Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig. If you didn’t put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted.

Unexpected .pc files: /usr/local/lib/pkgconfig/osxfuse.pc

Warning: Your Xcode (5.0) is outdated Please update to Xcode 5.0.1. Xcode can be updated from the App Store.

Okay, where are we? Now, I’ve updated XCode 5.0.1 as brew doctor instructed. Now, I have a bunch of warnings due to the presence of fuse and a few other things that use /usr/local/lib. But I think it will be fine.

I have to make sure that when I build qemu, I’m enabling curses mode. This is where I did it last:


Ah! Now I remember! I still build QEMU from the same source code as on every other platform. I’m just using Homebrew as a quick and easy way of putting dependency requirements in place. And JUST LIKE back then, I try my configure command:

./configure target-list=i386-softmmu –enable-curses –static

…and I get the message about pkg-config being required. So…

brew install pkg-config

And I get the message about zlib being required.

Ugh! I removed the –static option, and it gets pas that, but it’s kicking of dependency hell. I’m just going to do:

brew install qemu

…and see what happens. A ton of dependencies are being installed. Hmmm. I hope they are just build requirements and not runtime requirements. I’m going to have to uninstall brew and everything it installed to test this. Ugh.

Okay, I see the download occurring. It is version 1.6.1 just like I’m compiling from source. Okay, that’s good. But is it enabling curses? It will be easy enough to find out. But another option is trying to compile from source myself AFTER brew does, because it will make sure all the dependencies are there.

Good news and bad news. The good news is that I could just rename the qemu binary, drop it into location, and it ran! No more outdated Q emulator. I will be able to get rid of a whole folder of graphics. The bad news is that adding the -curses switch stops it from running.


I now research how to set configure flags with homebrew, and it seems as easy as uninstalling with:

brew rm qemu

brew edit qemu

The resulting brew formula is easy to read and easy to edit with some flags like –enable-cocoa already set, so it’s easy to insert the curses flag!

Wow, that was a fairly long journey.

I delved deep into getting the Mac Homebrew version of QEMU working. Doing a static compile was a bust. It’s probably still possible. But I had to do a bunch of installs and removals of Homebrew to nail the dependencies. Not having Mac OS X as a virtual machine for snapshots and easy rollbacks is starting to become a problem. Maybe look for tools like Freeze. But VMs are so much easier and encapsulated.

Anyway, there’s a bunch more .dylib dependencies than there used to be. And in switching to curses mode, I had to go back to a launch script method that employs the AppleScript osascript method, so that I can make a Mac Application Bundle launch a bash shell on a double click IN WHICH QEMU is launched in curses mode. It’s a pretty bad-ass trick, but I’m hoping it’s not fragile. Testing needed.

Anyway, I’m pretty aggressively updating the underpinnings of Levinux, starting with gaining control of all those QEMU binaries, so I can come into GPL compliance and get this thing out on github, which I think is pretty necessary to cause Levinux groundswelling popularity.