Skip to content

Instantly share code, notes, and snippets.

@hzshang
Last active January 26, 2018 16:38
Show Gist options
  • Save hzshang/7059fa69729501272d2afad1a3e40d72 to your computer and use it in GitHub Desktop.
Save hzshang/7059fa69729501272d2afad1a3e40d72 to your computer and use it in GitHub Desktop.
#!/bin/bash
# complie cross tool, only passed for i386-pc-elf
# before you start, make sure you have installed gmp mpfr isl zlib mpc m4 makeinfo to your system path
# download i386-pc-elf binary from https://drive.google.com/file/d/1VuKflnxlq934tImeO06ulqsilgIzzcc9/view?usp=sharing
export TARGET=i386-pc-elf
export PREFIX=$HOME/cross/usr
export SRC=$HOME/cross/src
export BUILD=$HOME/cross/build
export BINUTILS=binutils-2.29
export GCC=gcc-7.2.0
export NEWLIB=newlib-2.5.0.20170818
export GDB=gdb-8.0
mkdir -p $PREFIX $SRC $BUILD
cd $BUILD && mkdir binutils gcc-pass1 gcc-pass2 newlib gdb
# download src
cd $SRC
wget https://ftp.gnu.org/gnu/gcc/$GCC/$GCC.tar.xz
wget https://ftp.gnu.org/gnu/gdb/$GDB.tar.xz
wget https://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.xz
wget http://sourceware.org/pub/newlib/$NEWLIB.tar.gz
tar xvf $GCC.tar.xz
tar xvf $GDB.tar.xz
tar xvf $BINUTILS.tar.xz
tar xvf $NEWLIB.tar.gz
# complie
cd $BUILD/binutils
$SRC/$BINUTILS/configure --prefix=$PREFIX --target=$TARGET --enable-thumb --enable-interwork --enable-multilib --disable-nls
make -j8
make install
# Add absolute path
export PATH="$PATH:$PREFIX/bin"
cd $BUILD/gcc-pass1
$SRC/$GCC/configure --prefix=$PREFIX --target=$TARGET \
--disable-nls --enable-languages=c --without-headers --with-newlib \
--disable-libssp --disable-libquadmath --with-system-zlib --enable-thumb \
--enable-interwork --enable-multilib
make all-gcc -j8
make install-gcc
cd $BUILD/newlib
$SRC/$NEWLIB/configure --prefix=$PREFIX --target=$TARGET --disable-nls
make -j8
make install
cd $BUILD/gcc-pass2
$SRC/$GCC/configure --prefix=$PREFIX --target=$TARGET --enable-thumb --enable-interwork --enable-multilib --disable-nls --enable-languages=c --with-system-zlib
make -j8
make install
cd $BUILD/gdb
$SRC/$GDB/configure --prefix=$PREFIX --target=$TARGET
make -j8
make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment