diff options
| author | Peter Fors <peter.fors@mindkiller.com> | 2025-10-28 17:46:44 +0100 |
|---|---|---|
| committer | Peter Fors <peter.fors@mindkiller.com> | 2025-10-28 17:46:44 +0100 |
| commit | 9ab02b59d34d670197ef590fa6c1646b0618a5b9 (patch) | |
| tree | 79aef1d9ca1d6393dde589a130f4d823a89d09ea | |
| parent | 9ee76c20c0d093d5adac2dcc3b275b53b879c369 (diff) | |
add bootstrap.sh to build a local version of gcc 5.2.0 for now
| -rwxr-xr-x | bootstrap.sh | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..22c96ff --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# bootstrap.sh - Build project-local GCC toolchain + +set -e + +GCC_VERSION=15.2.0 # Use latest stable release +TOOLCHAIN_DIR="$(pwd)/toolchain" +GCC_PREFIX="${TOOLCHAIN_DIR}/gcc-${GCC_VERSION}" + +# Check if already built +if [ -f "${GCC_PREFIX}/bin/gcc" ]; then + echo "GCC ${GCC_VERSION} already built in ${GCC_PREFIX}" + echo "To rebuild, remove ${TOOLCHAIN_DIR} and re-run" + exit 0 +fi + +# Check system dependencies +check_deps() { + local missing="" + for cmd in make tar wget as ld; do + if ! command -v $cmd &> /dev/null; then + missing="$missing $cmd" + fi + done + + # Check for required libraries + for lib in isl mpc; do + if ! ldconfig -p | grep -q "lib${lib}\.so"; then + missing="$missing lib${lib}" + fi + done + + if [ -n "$missing" ]; then + echo "ERROR: Missing system dependencies:$missing" + echo "On Arch: sudo pacman -S base-devel binutils wget libisl libmpc" + exit 1 + fi +} + +check_deps + +echo "Building GCC ${GCC_VERSION} in ${GCC_PREFIX}" +echo "This will take ~3-4 minutes on an AMD 7950X..." + +mkdir -p "${TOOLCHAIN_DIR}" +cd "${TOOLCHAIN_DIR}" + + +# Download GCC sources +if [ ! -f "gcc-${GCC_VERSION}.tar.xz" ]; then + echo "Downloading GCC ${GCC_VERSION}..." + # Use mirror redirect (usually faster) + wget "https://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz" \ + || wget "https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz" +fi + +# Extract +if [ ! -d "gcc-${GCC_VERSION}" ]; then + echo "Extracting GCC sources..." + tar xf "gcc-${GCC_VERSION}.tar.xz" +fi + +cd "gcc-${GCC_VERSION}" + +# Download prerequisites (GMP, MPFR, MPC, ISL) +echo "Downloading GCC prerequisites..." +./contrib/download_prerequisites + +# Build +mkdir -p build +cd build + +echo "Configuring GCC..." +../configure \ + --prefix="${GCC_PREFIX}" \ + --enable-languages=c \ + --with-system-zlib \ + --with-linker-hash-style=gnu \ + --disable-multilib \ + --disable-bootstrap \ + --disable-libsanitizer \ + --disable-libssp \ + --disable-werror \ + --disable-cet \ + --disable-default-pie \ + --disable-default-ssp \ + --enable-lto + +echo "Building GCC (using $(nproc) cores)..." +make -j$(nproc) + +echo "Installing GCC to ${GCC_PREFIX}..." +make install + +echo "" +echo "======================================" +echo "GCC ${GCC_VERSION} built successfully!" +echo "======================================" +echo "Toolchain installed in: ${GCC_PREFIX}" +echo "" +echo "To use it, just run: ./build.sh or ./Bench.sh" + |
