Skip to content

Instantly share code, notes, and snippets.

@jtauber
Last active January 20, 2023 19:40
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtauber/8b2fa862d43ecedf7536 to your computer and use it in GitHub Desktop.
Save jtauber/8b2fa862d43ecedf7536 to your computer and use it in GitHub Desktop.
setting up OS X 10.9 for i386-elf cross-compilation
# frustratingly, we need to have "real" gcc to build the i386-elf binutils/gcc
brew install gcc
# $PROJECT_HOME should be the parent directory under which you'll download
# everything and build the toolchain
cd $PROJECT_HOME
mkdir toolchain
# set up our environment variables
export PREFIX=$PROJECT_HOME/toolchain
export TARGET=i386-elf
export CC=/usr/local/bin/gcc-4.8
export CXX=/usr/local/bin/g++-4.8
export LD=/usr/local/bin/gcc-4.8
export CFLAGS=-Wno-error=deprecated-declarations
# get binutils source
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.gz
tar xvzf binutils-2.24.tar.gz
cd binutils-2.24
# make binutils (for i386-elf)
./configure --prefix=$PREFIX --target=$TARGET --disable-nls
make
make install
cd ..
# get gcc source
curl -O http://ftp.gnu.org/gnu/gcc/gcc-4.9.0/gcc-4.9.0.tar.gz
tar xvzf gcc-4.9.0.tar.gz
cd gcc-4.9.0
# make gcc (for i386-elf)
./configure --prefix=$PREFIX --target=$TARGET --disable-nls --enable-languages=c --without-headers
make all-gcc
make install-gcc
export PATH=$PREFIX/bin:$PATH
# how to make a grub floppy image
dd if=/dev/zero of=grub.img bs=512 count=2880
cat boot/grub/stage1 boot/grub/stage2 | dd of=grub.img conv=notrunc
@pgeorgan
Copy link

How long does this take? My machine is taking 30+ minutes to run the first script.

@Nashenas88
Copy link

For anyone attempting this in the future and curious about runtime (this is just the compiling gcc part):
MacBook Pro (15-inch, Late 2008)
2.4 GHz Intel Core 2 Duo
8 GB 1067 MHz DDR3
256GB SSD

It took a little over 60 minutes (gcc 4.9.3).

@hzshang
Copy link

hzshang commented Jan 7, 2018

make -j8 works faster

@allenmqcymp
Copy link

For anyone who will need to link libgcc, create a subdirectory eg. build in the gcc folder and run ../configure etc.

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