From ae494191ff232a9ae16aa1797cae978580cfb5ec Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Mon, 5 May 2025 06:42:13 -0700 Subject: [PATCH] fall back to gcc-12 and use of system tools --- .../README.org" | 5 + .../audit_glibc_headers.sh" | 0 .../build_Linux_requisites.sh" | 0 .../build_all.sh" | 9 +- .../build_binutils.sh" | 0 .../build_binutils_requisites.sh" | 4 +- .../build_gcc_final.sh" | 0 .../build_gcc_final_requisites.sh" | 0 .../build_gcc_stage1.sh" | 0 .../build_gcc_stage1_requisites.sh" | 0 .../build_glibc.sh" | 0 .../build_glibc_bootstrap.sh" | 0 .../build_glibc_bootstrap_requisites.sh" | 0 .../build_glibc_crt.sh" | 56 +++++++ .../build_glibc_crt_requisites.sh" | 60 +++++++ .../build_glibc_headers.sh" | 0 .../build_glibc_headers_requisites.sh" | 0 .../build_glibc_requisites.sh" | 0 .../build_linux.sh" | 0 .../clean_build.sh" | 0 .../clean_dist.sh" | 0 .../clean_source.sh" | 0 .../clean_upstream.sh" | 0 .../environment.sh" | 79 ++++++--- .../project_download.sh" | 64 ++++---- .../project_extract.sh" | 52 ++++++ .../project_requisites.sh" | 155 ++++++++++++++++++ .../project_setup.sh" | 0 .../README.org" | 34 ++++ .../build_all.sh" | 21 +++ .../build_gcc.sh" | 31 ++++ .../build_gcc_final_requisites.sh" | 46 ++++++ .../clean_build.sh" | 15 ++ .../clean_dist.sh" | 31 ++++ .../clean_source.sh" | 29 ++++ .../clean_upstream.sh" | 38 +++++ .../environment.sh" | 126 ++++++++++++++ .../mv_libs_to_gcc.sh" | 39 +++++ .../project_download.sh" | 131 +++++++++++++++ .../project_extract.sh" | 52 ++++++ .../project_requisites.sh" | 155 ++++++++++++++++++ .../project_setup.sh" | 45 +++++ "script\360\237\226\211/extract_from_tar.sh" | 43 ----- 43 files changed, 1220 insertions(+), 100 deletions(-) rename "script\360\237\226\211/README.org" => "script_gcc-15\360\237\226\211/README.org" (91%) rename "script\360\237\226\211/audit_glibc_headers.sh" => "script_gcc-15\360\237\226\211/audit_glibc_headers.sh" (100%) rename "script\360\237\226\211/build_Linux_requisites.sh" => "script_gcc-15\360\237\226\211/build_Linux_requisites.sh" (100%) rename "script\360\237\226\211/build_all.sh" => "script_gcc-15\360\237\226\211/build_all.sh" (86%) rename "script\360\237\226\211/build_binutils.sh" => "script_gcc-15\360\237\226\211/build_binutils.sh" (100%) rename "script\360\237\226\211/build_binutils_requisites.sh" => "script_gcc-15\360\237\226\211/build_binutils_requisites.sh" (89%) rename "script\360\237\226\211/build_gcc_final.sh" => "script_gcc-15\360\237\226\211/build_gcc_final.sh" (100%) rename "script\360\237\226\211/build_gcc_final_requisites.sh" => "script_gcc-15\360\237\226\211/build_gcc_final_requisites.sh" (100%) rename "script\360\237\226\211/build_gcc_stage1.sh" => "script_gcc-15\360\237\226\211/build_gcc_stage1.sh" (100%) rename "script\360\237\226\211/build_gcc_stage1_requisites.sh" => "script_gcc-15\360\237\226\211/build_gcc_stage1_requisites.sh" (100%) rename "script\360\237\226\211/build_glibc.sh" => "script_gcc-15\360\237\226\211/build_glibc.sh" (100%) rename "script\360\237\226\211/build_glibc_bootstrap.sh" => "script_gcc-15\360\237\226\211/build_glibc_bootstrap.sh" (100%) rename "script\360\237\226\211/build_glibc_bootstrap_requisites.sh" => "script_gcc-15\360\237\226\211/build_glibc_bootstrap_requisites.sh" (100%) create mode 100755 "script_gcc-15\360\237\226\211/build_glibc_crt.sh" create mode 100755 "script_gcc-15\360\237\226\211/build_glibc_crt_requisites.sh" rename "script\360\237\226\211/build_glibc_headers.sh" => "script_gcc-15\360\237\226\211/build_glibc_headers.sh" (100%) rename "script\360\237\226\211/build_glibc_headers_requisites.sh" => "script_gcc-15\360\237\226\211/build_glibc_headers_requisites.sh" (100%) rename "script\360\237\226\211/build_glibc_requisites.sh" => "script_gcc-15\360\237\226\211/build_glibc_requisites.sh" (100%) rename "script\360\237\226\211/build_linux.sh" => "script_gcc-15\360\237\226\211/build_linux.sh" (100%) rename "script\360\237\226\211/clean_build.sh" => "script_gcc-15\360\237\226\211/clean_build.sh" (100%) rename "script\360\237\226\211/clean_dist.sh" => "script_gcc-15\360\237\226\211/clean_dist.sh" (100%) rename "script\360\237\226\211/clean_source.sh" => "script_gcc-15\360\237\226\211/clean_source.sh" (100%) rename "script\360\237\226\211/clean_upstream.sh" => "script_gcc-15\360\237\226\211/clean_upstream.sh" (100%) rename "script\360\237\226\211/environment.sh" => "script_gcc-15\360\237\226\211/environment.sh" (53%) rename "script\360\237\226\211/download_sources.sh" => "script_gcc-15\360\237\226\211/project_download.sh" (62%) create mode 100755 "script_gcc-15\360\237\226\211/project_extract.sh" create mode 100755 "script_gcc-15\360\237\226\211/project_requisites.sh" rename "script\360\237\226\211/setup_project.sh" => "script_gcc-15\360\237\226\211/project_setup.sh" (100%) create mode 100755 "script_gcc_min-12\360\237\226\211/README.org" create mode 100755 "script_gcc_min-12\360\237\226\211/build_all.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/build_gcc.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/build_gcc_final_requisites.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/clean_build.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/clean_dist.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/clean_source.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/clean_upstream.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/environment.sh" create mode 100644 "script_gcc_min-12\360\237\226\211/mv_libs_to_gcc.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/project_download.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/project_extract.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/project_requisites.sh" create mode 100755 "script_gcc_min-12\360\237\226\211/project_setup.sh" delete mode 100755 "script\360\237\226\211/extract_from_tar.sh" diff --git "a/script\360\237\226\211/README.org" "b/script_gcc-15\360\237\226\211/README.org" similarity index 91% rename from "script\360\237\226\211/README.org" rename to "script_gcc-15\360\237\226\211/README.org" index 233a35d..44936b8 100755 --- "a/script\360\237\226\211/README.org" +++ "b/script_gcc-15\360\237\226\211/README.org" @@ -1,4 +1,9 @@ +This was a bear to get running, and I have given up on it for now. + +It dies early in the chain at the making of glibc and the crt.o +etc. files. + # Scripts for building standalone gcc The scripts here will build a standalone gcc along with version compatible tools. diff --git "a/script\360\237\226\211/audit_glibc_headers.sh" "b/script_gcc-15\360\237\226\211/audit_glibc_headers.sh" similarity index 100% rename from "script\360\237\226\211/audit_glibc_headers.sh" rename to "script_gcc-15\360\237\226\211/audit_glibc_headers.sh" diff --git "a/script\360\237\226\211/build_Linux_requisites.sh" "b/script_gcc-15\360\237\226\211/build_Linux_requisites.sh" similarity index 100% rename from "script\360\237\226\211/build_Linux_requisites.sh" rename to "script_gcc-15\360\237\226\211/build_Linux_requisites.sh" diff --git "a/script\360\237\226\211/build_all.sh" "b/script_gcc-15\360\237\226\211/build_all.sh" similarity index 86% rename from "script\360\237\226\211/build_all.sh" rename to "script_gcc-15\360\237\226\211/build_all.sh" index 201e76f..6f55a28 100755 --- "a/script\360\237\226\211/build_all.sh" +++ "b/script_gcc-15\360\237\226\211/build_all.sh" @@ -9,11 +9,10 @@ source "$SCRIPT_DIR/environment.sh" cd "$SCRIPT_DIR" -./clean_build.sh -./setup_project.sh - -./download_sources.sh -./extract_from_tar.sh +./project_setup.sh +./project_download.sh +./project_extract.sh +./project_requisites ./build_binutils_requisites.sh ./build_binutils.sh diff --git "a/script\360\237\226\211/build_binutils.sh" "b/script_gcc-15\360\237\226\211/build_binutils.sh" similarity index 100% rename from "script\360\237\226\211/build_binutils.sh" rename to "script_gcc-15\360\237\226\211/build_binutils.sh" diff --git "a/script\360\237\226\211/build_binutils_requisites.sh" "b/script_gcc-15\360\237\226\211/build_binutils_requisites.sh" similarity index 89% rename from "script\360\237\226\211/build_binutils_requisites.sh" rename to "script_gcc-15\360\237\226\211/build_binutils_requisites.sh" index 871c68c..317378e 100755 --- "a/script\360\237\226\211/build_binutils_requisites.sh" +++ "b/script_gcc-15\360\237\226\211/build_binutils_requisites.sh" @@ -17,8 +17,8 @@ found_requisite_list=() ) for tool in "${required_tools[@]}"; do - location=$(command -v "$tool") # Fixed this part to use $tool instead of "tool" - if [ $? -eq 0 ]; then # Check if the command was successful + location=$(command -v "$tool") + if [ $? -eq 0 ]; then found_requisite_list+=("$location") else missing_requisite_list+=("$tool") diff --git "a/script\360\237\226\211/build_gcc_final.sh" "b/script_gcc-15\360\237\226\211/build_gcc_final.sh" similarity index 100% rename from "script\360\237\226\211/build_gcc_final.sh" rename to "script_gcc-15\360\237\226\211/build_gcc_final.sh" diff --git "a/script\360\237\226\211/build_gcc_final_requisites.sh" "b/script_gcc-15\360\237\226\211/build_gcc_final_requisites.sh" similarity index 100% rename from "script\360\237\226\211/build_gcc_final_requisites.sh" rename to "script_gcc-15\360\237\226\211/build_gcc_final_requisites.sh" diff --git "a/script\360\237\226\211/build_gcc_stage1.sh" "b/script_gcc-15\360\237\226\211/build_gcc_stage1.sh" similarity index 100% rename from "script\360\237\226\211/build_gcc_stage1.sh" rename to "script_gcc-15\360\237\226\211/build_gcc_stage1.sh" diff --git "a/script\360\237\226\211/build_gcc_stage1_requisites.sh" "b/script_gcc-15\360\237\226\211/build_gcc_stage1_requisites.sh" similarity index 100% rename from "script\360\237\226\211/build_gcc_stage1_requisites.sh" rename to "script_gcc-15\360\237\226\211/build_gcc_stage1_requisites.sh" diff --git "a/script\360\237\226\211/build_glibc.sh" "b/script_gcc-15\360\237\226\211/build_glibc.sh" similarity index 100% rename from "script\360\237\226\211/build_glibc.sh" rename to "script_gcc-15\360\237\226\211/build_glibc.sh" diff --git "a/script\360\237\226\211/build_glibc_bootstrap.sh" "b/script_gcc-15\360\237\226\211/build_glibc_bootstrap.sh" similarity index 100% rename from "script\360\237\226\211/build_glibc_bootstrap.sh" rename to "script_gcc-15\360\237\226\211/build_glibc_bootstrap.sh" diff --git "a/script\360\237\226\211/build_glibc_bootstrap_requisites.sh" "b/script_gcc-15\360\237\226\211/build_glibc_bootstrap_requisites.sh" similarity index 100% rename from "script\360\237\226\211/build_glibc_bootstrap_requisites.sh" rename to "script_gcc-15\360\237\226\211/build_glibc_bootstrap_requisites.sh" diff --git "a/script_gcc-15\360\237\226\211/build_glibc_crt.sh" "b/script_gcc-15\360\237\226\211/build_glibc_crt.sh" new file mode 100755 index 0000000..cb6d0b5 --- /dev/null +++ "b/script_gcc-15\360\237\226\211/build_glibc_crt.sh" @@ -0,0 +1,56 @@ +#!/bin/bash +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +# Use separate dir to avoid conflicts with headers +# this build variable should be moved to environment.sh, so that the clean scripts will work: +GLIBC_BUILD_CRT="$ROOT/build/glibc-crt" +rm -rf "$GLIBC_BUILD_CRT" +mkdir -p "$GLIBC_BUILD_CRT" +mkdir -p /home/Thomas/subu_data/developer/RT_gcc/build/glibc-crt/csu +touch /home/Thomas/subu_data/developer/RT_gcc/build/glibc-crt/csu/grcrt1.o +mkdir -p "$GLIBC_BUILD_CRT/include" +cp -r "$SYSROOT/usr/include"/* "$GLIBC_BUILD_CRT/include" + + +pushd "$GLIBC_BUILD_CRT" + + + echo "🧱 Configuring glibc for startup file build..." + + # Invoke configure explicitly + "$GLIBC_SRC/configure" \ + --prefix=/usr \ + --build="$HOST" \ + --host="$HOST" \ + --with-headers="$SYSROOT/usr/include" \ + --disable-multilib \ + --enable-static \ + --disable-shared \ + --enable-kernel=4.4.0 \ + libc_cv_slibdir="/usr/lib" + + # Ensure csu/Makefile is generated + #make -C "$GLIBC_SRC" objdir="$GLIBC_BUILD_CRT" csu/subdir_lib -j"$MAKE_JOBS" + make -C "$GLIBC_SRC" objdir="$GLIBC_BUILD_CRT" csu/crt1.o csu/crti.o csu/crtn.o -j"$MAKE_JOBS" + + # Now check and continue + if [[ ! -f "$GLIBC_BUILD_CRT/csu/Makefile" ]]; then + echo "❌ csu/Makefile still not found after configure. Startup build failed." + exit 1 + fi + + echo "🔨 Building crt objects..." + make -C "$GLIBC_SRC" objdir="$GLIBC_BUILD_CRT" csu/crt1.o csu/crti.o csu/crtn.o -j"$MAKE_JOBS" + + echo "📦 Installing crt objects to sysroot..." + install -m 644 "$GLIBC_BUILD_CRT/csu/crt1.o" "$GLIBC_BUILD_CRT/csu/crti.o" "$GLIBC_BUILD_CRT/csu/crtn.o" "$SYSROOT/usr/lib" + touch "$SYSROOT/usr/lib/libc.so" + + for f in crt1.o crti.o crtn.o; do + [[ -f "$SYSROOT/usr/lib/$f" ]] || { echo "❌ Missing $f after install"; exit 1; } + done + +popd +echo "✅ Startup files installed from isolated build dir: $GLIBC_BUILD_CRT" diff --git "a/script_gcc-15\360\237\226\211/build_glibc_crt_requisites.sh" "b/script_gcc-15\360\237\226\211/build_glibc_crt_requisites.sh" new file mode 100755 index 0000000..7875681 --- /dev/null +++ "b/script_gcc-15\360\237\226\211/build_glibc_crt_requisites.sh" @@ -0,0 +1,60 @@ +#!/bin/bash +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +echo "📦 Checking requisites for glibc crt (startup files)" + +missing=() +found=() + +# Core toolchain utilities +for tool in gcc g++ make ld as; do + if command -v "$tool" >/dev/null; then + found+=("tool: $tool at $(command -v "$tool")") + else + missing+=("missing tool: $tool") + fi +done + +# GLIBC source/csu +if [[ -d "$GLIBC_SRC/csu" ]]; then + found+=("glibc source/csu present") +else + missing+=("missing: $GLIBC_SRC/csu") +fi + +# Expected headers from sysroot +for h in gnu/libc-version.h stdio.h unistd.h; do + if [[ -f "$SYSROOT/usr/include/$h" ]]; then + found+=("header present: $h") + else + missing+=("missing header: $SYSROOT/usr/include/$h") + fi +done + +# Writable sysroot lib dir +if [[ -w "$SYSROOT/usr/lib" ]]; then + found+=("SYSROOT writable: $SYSROOT/usr/lib") +else + missing+=("not writable: $SYSROOT/usr/lib") +fi + +# Summary output +echo +if (( ${#found[@]} > 0 )); then + echo "✅ Found:" + for item in "${found[@]}"; do echo " $item"; done +fi + +echo +if (( ${#missing[@]} > 0 )); then + echo "❌ Missing:" + for item in "${missing[@]}"; do echo " $item"; done + echo + echo "❌ Requisites check failed" + exit 1 +else + echo "✅ All crt requisites satisfied" + exit 0 +fi diff --git "a/script\360\237\226\211/build_glibc_headers.sh" "b/script_gcc-15\360\237\226\211/build_glibc_headers.sh" similarity index 100% rename from "script\360\237\226\211/build_glibc_headers.sh" rename to "script_gcc-15\360\237\226\211/build_glibc_headers.sh" diff --git "a/script\360\237\226\211/build_glibc_headers_requisites.sh" "b/script_gcc-15\360\237\226\211/build_glibc_headers_requisites.sh" similarity index 100% rename from "script\360\237\226\211/build_glibc_headers_requisites.sh" rename to "script_gcc-15\360\237\226\211/build_glibc_headers_requisites.sh" diff --git "a/script\360\237\226\211/build_glibc_requisites.sh" "b/script_gcc-15\360\237\226\211/build_glibc_requisites.sh" similarity index 100% rename from "script\360\237\226\211/build_glibc_requisites.sh" rename to "script_gcc-15\360\237\226\211/build_glibc_requisites.sh" diff --git "a/script\360\237\226\211/build_linux.sh" "b/script_gcc-15\360\237\226\211/build_linux.sh" similarity index 100% rename from "script\360\237\226\211/build_linux.sh" rename to "script_gcc-15\360\237\226\211/build_linux.sh" diff --git "a/script\360\237\226\211/clean_build.sh" "b/script_gcc-15\360\237\226\211/clean_build.sh" similarity index 100% rename from "script\360\237\226\211/clean_build.sh" rename to "script_gcc-15\360\237\226\211/clean_build.sh" diff --git "a/script\360\237\226\211/clean_dist.sh" "b/script_gcc-15\360\237\226\211/clean_dist.sh" similarity index 100% rename from "script\360\237\226\211/clean_dist.sh" rename to "script_gcc-15\360\237\226\211/clean_dist.sh" diff --git "a/script\360\237\226\211/clean_source.sh" "b/script_gcc-15\360\237\226\211/clean_source.sh" similarity index 100% rename from "script\360\237\226\211/clean_source.sh" rename to "script_gcc-15\360\237\226\211/clean_source.sh" diff --git "a/script\360\237\226\211/clean_upstream.sh" "b/script_gcc-15\360\237\226\211/clean_upstream.sh" similarity index 100% rename from "script\360\237\226\211/clean_upstream.sh" rename to "script_gcc-15\360\237\226\211/clean_upstream.sh" diff --git "a/script\360\237\226\211/environment.sh" "b/script_gcc-15\360\237\226\211/environment.sh" similarity index 53% rename from "script\360\237\226\211/environment.sh" rename to "script_gcc-15\360\237\226\211/environment.sh" index 95747db..1991f40 100755 --- "a/script\360\237\226\211/environment.sh" +++ "b/script_gcc-15\360\237\226\211/environment.sh" @@ -28,6 +28,13 @@ cd $SCRIPT_DIR export GCC_VER=15.1.0 export GLIBC_VER=2.39 + # Library versions: required minimums or recommended tested versions + export GMP_VER=6.3.0 # Compatible with GCC 15, latest stable from GMP site + export MPFR_VER=4.2.1 # Latest stable, tested with GCC 15 + export MPC_VER=1.3.1 # Works with GCC 15, matches default in-tree + export ISL_VER=0.26 # Matches upstream GCC infrastructure repo + export ZSTD_VER=1.5.5 # Stable release, supported by GCC for LTO compression + #-------------------------------------------------------------------------------- # project structure @@ -60,11 +67,22 @@ cd $SCRIPT_DIR export BINUTILS_SRC="$SRC/binutils-$BINUTILS_VER" export GCC_SRC="$SRC/gcc-$GCC_VER" export GLIBC_SRC="$SRC/glibc-$GLIBC_VER" + export GMP_SRC="$SRC/gmp-$GMP_VER" + export MPFR_SRC="$SRC/mpfr-$MPFR_VER" + export MPC_SRC="$SRC/mpc-$MPC_VER" + export ISL_SRC="$SRC/isl-$ISL_VER" + export ZSTD_SRC="$SRC/zstd-$ZSTD_VER" + SOURCE_DIR_LIST=( "$LINUX_SRC" "$BINUTILS_SRC" "$GCC_SRC" "$GLIBC_SRC" + "$GMP_SRC" + "$MPFR_SRC" + "$MPC_SRC" + "$ISL_SRC" + "$ZSTD_SRC" ) # Build directories @@ -84,40 +102,59 @@ cd $SCRIPT_DIR # see top of this file for the _VER variables - # Tarballs - export LINUX_TARBALL="linux-${LINUX_VER}.tar.xz" - export BINUTILS_TARBALL="binutils-${BINUTILS_VER}.tar.gz" - export GLIBC_TARBALL="glibc-${GLIBC_VER}.tar.gz" - # Tarball Download Info (Name, URL, Destination Directory) export UPSTREAM_TARBALL_LIST=( - "$LINUX_TARBALL" - "https://cdn.kernel.org/pub/linux/kernel/v6.x/$LINUX_TARBALL" + "linux-${LINUX_VER}.tar.xz" + "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${LINUX_VER}.tar.xz" "$UPSTREAM/linux-$LINUX_VER" - - "$BINUTILS_TARBALL" - "https://ftp.gnu.org/gnu/binutils/$BINUTILS_TARBALL" + + "binutils-${BINUTILS_VER}.tar.xz" + "https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.xz" "$UPSTREAM/binutils-$BINUTILS_VER" - - "$GLIBC_TARBALL" - "https://ftp.gnu.org/gnu/libc/$GLIBC_TARBALL" + + # using repo + # "gcc-${GCC_VER}.tar.xz" + # "https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-${GCC_VER}.tar.xz" + # "$UPSTREAM/gcc-$GCC_VER" + + "glibc-${GLIBC_VER}.tar.xz" + "https://ftp.gnu.org/gnu/libc/glibc-${GLIBC_VER}.tar.xz" "$UPSTREAM/glibc-$GLIBC_VER" + + "gmp-${GMP_VER}.tar.xz" + "https://ftp.gnu.org/gnu/gmp/gmp-${GMP_VER}.tar.xz" + "$UPSTREAM/gmp-$GMP_VER" + + "mpfr-${MPFR_VER}.tar.xz" + "https://www.mpfr.org/mpfr-${MPFR_VER}/mpfr-${MPFR_VER}.tar.xz" + "$UPSTREAM/mpfr-$MPFR_VER" + + "mpc-${MPC_VER}.tar.gz" + "https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VER}.tar.gz" + "$UPSTREAM/mpc-$MPC_VER" + + "isl-${ISL_VER}.tar.bz2" +# "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${ISL_VER}.tar.bz2" + "https://libisl.sourceforge.io/isl-0.26.tar.bz2" +# "https://github.com/Meinersbur/isl/archive/refs/tags/isl-0.26.tar.gz" + "$UPSTREAM/isl-$ISL_VER" + + "zstd-${ZSTD_VER}.tar.zst" + "https://github.com/facebook/zstd/releases/download/v${ZSTD_VER}/zstd-${ZSTD_VER}.tar.zst" + "$UPSTREAM/zstd-$ZSTD_VER" ) - # Git Repositories (URL, Branch, Destination Directory) - export GCC_REPO="git://gcc.gnu.org/git/gcc.git" - export GCC_BRANCH="releases/gcc-15" - # Git Repo Info: Repository URL, Branch, Destination Directory - # Repo's expand on load so go directly into $SRC + # Git Repo Info + # Each entry is triple: Repository URL, Branch, Destination Directory + # Repos clone directly into $SRC export UPSTREAM_GIT_REPO_LIST=( - "$GCC_REPO" - "$GCC_BRANCH" + "git://gcc.gnu.org/git/gcc.git" + "releases/gcc-15" "$SRC/gcc-$GCC_VER" #currently there is no second repo ) - diff --git "a/script\360\237\226\211/download_sources.sh" "b/script_gcc-15\360\237\226\211/project_download.sh" similarity index 62% rename from "script\360\237\226\211/download_sources.sh" rename to "script_gcc-15\360\237\226\211/project_download.sh" index 2dd2dbc..0aa20bc 100755 --- "a/script\360\237\226\211/download_sources.sh" +++ "b/script_gcc-15\360\237\226\211/project_download.sh" @@ -1,7 +1,7 @@ #!/bin/bash -# This script can be run multiple times to fetch what was missed on prior invocations +# This script can be run multiple times to download what was missed on prior invocations # If there is a corrupt tarball, delete it and run this again -# Sometimes the connection test fails, then the data downloads anyway +# Sometimes a connection test will fails, then the downloads runs anyway set -uo pipefail # no `-e`, we want to continue on error @@ -26,16 +26,17 @@ check_internet_connection() { check_server_reachability() { local url=$1 - + echo "checking is reachable: $url " + # Attempt to get the HTTP response code without following redirects http_code=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 "$url") # If the HTTP code is between 200 and 299, consider it reachable if [[ "$http_code" -ge 200 && "$http_code" -lt 300 ]]; then - echo "✅ Server $url is reachable (HTTP $http_code)" + echo "✅ Server reachable (HTTP $http_code): $url " else # If not 2xx, print the status code for transparency - echo "⚠️ Server $url returned HTTP $http_code (proceeding with download anyway)" + echo "⚠️ Server HTTP $http_code not 2xx, will try anyway: $url" fi } @@ -50,46 +51,46 @@ download_file() { echo "Downloading $file from $url..." if (cd "$UPSTREAM" && curl -LO "$url"); then - if [[ -f "$UPSTREAM/$file" ]]; then - echo "✅ Successfully downloaded $file" + if file "$UPSTREAM/$file" | grep -qi 'html'; then + echo "❌ Invalid download (HTML, not archive): $file" + rm -f "$UPSTREAM/$file" + return 1 + elif [[ -f "$UPSTREAM/$file" ]]; then + echo "✅ Successfully downloaded: $file" return 0 + # Validate it's not an HTML error page else - echo "❌ $file did not appear after download" + echo "❌ Did not appear after download: $file " return 1 fi else - echo "❌ Failed to download $file" + echo "❌ Failed to download: $file" return 1 fi } -fetch_tarballs() { - echo "Starting to download tarballs..." - +download_tarballs() { i=0 while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do tarball="${UPSTREAM_TARBALL_LIST[$i]}" url="${UPSTREAM_TARBALL_LIST[$((i+1))]}" + i=$((i + 3)) if check_file_exists "$tarball"; then - echo "⚡ $tarball already exists, skipping download" - i=$((i + 3)) + echo "⚡ already exists, skipping download: $tarball " continue fi check_server_reachability "$url" if ! download_file "$tarball" "$url"; then - echo "⚠️ Skipping $tarball due to previous error" + echo "⚠️ Skipping due to previous error: $tarball " fi - i=$((i + 3)) done } -fetch_git_repos() { - echo "Starting to download Git repositories..." - +download_git_repos() { i=0 while [ $i -lt ${#UPSTREAM_GIT_REPO_LIST[@]} ]; do repo="${UPSTREAM_GIT_REPO_LIST[$i]}" @@ -97,7 +98,7 @@ fetch_git_repos() { dir="${UPSTREAM_GIT_REPO_LIST[$((i+2))]}" if [[ -d "$dir/.git" ]]; then - echo "⚡ $dir already exists, skipping git clone" + echo "⚡ Already exists, skipping git clone: $dir " i=$((i + 3)) continue fi @@ -111,15 +112,20 @@ fetch_git_repos() { done } -# Show what will be downloaded -echo "Preparing to download the following sources:" -echo " - Linux kernel: $LINUX_TARBALL" -echo " - Binutils: $BINUTILS_TARBALL" -echo " - Glibc: $GLIBC_TARBALL" -echo " - GCC source: $GCC_REPO (branch $GCC_BRANCH)" +# do the downloads check_internet_connection -fetch_tarballs -fetch_git_repos -echo "✅ download_expand_source.sh completed" +echo "Downloading tarballs:" +for ((i=0; i<${#UPSTREAM_TARBALL_LIST[@]}; i+=3)); do + echo " - ${UPSTREAM_TARBALL_LIST[i]}" +done +download_tarballs + +echo "Cloning Git repositories:" +for ((i=0; i<${#UPSTREAM_GIT_REPO_LIST[@]}; i+=3)); do + echo " - ${UPSTREAM_GIT_REPO_LIST[i]} (branch ${UPSTREAM_GIT_REPO_LIST[i+1]})" +done +download_git_repos + +echo "project_download.sh completed" diff --git "a/script_gcc-15\360\237\226\211/project_extract.sh" "b/script_gcc-15\360\237\226\211/project_extract.sh" new file mode 100755 index 0000000..e114d34 --- /dev/null +++ "b/script_gcc-15\360\237\226\211/project_extract.sh" @@ -0,0 +1,52 @@ +#!/bin/bash +# Will not extract if target already exists +# Delete any malformed extractions before running again + +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +had_error=0 +i=0 + +while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do + tarball="${UPSTREAM_TARBALL_LIST[$i]}" + i=$((i + 3)) + + src_path="$UPSTREAM/$tarball" + + # Strip compression suffix to guess subdirectory name + base_name="${tarball%%.tar.*}" # safer across .tar.gz, .tar.zst, etc. + target_dir="$SRC/$base_name" + + if [[ -d "$target_dir" ]]; then + echo "⚡ Already exists, skipping: $target_dir" + continue + fi + + if [[ ! -f "$src_path" ]]; then + echo "❌ Missing tarball: $src_path" + had_error=1 + continue + fi + + echo "tar -xf $tarball" + if ! (cd "$SRC" && tar -xf "$src_path"); then + echo "❌ Extraction failed: $tarball" + had_error=1 + continue + fi + + if [[ -d "$target_dir" ]]; then + echo "Extracted to: $target_dir" + else + echo "❌ Target not found after extraction: $target_dir" + had_error=1 + fi +done + +if [[ $had_error -eq 0 ]]; then + echo "✅ All tarballs extracted successfully" +else + echo "❌ Some extractions failed or were incomplete" +fi diff --git "a/script_gcc-15\360\237\226\211/project_requisites.sh" "b/script_gcc-15\360\237\226\211/project_requisites.sh" new file mode 100755 index 0000000..76bf171 --- /dev/null +++ "b/script_gcc-15\360\237\226\211/project_requisites.sh" @@ -0,0 +1,155 @@ +#!/bin/bash +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +echo "Checking requisites for native standalone GCC build." + +if [ ! $(command -v pkg-config) ]; then + echo "pkg-config command required for this script" + echo "Debian: sudo apt install pkg-config" + echo "Fedora: sudo dnf install pkg-config" + exit 1 +fi + + +missing_requisite_list=() +failed_pkg_config_list=() +found_reequisite_list=() + +# --- Required Script Tools (must be usable by this script itself) --- +script_tools=( + bash + awk + sed + grep +) + +echo "Checking for essential script dependencies." +for tool in "${script_tools[@]}"; do + location=$(command -v "$tool") + if [ $? -eq 0 ]; then + found_requisite_list+=("$location") + else + missing_requisite_list+=("$tool") + fi +done + +# --- Build Tools --- +build_tools=( + gcc + g++ + make + tar + gzip + bzip2 + perl + patch + diff + python3 +) + +echo "Checking for required build tools." +for tool in "${build_tools[@]}"; do + location=$(command -v "$tool") + if [ $? -eq 0 ]; then + found_requisite_list+=("$location") + else + missing_requisite_list+=("$tool") + fi +done + +# --- Libraries --- +required_pkgs=( + gmp + mpfr + mpc + isl + zstd +) + +echo "Checking for required development libraries (via pkg-config)." +for lib in "${required_pkgs[@]}"; do + if pkg-config --exists "$lib"; then + found_reequisite_list+=("library: $lib => $(pkg-config --modversion "$lib")") + else + failed_pkg_config_list+=("library: $lib") + fi +done + +# --- Source Trees --- +required_sources=( + "$GCC_SRC" + "$BINUTILS_SRC" + "$GLIBC_SRC" + "$LINUX_SRC" + "$GMP_SRC" + "$MPFR_SRC" + "$MPC_SRC" + "$ISL_SRC" + "$ZSTD_SRC" +) + +echo "Checking for required source directories." +echo "These will be installed by download_sources.sh and extract_from_tar.sh" +for src in "${required_sources[@]}"; do + if [[ -d "$src" && "$(ls -A "$src")" ]]; then + found_reequisite_list+=("source: $src") + else + missing_requisite_list+=("source: $src") + fi +done + +# --- Python Modules (non-fatal) --- +optional_py_modules=(re sys os json gzip pathlib shutil time tempfile) + +echo "Checking optional Python3 modules." +for mod in "${optional_py_modules[@]}"; do + if python3 -c "import $mod" &>/dev/null; then + found_reequisite_list+=("python: module $mod") + else + missing_requisite_list+=("python (optional): module $mod") + fi +done + +echo +echo "Summary:" +echo "--------" + +# Found tools +for item in "${found_reequisite_list[@]}"; do + echo " found: $item" +done + +# Missing essentials +for item in "${missing_requisite_list[@]:-}"; do + echo "❌ missing required tool: $item" +done + +# pkg-config failures +for item in "${failed_pkg_config_list[@]:-}"; do + echo "⚠️ pkg-config could not find: $item" +done + +# Final verdict +echo + +if [[ ${#missing_requisite_list[@]} -eq 0 && ${#failed_pkg_config_list[@]} -eq 0 ]]; then + echo "✅ All required tools and libraries found." +else + echo "❌ Some requisites are missing." + + if [[ ${#failed_pkg_config_list[@]} -gt 0 ]]; then + echo + echo "Note: pkg-config did not find some libraries:" + echo " These are expected if you are building them from source:" + echo " - mpc" + echo " - isl" + echo " - zstd" + echo " If not, consider installing the corresponding dev packages." + echo " Debian: sudo apt install libmpc-dev libisl-dev libzstd-dev" + echo " Fedora: sudo dnf install libmpc-devel isl-devel libzstd-devel" + fi +fi + + diff --git "a/script\360\237\226\211/setup_project.sh" "b/script_gcc-15\360\237\226\211/project_setup.sh" similarity index 100% rename from "script\360\237\226\211/setup_project.sh" rename to "script_gcc-15\360\237\226\211/project_setup.sh" diff --git "a/script_gcc_min-12\360\237\226\211/README.org" "b/script_gcc_min-12\360\237\226\211/README.org" new file mode 100755 index 0000000..44936b8 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/README.org" @@ -0,0 +1,34 @@ + +This was a bear to get running, and I have given up on it for now. + +It dies early in the chain at the making of glibc and the crt.o +etc. files. + +# Scripts for building standalone gcc + +The scripts here will build a standalone gcc along with version compatible tools. + +There is a lot more to a gcc than one might imagine. It was developed as though an integral part of Unix. Hence, the standalone build has top level directories with many things in them, in parallel to the top level directories a person would find on a Unix system. + +## .gitignore + +* If there is no top level `.gitignore`, `setup_project.sh` will create one. +* The synthesized `.gitignore` references itself, so it will not get checked in. +* No script, including`clean_dist.sh`, will delete an existing `.gitignore`. + +## Clean + +* clean_build.sh - for saving space after the build is done. The build scripts are idempotent, so in an ideal world this need not be run to do a rebuild. + +* clean_dist.sh - with on exception, this will delete everything that was synthesized. The one exception is that .gitignore is moved to the tmp directory so as to preserve any changes a user might have been made, and the contents of the tmp directory are not removed. + +* clean_tmp.sh - wipes clean all contents of the temporary directory. + +## Setup + +* setup_project.sh - makes the directory structure for the build, creates a `tmp/` directory under the project. If it does not already exist, creates a .gitignore file with all the created directories listed. + +## Download + +* download_upstream_sources.sh - goes to the Internet, fetches all the sources that have not already been fetched. Then expands the sources into the proper sub-directory under `source/1. + diff --git "a/script_gcc_min-12\360\237\226\211/build_all.sh" "b/script_gcc_min-12\360\237\226\211/build_all.sh" new file mode 100755 index 0000000..dbb890c --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/build_all.sh" @@ -0,0 +1,21 @@ +#!/bin/bash +set -euo pipefail + +cd "$(dirname "$0")" +SCRIPT_DIR="$PWD" + +echo "loading environment" +source "$SCRIPT_DIR/environment.sh" + +cd "$SCRIPT_DIR" + +./project_setup.sh +./project_download.sh +./project_extract.sh +./project_requisites.sh + +./mv_libs_to_gcc.sh +./build_gcc.sh + +echo "Toolchain build complete" +"$TOOLCHAIN/bin/gcc" --version diff --git "a/script_gcc_min-12\360\237\226\211/build_gcc.sh" "b/script_gcc_min-12\360\237\226\211/build_gcc.sh" new file mode 100755 index 0000000..1e6ca88 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/build_gcc.sh" @@ -0,0 +1,31 @@ +#!/bin/bash +set -euo pipefail + +# Load environment +source "$(dirname "$0")/environment.sh" + +echo "🔧 Starting final GCC build..." + +mkdir -p "$GCC_BUILD_FINAL" +pushd "$GCC_BUILD_FINAL" + +"$GCC_SRC/configure" \ + --prefix="$TOOLCHAIN" \ + --with-sysroot="$SYSROOT" \ + --with-native-system-header-dir=/usr/include \ + --target="$TARGET" \ + --enable-languages=c,c++ \ + --enable-threads=posix \ + --enable-shared \ + --disable-nls \ + --disable-multilib \ + --disable-bootstrap \ + --disable-libsanitizer \ + $CONFIGURE_FLAGS + +$MAKE +$MAKE install + +popd + +echo "✅ Final GCC installed to $TOOLCHAIN/bin" diff --git "a/script_gcc_min-12\360\237\226\211/build_gcc_final_requisites.sh" "b/script_gcc_min-12\360\237\226\211/build_gcc_final_requisites.sh" new file mode 100755 index 0000000..5d36697 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/build_gcc_final_requisites.sh" @@ -0,0 +1,46 @@ +#!/bin/bash +set -euo pipefail + +# Load shared environment +source "$(dirname "$0")/environment.sh" + +echo "📦 Checking prerequisites for final GCC..." + +# Required host tools +required_tools=(gcc g++ make curl tar gawk bison flex) +missing_tools=() + +for tool in "${required_tools[@]}"; do + if ! type -P "$tool" > /dev/null; then + missing_tools+=("$tool") + fi +done + +if (( ${#missing_tools[@]} )); then + echo "❌ Missing required tools: ${missing_tools[*]}" + exit 1 +fi + +# Check for libc headers and startup objects in sysroot +required_headers=("$SYSROOT/include/stdio.h") +required_crt_objects=( + "$SYSROOT/lib/crt1.o" + "$SYSROOT/lib/crti.o" + "$SYSROOT/lib/crtn.o" +) + +for hdr in "${required_headers[@]}"; do + if [ ! -f "$hdr" ]; then + echo "❌ C library header missing: $hdr" + exit 1 + fi +done + +for obj in "${required_crt_objects[@]}"; do + if [ ! -f "$obj" ]; then + echo "❌ Startup object missing: $obj" + exit 1 + fi +done + +echo "✅ Prerequisites for final GCC met." diff --git "a/script_gcc_min-12\360\237\226\211/clean_build.sh" "b/script_gcc_min-12\360\237\226\211/clean_build.sh" new file mode 100755 index 0000000..7c9bca3 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/clean_build.sh" @@ -0,0 +1,15 @@ +#!/bin/bash +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +echo "🧹 Cleaning build directories..." + +for dir in "${BUILD_DIR_LIST[@]}"; do + if [[ -d "$dir" ]]; then + echo "rm -rf $dir" + rm -rf "$dir" + fi +done + +echo "✅ Build directories cleaned." diff --git "a/script_gcc_min-12\360\237\226\211/clean_dist.sh" "b/script_gcc_min-12\360\237\226\211/clean_dist.sh" new file mode 100755 index 0000000..009e01e --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/clean_dist.sh" @@ -0,0 +1,31 @@ +#!/bin/bash +set -euo pipefail + +echo "removing: build, source, upstream, and project directories" + +source "$(dirname "$0")/environment.sh" + +# Remove build +# + "./clean_build.sh" + ! ! rmdir "$BUILD_DIR" >& /dev/null && echo "rmdir $BUILD_DIR" + +# Remove source +# note that repos are removed with clean_upstream +# + "./clean_source.sh" + "./clean_upstream.sh" + + ! ! rmdir "$SRC" >& /dev/null && echo "rmdir $SRC" + ! ! rmdir "$UPSTREAM" >& /dev/null && echo "rmdir $UPSTREAM" + +# Remove project directories +# + for dir in "${PROJECT_SUBDIR_LIST[@]}" "${PROJECT_DIR_LIST[@]}"; do + if [[ -d "$dir" ]]; then + echo "rm -rf $dir" + ! rm -rf "$dir" && echo "could not remove $dir" + fi + done + +echo "✅ clean_dist.sh" diff --git "a/script_gcc_min-12\360\237\226\211/clean_source.sh" "b/script_gcc_min-12\360\237\226\211/clean_source.sh" new file mode 100755 index 0000000..2f5beb0 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/clean_source.sh" @@ -0,0 +1,29 @@ +#!/bin/bash +# removes project tarball expansions from source/ +# git repos are part of `upstream` so are not removed + +set -euo pipefail + + +source "$(dirname "$0")/environment.sh" + +i=0 +while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do + tarball="${UPSTREAM_TARBALL_LIST[$i]}" + # skip url + i=$((i + 1)) + # skip explicit dest dir + i=$((i + 1)) + + base_name="${tarball%.tar.*}" + dir="$SRC/$base_name" + + if [[ -d "$dir" ]]; then + echo "rm -rf $dir" + rm -rf "$dir" + fi + + i=$((i + 1)) +done + +echo "✅ clean_source.sh" diff --git "a/script_gcc_min-12\360\237\226\211/clean_upstream.sh" "b/script_gcc_min-12\360\237\226\211/clean_upstream.sh" new file mode 100755 index 0000000..50e8d98 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/clean_upstream.sh" @@ -0,0 +1,38 @@ +#!/bin/bash +# run this to force repeat of the downloads +# removes project tarballs from upstream/ +# removes project repos from source/ +# does not remove non-project files + +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +# Remove tarballs +i=0 +while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do + tarball="${UPSTREAM_TARBALL_LIST[$i]}" + path="$UPSTREAM/$tarball" + + if [[ -f "$path" ]]; then + echo "rm $path" + rm "$path" + fi + + i=$((i + 3)) +done + +# Remove Git repositories +i=0 +while [ $i -lt ${#UPSTREAM_GIT_REPO_LIST[@]} ]; do + dir="${UPSTREAM_GIT_REPO_LIST[$((i+2))]}" + + if [[ -d "$dir" ]]; then + echo "rm -rf $dir" + rm -rf "$dir" + fi + + i=$((i + 3)) +done + +echo "✅ clean_upstream.sh" diff --git "a/script_gcc_min-12\360\237\226\211/environment.sh" "b/script_gcc_min-12\360\237\226\211/environment.sh" new file mode 100755 index 0000000..49ee8c4 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/environment.sh" @@ -0,0 +1,126 @@ +# === environment.sh === +# Source this file in each build script to ensure consistent paths and settings + +echo "ROOT: $ROOT" +cd $SCRIPT_DIR + +#-------------------------------------------------------------------------------- +# tools + + # machine target + export HOST=$(gcc -dumpmachine) + + export MAKE_JOBS=$(getconf _NPROCESSORS_ONLN) + export MAKE=make + + # Compiler path prefixes + export CC_FOR_BUILD=$(command -v gcc) + export CXX_FOR_BUILD=$(command -v g++) + +#-------------------------------------------------------------------------------- +# Tool and library versions (optimized build with Graphite and LTO compression) + + export GCC_VER=12.2.0 # GCC version to build + export GMP_VER=6.2.1 # Sufficient for GCC 12.2 + export MPFR_VER=4.1.0 # Stable version compatible with GCC 12.2 + export MPC_VER=1.2.1 # Recommended for GCC 12.2 + export ISL_VER=0.24 # GCC 12.x infra uses this; don't use 0.26+ unless patched + export ZSTD_VER=1.5.5 # zstd compression for LTO bytecode + +#-------------------------------------------------------------------------------- +# project structure + + # temporary directory + export TMPDIR="$ROOT/tmp" + + # Project directories + export SYSROOT="$ROOT/sysroot" + export TOOLCHAIN="$ROOT/toolchain" + export BUILD_DIR="$ROOT/build" + export LOGDIR="$ROOT/log" + export UPSTREAM="$ROOT/upstream" + export SRC=$ROOT/source + + # Synthesized directory lists + PROJECT_DIR_LIST=( + "$LOGDIR" + "$SYSROOT" "$TOOLCHAIN" "$BUILD_DIR" + "$UPSTREAM" "$SRC" + ) + # list these in the order they can be deleted + PROJECT_SUBDIR_LIST=( + "$SYSROOT/usr/lib" + "$SYSROOT/lib" + "$SYSROOT/usr/include" + ) + +#-------------------------------------------------------------------------------- +# upstream -> local stuff + + # see top of this file for the _VER variables + + # Tarball Download Info (Name, URL, Destination Directory) + export UPSTREAM_TARBALL_LIST=( + "gmp-${GMP_VER}.tar.xz" + "https://ftp.gnu.org/gnu/gmp/gmp-${GMP_VER}.tar.xz" + "$UPSTREAM/gmp-$GMP_VER" + + "mpfr-${MPFR_VER}.tar.xz" + "https://www.mpfr.org/mpfr-${MPFR_VER}/mpfr-${MPFR_VER}.tar.xz" + "$UPSTREAM/mpfr-$MPFR_VER" + + "mpc-${MPC_VER}.tar.gz" + "https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VER}.tar.gz" + "$UPSTREAM/mpc-$MPC_VER" + + "isl-${ISL_VER}.tar.bz2" + "https://libisl.sourceforge.io/isl-${ISL_VER}.tar.bz2" + "$UPSTREAM/isl-$ISL_VER" + + "zstd-${ZSTD_VER}.tar.zst" + "https://github.com/facebook/zstd/releases/download/v${ZSTD_VER}/zstd-${ZSTD_VER}.tar.zst" + "$UPSTREAM/zstd-$ZSTD_VER" + ) + + # Git Repo Info + # Each entry is triple: Repository URL, Branch, Destination Directory + export UPSTREAM_GIT_REPO_LIST=( + + "git://gcc.gnu.org/git/gcc.git" + "releases/gcc-12" + "$SRC/gcc-$GCC_VER" + + #no second repo entry + ) + +#-------------------------------------------------------------------------------- +# source + + # Source directories + export GCC_SRC="$SRC/gcc-$GCC_VER" + export GMP_SRC="$SRC/gmp-$GMP_VER" + export MPFR_SRC="$SRC/mpfr-$MPFR_VER" + export MPC_SRC="$SRC/mpc-$MPC_VER" + export ISL_SRC="$SRC/isl-$ISL_VER" + export ZSTD_SRC="$SRC/zstd-$ZSTD_VER" + + SOURCE_DIR_LIST=( + "$GCC_SRC" + "$GMP_SRC" + "$MPFR_SRC" + "$MPC_SRC" + "$ISL_SRC" + "$ZSTD_SRC" + ) + +#-------------------------------------------------------------------------------- +# build + + # Build directories + export GCC_BUILD="$BUILD_DIR/gcc" + BUILD_DIR_LIST=( + "$GCC_BUILD" + ) + + + diff --git "a/script_gcc_min-12\360\237\226\211/mv_libs_to_gcc.sh" "b/script_gcc_min-12\360\237\226\211/mv_libs_to_gcc.sh" new file mode 100644 index 0000000..9e4b5e5 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/mv_libs_to_gcc.sh" @@ -0,0 +1,39 @@ +#!/bin/bash +# mv_libs_to_gcc.sh +# Move prerequisite libraries into the GCC source tree, replacing stale copies. +# This script can be run multiple times for incremental moves when more sources become available. + +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +LIB_LIST=( + "gmp" "$GMP_SRC" + "mpfr" "$MPFR_SRC" + "mpc" "$MPC_SRC" + "isl" "$ISL_SRC" + "zstd" "$ZSTD_SRC" +) + +i=0 +while [ $i -lt ${#LIB_LIST[@]} ]; do + lib="${LIB_LIST[$i]}" + src="${LIB_LIST[$((i + 1))]}" + dest="$GCC_SRC/$lib" + i=$((i + 2)) + + if [[ ! -d "$src" ]]; then + echo "Source not found, skipping: $src" + continue + fi + + if [[ -d "$dest" ]]; then + echo "Removing stale: $dest" + rm -rf "$dest" + fi + + echo "mv $src $dest" + mv "$src" "$dest" +done + +echo "completed mv_libs_to_gcc.sh" diff --git "a/script_gcc_min-12\360\237\226\211/project_download.sh" "b/script_gcc_min-12\360\237\226\211/project_download.sh" new file mode 100755 index 0000000..0aa20bc --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/project_download.sh" @@ -0,0 +1,131 @@ +#!/bin/bash +# This script can be run multiple times to download what was missed on prior invocations +# If there is a corrupt tarball, delete it and run this again +# Sometimes a connection test will fails, then the downloads runs anyway + +set -uo pipefail # no `-e`, we want to continue on error + +source "$(dirname "$0")/environment.sh" + +check_internet_connection() { + echo "🌐 Checking internet connection..." + # Use a quick connection check without blocking the whole script + if ! curl -s --connect-timeout 5 https://google.com > /dev/null; then + echo "⚠️ No internet connection detected (proceeding with download anyway)" + else + echo "✅ Internet connection detected" + fi +} + +# check_server_reachability() { +# local url=$1 +# if ! curl -s --head "$url" | head -n 1 | grep -q "HTTP/1.1 200 OK"; then +# echo "⚠️ Cannot reach $url (proceeding with download anyway)" +# fi +# } + +check_server_reachability() { + local url=$1 + echo "checking is reachable: $url " + + # Attempt to get the HTTP response code without following redirects + http_code=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 "$url") + + # If the HTTP code is between 200 and 299, consider it reachable + if [[ "$http_code" -ge 200 && "$http_code" -lt 300 ]]; then + echo "✅ Server reachable (HTTP $http_code): $url " + else + # If not 2xx, print the status code for transparency + echo "⚠️ Server HTTP $http_code not 2xx, will try anyway: $url" + fi +} + +check_file_exists() { + local file=$1 + [[ -f "$UPSTREAM/$file" ]] +} + +download_file() { + local file=$1 + local url=$2 + + echo "Downloading $file from $url..." + if (cd "$UPSTREAM" && curl -LO "$url"); then + if file "$UPSTREAM/$file" | grep -qi 'html'; then + echo "❌ Invalid download (HTML, not archive): $file" + rm -f "$UPSTREAM/$file" + return 1 + elif [[ -f "$UPSTREAM/$file" ]]; then + echo "✅ Successfully downloaded: $file" + return 0 + # Validate it's not an HTML error page + else + echo "❌ Did not appear after download: $file " + return 1 + fi + else + echo "❌ Failed to download: $file" + return 1 + fi +} + +download_tarballs() { + i=0 + while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do + tarball="${UPSTREAM_TARBALL_LIST[$i]}" + url="${UPSTREAM_TARBALL_LIST[$((i+1))]}" + i=$((i + 3)) + + if check_file_exists "$tarball"; then + echo "⚡ already exists, skipping download: $tarball " + continue + fi + + check_server_reachability "$url" + + if ! download_file "$tarball" "$url"; then + echo "⚠️ Skipping due to previous error: $tarball " + fi + + done +} + +download_git_repos() { + i=0 + while [ $i -lt ${#UPSTREAM_GIT_REPO_LIST[@]} ]; do + repo="${UPSTREAM_GIT_REPO_LIST[$i]}" + branch="${UPSTREAM_GIT_REPO_LIST[$((i+1))]}" + dir="${UPSTREAM_GIT_REPO_LIST[$((i+2))]}" + + if [[ -d "$dir/.git" ]]; then + echo "⚡ Already exists, skipping git clone: $dir " + i=$((i + 3)) + continue + fi + + echo "Cloning $repo into $dir..." + if ! git clone --branch "$branch" "$repo" "$dir"; then + echo "❌ Failed to clone $repo → $dir" + fi + + i=$((i + 3)) + done +} + +# do the downloads + +check_internet_connection + +echo "Downloading tarballs:" +for ((i=0; i<${#UPSTREAM_TARBALL_LIST[@]}; i+=3)); do + echo " - ${UPSTREAM_TARBALL_LIST[i]}" +done +download_tarballs + +echo "Cloning Git repositories:" +for ((i=0; i<${#UPSTREAM_GIT_REPO_LIST[@]}; i+=3)); do + echo " - ${UPSTREAM_GIT_REPO_LIST[i]} (branch ${UPSTREAM_GIT_REPO_LIST[i+1]})" +done +download_git_repos + +echo "project_download.sh completed" diff --git "a/script_gcc_min-12\360\237\226\211/project_extract.sh" "b/script_gcc_min-12\360\237\226\211/project_extract.sh" new file mode 100755 index 0000000..e114d34 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/project_extract.sh" @@ -0,0 +1,52 @@ +#!/bin/bash +# Will not extract if target already exists +# Delete any malformed extractions before running again + +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +had_error=0 +i=0 + +while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do + tarball="${UPSTREAM_TARBALL_LIST[$i]}" + i=$((i + 3)) + + src_path="$UPSTREAM/$tarball" + + # Strip compression suffix to guess subdirectory name + base_name="${tarball%%.tar.*}" # safer across .tar.gz, .tar.zst, etc. + target_dir="$SRC/$base_name" + + if [[ -d "$target_dir" ]]; then + echo "⚡ Already exists, skipping: $target_dir" + continue + fi + + if [[ ! -f "$src_path" ]]; then + echo "❌ Missing tarball: $src_path" + had_error=1 + continue + fi + + echo "tar -xf $tarball" + if ! (cd "$SRC" && tar -xf "$src_path"); then + echo "❌ Extraction failed: $tarball" + had_error=1 + continue + fi + + if [[ -d "$target_dir" ]]; then + echo "Extracted to: $target_dir" + else + echo "❌ Target not found after extraction: $target_dir" + had_error=1 + fi +done + +if [[ $had_error -eq 0 ]]; then + echo "✅ All tarballs extracted successfully" +else + echo "❌ Some extractions failed or were incomplete" +fi diff --git "a/script_gcc_min-12\360\237\226\211/project_requisites.sh" "b/script_gcc_min-12\360\237\226\211/project_requisites.sh" new file mode 100755 index 0000000..76bf171 --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/project_requisites.sh" @@ -0,0 +1,155 @@ +#!/bin/bash +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +echo "Checking requisites for native standalone GCC build." + +if [ ! $(command -v pkg-config) ]; then + echo "pkg-config command required for this script" + echo "Debian: sudo apt install pkg-config" + echo "Fedora: sudo dnf install pkg-config" + exit 1 +fi + + +missing_requisite_list=() +failed_pkg_config_list=() +found_reequisite_list=() + +# --- Required Script Tools (must be usable by this script itself) --- +script_tools=( + bash + awk + sed + grep +) + +echo "Checking for essential script dependencies." +for tool in "${script_tools[@]}"; do + location=$(command -v "$tool") + if [ $? -eq 0 ]; then + found_requisite_list+=("$location") + else + missing_requisite_list+=("$tool") + fi +done + +# --- Build Tools --- +build_tools=( + gcc + g++ + make + tar + gzip + bzip2 + perl + patch + diff + python3 +) + +echo "Checking for required build tools." +for tool in "${build_tools[@]}"; do + location=$(command -v "$tool") + if [ $? -eq 0 ]; then + found_requisite_list+=("$location") + else + missing_requisite_list+=("$tool") + fi +done + +# --- Libraries --- +required_pkgs=( + gmp + mpfr + mpc + isl + zstd +) + +echo "Checking for required development libraries (via pkg-config)." +for lib in "${required_pkgs[@]}"; do + if pkg-config --exists "$lib"; then + found_reequisite_list+=("library: $lib => $(pkg-config --modversion "$lib")") + else + failed_pkg_config_list+=("library: $lib") + fi +done + +# --- Source Trees --- +required_sources=( + "$GCC_SRC" + "$BINUTILS_SRC" + "$GLIBC_SRC" + "$LINUX_SRC" + "$GMP_SRC" + "$MPFR_SRC" + "$MPC_SRC" + "$ISL_SRC" + "$ZSTD_SRC" +) + +echo "Checking for required source directories." +echo "These will be installed by download_sources.sh and extract_from_tar.sh" +for src in "${required_sources[@]}"; do + if [[ -d "$src" && "$(ls -A "$src")" ]]; then + found_reequisite_list+=("source: $src") + else + missing_requisite_list+=("source: $src") + fi +done + +# --- Python Modules (non-fatal) --- +optional_py_modules=(re sys os json gzip pathlib shutil time tempfile) + +echo "Checking optional Python3 modules." +for mod in "${optional_py_modules[@]}"; do + if python3 -c "import $mod" &>/dev/null; then + found_reequisite_list+=("python: module $mod") + else + missing_requisite_list+=("python (optional): module $mod") + fi +done + +echo +echo "Summary:" +echo "--------" + +# Found tools +for item in "${found_reequisite_list[@]}"; do + echo " found: $item" +done + +# Missing essentials +for item in "${missing_requisite_list[@]:-}"; do + echo "❌ missing required tool: $item" +done + +# pkg-config failures +for item in "${failed_pkg_config_list[@]:-}"; do + echo "⚠️ pkg-config could not find: $item" +done + +# Final verdict +echo + +if [[ ${#missing_requisite_list[@]} -eq 0 && ${#failed_pkg_config_list[@]} -eq 0 ]]; then + echo "✅ All required tools and libraries found." +else + echo "❌ Some requisites are missing." + + if [[ ${#failed_pkg_config_list[@]} -gt 0 ]]; then + echo + echo "Note: pkg-config did not find some libraries:" + echo " These are expected if you are building them from source:" + echo " - mpc" + echo " - isl" + echo " - zstd" + echo " If not, consider installing the corresponding dev packages." + echo " Debian: sudo apt install libmpc-dev libisl-dev libzstd-dev" + echo " Fedora: sudo dnf install libmpc-devel isl-devel libzstd-devel" + fi +fi + + diff --git "a/script_gcc_min-12\360\237\226\211/project_setup.sh" "b/script_gcc_min-12\360\237\226\211/project_setup.sh" new file mode 100755 index 0000000..31516dc --- /dev/null +++ "b/script_gcc_min-12\360\237\226\211/project_setup.sh" @@ -0,0 +1,45 @@ +#!/bin/bash +set -euo pipefail + +source "$(dirname "$0")/environment.sh" + +# Create top-level project directories +for dir in "${PROJECT_DIR_LIST[@]}"; do + echo "mkdir -p $dir" + mkdir -p "$dir" +done + +# Create subdirectories within SYSROOT +for subdir in "${PROJECT_SUBDIR_LIST[@]}"; do + echo "mkdir -p $subdir" + mkdir -p "$subdir" +done + +# Ensure TMPDIR exists and add .gitignore +if [[ ! -d "$TMPDIR" ]]; then + echo "mkdir -p $TMPDIR" + mkdir -p "$TMPDIR" + + echo "echo $TMPDIR/ > $TMPDIR/.gitignore" + echo "$TMPDIR/" > "$TMPDIR/.gitignore" +else + echo "⚠️ TMPDIR already exists" +fi + +# Create root-level .gitignore if missing +if [[ -f "$ROOT/.gitignore" ]]; then + echo "⚠️ $ROOT/.gitignore already exists" +else + echo "create $ROOT/.gitignore" + { + echo "# Ignore synthesized top-level directories" + for dir in "${PROJECT_DIR_LIST[@]}"; do + rel_path="${dir#$ROOT/}" + echo "/$rel_path" + done + echo "# Ignore synthesized files" + echo "/.gitignore" + } > "$ROOT/.gitignore" +fi + +echo "✅ setup_project.sh" diff --git "a/script\360\237\226\211/extract_from_tar.sh" "b/script\360\237\226\211/extract_from_tar.sh" deleted file mode 100755 index 5d787de..0000000 --- "a/script\360\237\226\211/extract_from_tar.sh" +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -euo pipefail - -source "$(dirname "$0")/environment.sh" - -i=0 -while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do - tarball="${UPSTREAM_TARBALL_LIST[$i]}" - # url is unused - src_path="$UPSTREAM/$tarball" - - # Strip compression suffix to guess subdirectory name - base_name="${tarball%.tar.*}" - target_dir="$SRC/$base_name" - - if [[ -d "$target_dir" ]]; then - echo "⚠️ $target_dir already exists, skipping" - i=$((i + 3)) - continue - fi - - if [[ ! -f "$src_path" ]]; then - echo "❌ Missing tarball: $src_path" - i=$((i + 3)) - continue - fi - - echo "tar -xf $tarball → $SRC" - ( - cd "$SRC" - tar -xf "$src_path" - ) - - if [[ -d "$target_dir" ]]; then - echo "✅ Extracted to $target_dir" - else - echo "❌ Expected $target_dir not found after extraction" - fi - - i=$((i + 3)) -done - -echo "✅ extract_from_tar.sh" -- 2.20.1