Created
April 12, 2025 21:18
-
-
Save phaser/5352f350fe5d79bd1a3103bffc12a98c to your computer and use it in GitHub Desktop.
Creating a cross-compiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -x | |
| export PATH="$(brew --prefix bison)/bin:$(brew --prefix flex)/bin:/usr/local/bin:$PATH" | |
| export PREFIX="$HOME/opt/cross" | |
| export TARGET=i686-elf | |
| export PATH="$PREFIX/bin:$PATH" | |
| BUILD_FOLDER="build" | |
| BINUTILS="binutils-2.44.tar" | |
| GCC="gcc-14.1.0.tar" | |
| rm -rf $BUILD_FOLDER | |
| mkdir -p $BUILD_FOLDER | |
| cd $BUILD_FOLDER | |
| echo "Compile $BINUTILS" | |
| tar -xf ../$BINUTILS | |
| BINUTILS_SRC=$(ls . | grep "binutils.*") | |
| BINUTILS_BUILD="binutils_build" | |
| mkdir -p $BINUTILS_BUILD | |
| cd $BINUTILS_BUILD | |
| ../$BINUTILS_SRC/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror | |
| make -j8 | |
| make install | |
| cd .. | |
| echo "Compile $GCC" | |
| # The $PREFIX/bin dir _must_ be in the PATH. We did that above. | |
| which -- $TARGET-as || echo $TARGET-as is not in the PATH | |
| tar -xf ../$GCC | |
| GCC_SRC=$(ls . | grep "gcc*") | |
| GCC_BUILD="gcc_build" | |
| mkdir -p $GCC_BUILD | |
| cd $GCC_BUILD | |
| ../$GCC_SRC/configure --prefix=$PREFIX \ | |
| --target=$TARGET \ | |
| --disable-nls \ | |
| --enable-languages=c,c++ \ | |
| --disable-hosted-libstdcxx \ | |
| --without-headers \ | |
| --enable-interwork \ | |
| --enable-multilib \ | |
| --with-gmp=$(brew --prefix gmp) \ | |
| --with-mpc=/opt/homebrew/Cellar/libmpc/1.3.1 \ | |
| --with-mpfr=$(brew --prefix mpfr) \ | |
| --with-newlib | |
| make all-gcc -j8 | |
| make install-gcc | |
| make all-target-libgcc -j8 | |
| make install-target-libgcc | |
| make all-target-libstdc++-v3 -j8 | |
| make install-target-libstdc++-v3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment