User:Lionel/OSX
|
Developing on Mac OSX is a pretty hard thing. Apple's toolchain is broken and will not create ELF executables, only MACH-O. This is problematic, so here I will list my experiences on trying to fix it or port stuff to OSX.
Contents |
What this is NOT
This is NOT a roadmap on how to develop on OSX, but a list of experiences I had, and hint's and notes that might help you with OS Development. Feel free to contribute.
Porting
Clang
Clang is pretty easy to port. And I mean a full clang, not just the apple version. The apple version of clang appears to be able to only output Mach-O binaries, and ignores any options to create ELF output, or cross compile. However, building a full version of clang is pretty easy. You require Subversion and cmake. Apple make and binutils work well enough to produce a working binary. Just follow the tutorial on compiling clang.
libiconv
Building an updated version of libiconv was easy. Here's my process:
function grab () { echo "Pulling $1..." if [ ! -f "$3" ]; then wget "$2/$3" else echo "Already have $1" fi } #Credit Kevin Lange (klange) for grab function ##TODO:COMPLETE
gcc
VERSION=4.7.0 PREFIX=/usr/gcc-4.7.0 LANGUAGES=c,c++ MAKE=make # Or # MAKE='make -j 4' # to compile using four cores brew-path() { brew info $1 | head -n3 | tail -n1 | cut -d' ' -f1; } # Prerequisites brew install gmp brew install mpfr brew install libmpc # Download & install the latest GCC mkdir -p /usr/gcc-4.7.0 mkdir temp-gcc cd temp-gcc wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.7.0/gcc-4.7.0.tar.gz tar xfz gcc-4.7.0.tar.gz rm gcc-4.7.0.tar.gz cd gcc-4.7.0 mkdir build cd build ../configure \ --prefix=/usr/gcc-4.7.0 \ --with-gmp=$(brew-path gmp) \ --with-mpfr=$(brew-path mpfr) \ --with-mpc=$(brew-path libmpc) \ --program-suffix=-4.7.0 \ --enable-languages=c,c++ \ --with-system-zlib \ --enable-stage1-checking \ --enable-plugin \ --enable-lto \ --disable-multilib sudo make -j 4 bootstrap sudo make -j 4 install
binutils (cross compiling)
Porting binutils was A HUGE PAIN. First of all, you need to compile a working GCC. Then, you need to run the following commands.
export PREFIX=/usr/local/cross export TARGET=i586-elf export MAKEFLAGS="-j 4" export CC=/usr/gcc-4.7.0/bin/gcc-4.7.0 export CXX=/usr/gcc-4.7.0/bin/g++-4.7.0 export CPP=/usr/gcc-4.7.0/bin/cpp-4.7.0 export LD=/usr/gcc-4.7.0/bin/gcc-4.7.0 mkdir -p ~/src/build-binutils/ curl ftp://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2 | tar -x -f - -C ~/src/ cd ~/src/build-binutils/ ../binutils-2.22/configure --prefix=$PREFIX --target=$TARGET --disable-nls
Now STOP. There is a bug in gcc that makes -Werror turn on for each component, and yet it wont be disabled by NO_WERROR. Enter build-binutils, and in each subfolder do a search for -Werror inside of Makefile, and delete it from CFLAGS. Then, finally you can:
make all sudo make install
To install binutils to /usr/local/cross