#!/bin/sh set -e PREFIX="$PWD/toolchain" TARGET=x86_64-linux-musl ARCH=x86_64 export CFLAGS='-Os -pipe' export CXXFLAGS="$CFLAGS" export PATH="$PREFIX/bin:$PATH" export MAKEFLAGS="-j$(nproc)" mkdir -p "$PREFIX/src" ( cd "$PREFIX/src" wget -c https://ftp.gnu.org/gnu/binutils/binutils-2.30.tar.xz wget -c https://ftp.gnu.org/gnu/gcc/gcc-8.1.0/gcc-8.1.0.tar.xz wget -c https://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.xz wget -c https://ftp.gnu.org/gnu/mpfr/mpfr-4.0.1.tar.xz wget -c https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz wget -c http://isl.gforge.inria.fr/isl-0.19.tar.xz wget -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.16.7.tar.xz wget -c https://www.musl-libc.org/releases/musl-1.1.19.tar.gz wget -c http://sigrok.org/download/source/libserialport/libserialport-0.1.1.tar.gz ) ( cd "$PREFIX/src" rm -rf binutils-*/ tar xf binutils-*.tar.xz cd binutils-*/ mkdir build cd build ../configure --prefix="$PREFIX" --target="$TARGET" --disable-nls --disable-multilib make make install ) ( cd "$PREFIX/src" rm -rf gcc-*/ tar xf gcc-*.tar.xz cd gcc-*/ tar xf ../gmp-*.tar.xz tar xf ../mpfr-*.tar.xz tar xf ../mpc-*.tar.gz tar xf ../isl-*.tar.xz mv gmp-*/ gmp mv mpfr-*/ mpfr mv mpc-*/ mpc mv isl-*/ isl mkdir build cd build ../configure --prefix="$PREFIX" --target="$TARGET" --disable-nls --disable-multilib --disable-libsanitizer --disable-libmpx --enable-languages=c,c++ make all-gcc make install-gcc ) ( cd "$PREFIX/src" rm -rf linux-*/ tar xf linux-*.tar.xz cd linux-*/ make ARCH="$ARCH" INSTALL_HDR_PATH="$PWD/install" headers_install find install -type f -a ! -name '*.h' -delete cp -aT install/include "$PREFIX/$TARGET/include" ) ( cd "$PREFIX/src" rm -rf musl-*/ tar xf musl-*.tar.gz cd musl-*/ ./configure --prefix="$PREFIX/$TARGET" --host="$TARGET" --syslibdir='$(prefix)/lib' make install-headers ) ( cd "$PREFIX/src" cd gcc-*/build make MAKE='make enable_shared=no' all-target-libgcc make MAKE='make enable_shared=no' install-target-libgcc ) ( cd "$PREFIX/src" cd musl-*/ make LIBCC="$PREFIX/lib/gcc/$TARGET/*/libgcc.a" install ) ( cd "$PREFIX/src" cd gcc-*/build make make install ) ( cd "$PREFIX/src" rm -rf libserialport-*/ tar xf libserialport-*.tar.gz cd libserialport-*/ ./configure --prefix="$PREFIX/$TARGET" --host="$TARGET" make make install ) ( cd "$PREFIX/src" rm -rf binutils-*/ rm -rf gcc-*/ rm -rf linux-*/ rm -rf musl-*/ rm -rf libserialport-*/ #find "$PREFIX" -type f -name '*.la' -delete ) cat > "$PREFIX/env" << EOF export PATH="$PREFIX/bin:\$PATH" EOF echo 'Run "source toolchain/env" before running make!'