For the OS course this semester, we’re using xv6, a simple operating system based upon Unix System 5, but rewritten from scratch for modern hardware and compilers.
The process for building xv6 on MacOS X is slightly more involved than on other systems. It took me a few tries to get it right, so here it is. These instructions are for MacOS X 10.7 (Lion), although they should be similar for other versions. They’re based on the original MIT instructions.
1) Install Xcode from the App Store (free download).
2) Install MacPorts.
3) From the Terminal application, use MacPorts to install glib2, gmp, mpc, mpfr, pkgconfig and ppl. This may take a while as glib2 has a lot of dependencies.
$ sudo port install glib2 gmp libmpc mpfr pkgconfig ppl
4) Add /usr/local/bin to $PATH if not already there.
$ export PATH=”$PATH:/usr/local/bin”
4) Install binutils.
$ curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.21.1.tar.bz2
$ tar -xjvf binutils-2.21.1.tar.bz2
$ cd binutils-2.21.1
$ ./configure –target=i386-jos-elf –disable-nls
$ make
$ sudo make install
$ cd ..
5) Install gcc. We have to modify LDFLAGS as there is some weirdness regarding MacPorts’ version of libiconv (a dependency of glib2) vs. the system’s one.
$ curl -O http://ftp.gnu.org/gnu/gcc/gcc-4.5.1/gcc-core-4.5.1.tar.bz2
$ tar -xjvf gcc-core-4.5.1.tar.bz2
$ mkdir objdir
$ cd objdir
$ ../gcc-4.5.1/configure –target=i386-jos-elf –disable-nls –without-headers –with-newlib \
–disable-threads –disable-shared –disable-libmudflap –disable-libssp –with-gmp=/opt/local
$ make LDFLAGS=-L/usr/lib
$ make install
$ cd ..
6) Install gdb
$ curl -O http://ftp.gnu.org/gnu/gdb/gdb-6.8a.tar.bz2
$ tar -xjvf gdb-6.8a.tar.bz2
$ cd gdb-6.8
$ ./configure –target=i386-jos-elf –program-prefix=i386-jos-elf- –disable-werror
$ make
$ sudo make install
$ cd ..
7) Install qemu (the MIT-modified version works better). Note that neither clang nor the default llvm-based gcc can successfully build qemu.
$ git clone http://pdos.csail.mit.edu/6.828/qemu.git -b 6.828-0.15
$ cd qemu
$ export CC=gcc-4.2
$ ./configure –disable-kvm –disable-sdl –target-list=”i386-softmmu x86_64-softmmu”
$ make
$ sudo make install
$ cd ..
8 ) Clean up
$ rm -rf binutils-2.21.1 binutils-2.21.1.tar.bz2 objdir gcc-4.5.1 gcc-core-4.5.1.tar.bz2 \
gdb-6.8 gdb-6.8a.tar.bz2 qemu
9) Install xv6 itself. No modifications should be necessary there.
$ git clone git://pdos.csail.mit.edu/xv6/xv6.gi
$ cd xv6
$ make qemu-nox