Skip to content

Instantly share code, notes, and snippets.

@theoparis
Last active October 28, 2022 22:36
Show Gist options
  • Save theoparis/e21615b3b9c840e45a69716abd6693eb to your computer and use it in GitHub Desktop.
Save theoparis/e21615b3b9c840e45a69716abd6693eb to your computer and use it in GitHub Desktop.
build statically linked cross gcc compiler (assumes you have downloaded the sources and prequsities for gcc)
#!/bin/sh
set -e
TARGET=${TARGET:-"x86_64-linux-musl"}
PREFIX=${PREFIX:-"/usr/local/dev/gcc"}
CC=${CC:-"gcc"}
CXX=${CXX-"g++"}
LANGUAGES=${LANGUAGES:-"c,c++,go"}
./configure \
--enable-languages="$LANGUAGES" \
--disable-nls \
--disable-shared \
--disable-host-shared \
--with-boot-ldflags=-static \
--with-stage1-ldflags=-static \
--disable-multilib \
--prefix="$PREFIX" \
--host="$TARGET" \
CC="$CC" CXX="$CXX"
make -j$(nproc)
make -j$(nproc) install
echo "DONE"
echo "You can find your compiled gcc executable at $PREFIX/bin/gcc".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment