I have written this post as notes for myself on how to
First, you have to make sure that Xcode command-line tools are installed.
xcode-select --install
Now you have to install C headers in the /usr/include by running the following command:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Now we can start building the GCC. Let’s define all the variables we will use while building it.
export WDIR=/tmp export BUILD=x86_64-apple-darwin$(uname -r) export TARGET=mipsel-linux-musl export PREFIX=/opt/cross/${TARGET} cd ${WDIR} mkdir -p ${TARGET}-src mkdir -p ${TARGET}-toolchain
You also have to download and install GNU sed utility. The macOS built-in sed does not support the features needed. I usually install sed in /opt/sed/bin because it has to be used when building GNU projects.
cd ${WDIR}/${TARGET}-src curl -L https://ftp.gnu.org/gnu/sed/sed-4.7.tar.xz | tar xJf - cd ${WDIR}/${TARGET}-toolchain mkdir -p build-sed cd build-sed ${WDIR}/${TARGET}-src/sed-4.7/configure \ --prefix=/opt/sed make -j 8 sudo make install-strip export PATH=/opt/sed/bin:${PATH}
cd ${WDIR}/${TARGET}-src curl -L http://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.gz | tar xzf - cd ${WDIR}/${TARGET}-toolchain mkdir -p build-binutils cd build-binutils ${WDIR}/${TARGET}-src/binutils-2.32/configure \ --disable-nls \ --prefix=${PREFIX} \ --target=${TARGET} make -j 8 sudo make install-strip
To build GCC we need GMP, MPFR, MPC, and ISL. Let’s download and build them.
cd ${WDIR}/${TARGET}-src curl -L https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2 | tar xjf - curl -L ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 | tar xjf - curl -L ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz | tar xzf - curl -L ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 | tar xjf - cd ${WDIR}/${TARGET}-toolchain mkdir -p build-gmp cd build-gmp ${WDIR}/${TARGET}-src/gmp-6.1.2/configure \ --prefix=/opt/gmp \ --enable-cxx make -j 8 sudo make install-strip cd ${WDIR}/${TARGET}-toolchain mkdir -p build-mpfr cd build-mpfr ${WDIR}/${TARGET}-src/mpfr-3.1.4/configure \ --prefix=/opt/mpfr \ --with-gmp=/opt/gmp make -j 8 sudo make install-strip cd ${WDIR}/${TARGET}-toolchain mkdir -p build-mpc cd build-mpc ${WDIR}/${TARGET}-src/mpc-1.0.3/configure \ --prefix=/opt/mpc \ --with-gmp=/opt/gmp \ --with-mpfr=/opt/mpfr make -j 8 sudo make install-strip cd ${WDIR}/${TARGET}-toolchain mkdir -p build-isl cd build-isl ${WDIR}/${TARGET}-src/isl-0.18/configure \ --prefix=/opt/isl \ --with-gmp-prefix=/opt/gmp make -j 8 sudo make install-strip
Now we can download GCC and build it. We will disable shared library support (you can enable it if you want but that will need some more configuration), enable C and C++ languages and build only the compiler (all-
cd ${WDIR}/${TARGET}-src curl -L https://ftpmirror.gnu.org/gcc/gcc-8.3.0/gcc-8.3.0.tar.xz | tar xJf - cd ${WDIR}/${TARGET}-toolchain mkdir -p build-gcc cd build-gcc ${WDIR}/${TARGET}-src/gcc-8.3.0/configure \ --enable-languages=c,c++ \ --disable-nls \ --prefix=${PREFIX} \ --with-gmp=/opt/gmp \ --with-mpfr=/opt/mpfr \ --with-mpc=/opt/mpc \ --with-isl=/opt/isl \ --target=${TARGET} \ --with-float=soft \ --disable-shared # remove to enable shared libs make all-gcc -j8 sudo make install-strip-gcc
When the GCC has been built we can download and build
cd ${WDIR}/${TARGET}-src curl -L https://www.musl-libc.org/releases/musl-1.1.21.tar.gz | tar xzf - cd ${WDIR}/${TARGET}-toolchain mkdir -p build-musl cd build-musl CROSS_COMPILE=${PREFIX}/bin/${TARGET}- \ ${WDIR}/${TARGET}-src/musl-1.1.21/configure \ --target=${TARGET} \ --prefix=${PREFIX}/${TARGET} \ --build=${BUILD} \ --with-float=soft \ --disable-shared # remove to enable shared libs make -j8 sudo make install
The last step is to finish building the rest of the GCC.
cd ${WDIR}/${TARGET}-toolchain cd build-gcc make -j8 sudo make install-strip
Now the full GCC toolchain and