Building a MIPS cross-compiler for Linux

  1. Get the binutils and gcc packages at ftp://ftp.gnu.org/gnu that are the same version that is installed on your computer.
  2. Unpack them both:
              tar xzf binutils-2.x.tar.gz 
              tar xzf gcc-3.x.x.tar.gz 
    
  3. Build the binutils package, and install under ~/gcc:
              cd binutils-2.x 
              ./configure --prefix ~/gcc --host=i486-linux --target=decstation-ultrix 
              make 
              make install 
    
  4. Build gcc, and install under ~/gcc:
              cd ../gcc-3.x.x 
              ./configure --host=i486-linux --target=decstation-ultrix --with-gnu-as --with-gnu-ld --prefix ~/gcc --enable-obsolete
    
    Before building gcc, you need to make a few changes. After building the cross-compiler, the Makefile is going to try to use it to build a set of libraries, and a couple of test cases. The libraries depend on Unix headers (such as stdio.h) which Nachos does not support, so we need to fake out the Makefile by creating dummy lib files:
              ar rc libgcc.a /dev/null 
              ar rc libgcc3.a /dev/null 
              PATH=$PATH:~/gcc/bin
              export PATH
              make LANGUAGES=c 
              make install LANGUAGES=c 
    
    At the end of the compile, you will get an error.
  5. (optional) Reduce the space used by ~/gcc by removing some unecessary stuff, and by stripping binaries. There is probably more pruning possible, but I don't know gcc well enough to know what is safe to remove.
              cd ~/gcc; strip `find . -type f -perm -111 -print` 
              rm -rf info man include 
              cd lib; rm lib* 
    
  6. Make a simple c program that does not use libc and test it with your new compiler.
    	~/gcc/decstation-ultrix/bin/gcc -S test.c