Skip to content

Instantly share code, notes, and snippets.

Created September 26, 2012 16:26
Show Gist options
  • Save gburd/3789004 to your computer and use it in GitHub Desktop.
Save gburd/3789004 to your computer and use it in GitHub Desktop.
Building the xv6 operating system using Clang on OS/X (10.8) for fun and non-profit.
diff --git a/Makefile b/Makefile
index 33bfb0a..af625c8 100644
--- a/Makefile
+++ b/Makefile
@@ -29,10 +29,10 @@ OBJS = \
# Cross-compiling (e.g., on Mac OS X)
-#TOOLPREFIX = i386-jos-elf-
+TOOLPREFIX = /opt/gnu/bin/i386-jos-elf-
# Using native tools (e.g., on X86 Linux)
# Try to infer the correct TOOLPREFIX if not set
@@ -51,7 +51,7 @@ TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/d
# If the makefile can't find QEMU, specify its path here
-#QEMU =
+QEMU = qemu-system-i386
# Try to infer the correct QEMU
ifndef QEMU
@@ -67,8 +67,8 @@ QEMU = $(shell if which qemu > /dev/null; \
echo "***" 1>&2; exit 1)
+CC = /opt/gnu/gcc

Building the UNIXv6 (xv6) operating system using Clang as a learning experience.

Work in Progress... these are my notes so far...

Why? Because.

I've run into xv6 a few times and always wanted to poke around with it. My two goals are:

  • Build and run it on OS/X 10.8 (Mountain Lion)
  • Change the build system so as to support compilation with Clang just for kicks My environment is a MacBook Pro where I'm running 10.8 and using Homebrew. I found this article useful as a starting point for building on OSX.


  1. Install Xcode. After installing Xcode install the Command Line Tools from the Downloads section of Xcode's preferences. I've installed Xcode Version 4.5 (4G182).
  2. Install Homebrew
  3. Install pre-requisites for building xv6
    $ brew install glib gmp mpfr pkgconfig ppl
    $ brew install libmpc --use-llvm
    $ brew install qemu --use-gcc
  4. Install GNU binutils
    $ cd /tmp
    $ curl -O
    $ tar -xvzf binutils-2.22.tar.gz
    $ ./configure --target=i386-jos-elf --disable-nls --prefix=/opt/gnu
    $ make
  5. Install GCC 4.5 via Homebrew
    $ cd /tmp
    $ curl -O
    $ cd gcc-4.7.2
    $ ./configure --target=i386-jos-elf --disable-nls --without-headers --with-newlib --disable-threads --disable-shared --disable-libmudflap --disable-libssp --with-system-zlib --disable-lto --with-gmp=/usr/local --enable-languages=c --prefix=/opt/gnu
    $ LDFLAGS=-L/usr/lib make
    $ make install

Install and build xv6 with GCC

$ git clone git://
cd xv6
make qemu-nox

Changes to support Clang

Building with Clang

Copy link

pk-nb commented Nov 27, 2012

I'm a bit confused on step 5. Install GCC 4.5 via Homebrew? Isn't this a normal make?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment