diff --git a/Dockerfile b/Dockerfile index 43f8daa..41b60b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,4 +30,9 @@ RUN apt update && apt install -y \ wget \ xz-utils +# Install musl-based toolchains. +ENV MUSL_INSTALL_DIR="/opt/musl-cross" +COPY src/compilation/install_musl_toolchains.sh . +RUN ./install_musl_toolchains.sh + WORKDIR /app/gdb diff --git a/src/compilation/install_musl_toolchains.sh b/src/compilation/install_musl_toolchains.sh new file mode 100755 index 0000000..b1c6d3c --- /dev/null +++ b/src/compilation/install_musl_toolchains.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -e + +# Define architectures and their respective musl toolchain URLs. +ARCHS=("x86_64" "arm" "aarch64" "powerpc" "mips" "mipsel") +BASE_URL="https://musl.cc" + +if [[ -z "$MUSL_INSTALL_DIR" ]]; then + echo "MUSL_INSTALL_DIR variable has not been set!" + exit 1 +fi + +# Create install directory. +mkdir -p "$MUSL_INSTALL_DIR" +cd "$MUSL_INSTALL_DIR" + +# Download and extract each toolchain. +for ARCH in "${ARCHS[@]}"; do + TOOLCHAIN_TAR="${ARCH}-linux-musl-cross.tgz" + + # Arm has a non-generic special toolchain name :(. + if [[ "$ARCH" == "arm" ]]; then + TOOLCHAIN_TAR="arm-linux-musleabi-cross.tgz" + fi + + URL="$BASE_URL/$TOOLCHAIN_TAR" + + echo "Downloading $URL..." + wget -q --show-progress "$URL" + + echo "Extracting $TOOLCHAIN_TAR..." + tar -xzf "$TOOLCHAIN_TAR" + rm "$TOOLCHAIN_TAR" +done + +# Add the installed toolchains to the PATH. +echo "Updating PATH..." +MUSL_PATHS="" +for dir in /opt/musl-cross/*/bin; do + MUSL_PATHS="$dir:$MUSL_PATHS" +done + +echo "PATH=$MUSL_PATHS:$PATH" >> ~/.bashrc