Skip to content

Instantly share code, notes, and snippets.

@gburd
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 = \
vm.o\
# 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)
-#TOOLPREFIX =
+#TOOLPREFIX =
# Try to infer the correct TOOLPREFIX if not set
ifndef TOOLPREFIX
@@ -51,7 +51,7 @@ TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/d
endif
# 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)
endif
-CC = $(TOOLPREFIX)gcc
-AS = $(TOOLPREFIX)gas
+CC = /opt/gnu/gcc
+AS = $(TOOLPREFIX)as
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump

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.

Configuration

  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 http://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.gz
    $ 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 http://ftp.gnu.org/gnu/gcc/gcc-4.7.2/gcc-4.7.2.tar.gz
    $ 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://pdos.csail.mit.edu/xv6/xv6.git
cd xv6
make qemu-nox

Changes to support Clang

Building with Clang

@pk-nb
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