--- /dev/null
+
+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.
+
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π Auditing glibc build state..."
+
+declare -a missing
+declare -a present
+
+# GLIBC_BUILD sanity
+[[ -d "$GLIBC_BUILD" ]] && present+=("GLIBC_BUILD exists: $GLIBC_BUILD") || missing+=("GLIBC_BUILD missing")
+
+# Check for Makefile
+if [[ -s "$GLIBC_BUILD/Makefile" ]]; then
+ present+=("Makefile exists and non-empty")
+else
+ missing+=("Makefile missing or empty in $GLIBC_BUILD")
+fi
+
+# Check bits/stdio_lim.h
+if [[ -f "$GLIBC_BUILD/bits/stdio_lim.h" ]]; then
+ present+=("bits/stdio_lim.h exists (post-header install marker)")
+else
+ missing+=("bits/stdio_lim.h missing β make install-headers likely incomplete")
+fi
+
+# Check csu/Makefile
+if [[ -f "$GLIBC_BUILD/csu/Makefile" ]]; then
+ present+=("csu/Makefile exists")
+ grep -q 'crt1\.o' "$GLIBC_BUILD/csu/Makefile" \
+ && present+=("csu/Makefile defines crt1.o") \
+ || missing+=("csu/Makefile missing rule for crt1.o")
+else
+ missing+=("csu/Makefile missing")
+fi
+
+# Show report
+echo "β
Present:"
+for p in "${present[@]}"; do echo " $p"; done
+
+echo
+if (( ${#missing[@]} )); then
+ echo "β Missing:"
+ for m in "${missing[@]}"; do echo " $m"; done
+ exit 1
+else
+ echo "π All bootstrap prerequisites are in place"
+ exit 0
+fi
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π¦ Checking requisites for Linux kernel headers build."
+
+missing_requisite_list=()
+found_requisite_list=()
+
+# tools required for build
+#
+required_tools=(
+ "gcc"
+ "g++"
+ "make"
+)
+
+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
+ found_requisite_list+=("$location")
+ else
+ missing_requisite_list+=("$tool")
+ fi
+done
+
+# source code required for build
+#
+if [ -d "$LINUX_SRC" ] && [ "$(ls -A "$LINUX_SRC")" ]; then
+ found_requisite_list+=("$LINUX_SRC")
+else
+ missing_requisite_list+=("$LINUX_SRC")
+fi
+
+# print requisites found
+#
+if (( ${#found_requisite_list[@]} != 0 )); then
+ echo "found:"
+ for found_requisite in "${found_requisite_list[@]}"; do
+ echo " $found_requisite"
+ done
+fi
+
+# print requisites missing
+#
+if (( ${#missing_requisite_list[@]} != 0 )); then
+ echo "missing:"
+ for missing_requisite in "${missing_requisite_list[@]}"; do
+ echo " $missing_requisite"
+ done
+fi
+
+# in conclusion
+#
+if (( ${#missing_requisite_list[@]} > 0 )); then
+ echo "β Missing requisites"
+ exit 1
+else
+ echo "β
All checked specified requisites found"
+ exit 0
+fi
--- /dev/null
+#!/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
+
+./build_binutils_requisites.sh
+./build_binutils.sh
+
+./build_linux_requisites.sh
+./build_linux.sh
+
+#./build_glibc_bootstrap_requisites.sh
+./build_glibc_bootstrap.sh
+
+./build_gcc_stage1_requisites.sh
+./build_gcc_stage1.sh
+
+./build_glibc_requisites.sh
+./build_glibc.sh
+
+./build_gcc_final_requisites.sh
+./build_gcc_final.sh
+
+echo "β
Toolchain build complete"
+"$TOOLCHAIN/bin/gcc" --version
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+mkdir -p "$BINUTILS_BUILD"
+pushd "$BINUTILS_BUILD"
+
+ "$BINUTILS_SRC/configure" \
+ --prefix="$TOOLCHAIN" \
+ --with-sysroot="$SYSROOT" \
+ --disable-nls \
+ --disable-werror \
+ --disable-multilib \
+ --enable-deterministic-archives \
+ --enable-plugins \
+ --with-lib-path="$SYSROOT/lib:$SYSROOT/usr/lib"
+
+ $MAKE
+ $MAKE install
+
+ # Verify installation
+ if [[ -x "$TOOLCHAIN/bin/ld" ]]; then
+ echo "β
Binutils installed in $TOOLCHAIN/bin"
+ exit 0
+ fi
+
+ echo "β Binutils install incomplete"
+ exit 1
+
+popd
+
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π¦ Checking requisites for binutils (bootstrap)."
+
+missing_requisite_list=()
+found_requisite_list=()
+
+# tool required for build
+#
+ required_tools=(
+ "gcc"
+ "g++"
+ "make"
+ )
+
+ for tool in "${required_tools[@]}"; do
+ location=$(command -v "$tool")
+ if [ $? -eq 0 ]; then
+ found_requisite_list+=("$location")
+ else
+ missing_requisite_list+=("$tool")
+ fi
+ done
+
+# source code required for build
+#
+ if [ -d "$BINUTILS_SRC" ] && [ "$(ls -A "$BINUTILS_SRC")" ]; then
+ found_requisite_list+=("$BINUTILS_SRC")
+ else
+ missing_requisite_list+=("$BINUTILS_SRC")
+ fi
+
+# print requisites found
+#
+ if (( ${#found_requisite_list[@]} != 0 )); then
+ echo "found:"
+ for found_requisite in "${found_requisite_list[@]}"; do
+ echo " $found_requisite"
+ done
+ fi
+
+# print requisites missing
+#
+ if (( ${#missing_requisite_list[@]} != 0 )); then
+ echo "missing:"
+ for missing_requisite in "${missing_requisite_list[@]}"; do
+ echo " $missing_requisite"
+ done
+ fi
+
+# in conclusion
+#
+ if (( ${#missing_requisite_list[@]} > 0 )); then
+ echo "β Missing requisites"
+ exit 1
+ else
+ echo "β
All checked specified requisites found"
+ exit 0
+ fi
--- /dev/null
+#!/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"
--- /dev/null
+#!/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."
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π§ Starting stage 1 GCC build (native layout)..."
+
+# π§Ό Clean optionally if forced
+if [[ "${CLEAN_STAGE1:-0}" == "1" ]]; then
+ echo "π§Ή Forcing rebuild: cleaning $GCC_BUILD_STAGE1"
+ rm -rf "$GCC_BUILD_STAGE1"
+fi
+
+mkdir -p "$GCC_BUILD_STAGE1"
+pushd "$GCC_BUILD_STAGE1"
+
+# π οΈ Configure only if not yet configured
+if [[ ! -f Makefile ]]; then
+ echo "βοΈ Configuring GCC stage 1..."
+ "$GCC_SRC/configure" \
+ --prefix="$TOOLCHAIN" \
+ --with-sysroot="$SYSROOT" \
+ --with-build-sysroot="$SYSROOT" \
+ --with-native-system-header-dir=/include \
+ --enable-languages=c \
+ --disable-nls \
+ --disable-shared \
+ --disable-threads \
+ --disable-libatomic \
+ --disable-libgomp \
+ --disable-libquadmath \
+ --disable-libssp \
+ --disable-multilib \
+ --disable-bootstrap \
+ --disable-libstdcxx \
+ --disable-fixincludes \
+ --without-headers \
+ --with-newlib
+else
+ echo "β
GCC already configured, skipping."
+fi
+
+# π§Ύ Ensure proper sysroot handling for internal libgcc
+export CFLAGS_FOR_TARGET="--sysroot=$SYSROOT"
+export CXXFLAGS_FOR_TARGET="--sysroot=$SYSROOT"
+export CPPFLAGS_FOR_TARGET="--sysroot=$SYSROOT"
+export CFLAGS="--sysroot=$SYSROOT"
+export CXXFLAGS="--sysroot=$SYSROOT"
+
+# ποΈ Build only if not built
+if [[ ! -x "$TOOLCHAIN/bin/gcc" ]]; then
+ echo "βοΈ Building GCC stage 1..."
+ make -j"$(nproc)" all-gcc all-target-libgcc
+
+ echo "π¦ Installing GCC stage 1 to $TOOLCHAIN"
+ make install-gcc install-target-libgcc
+else
+ echo "β
GCC stage 1 already installed at $TOOLCHAIN/bin/gcc, skipping build."
+fi
+
+popd
+
+# β
Final check
+if [[ ! -x "$TOOLCHAIN/bin/gcc" ]]; then
+ echo "β Stage 1 GCC not found at $TOOLCHAIN/bin/gcc β build may have failed."
+ exit 1
+fi
+
+echo "β
Stage 1 GCC successfully installed in $TOOLCHAIN/bin"
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π¦ Checking prerequisites for stage 1 GCC (bootstrap)..."
+
+required_tools=(gcc g++ make tar gawk bison flex)
+missing=()
+
+for tool in "${required_tools[@]}"; do
+ if ! type -P "$tool" &>/dev/null; then
+ missing+=("$tool")
+ fi
+done
+
+if (( ${#missing[@]} )); then
+ echo "β Missing required tools: ${missing[*]}"
+ exit 1
+fi
+
+if [ ! -d "$GCC_SRC" ]; then
+ echo "β GCC source not found at $GCC_SRC"
+ echo "π‘ You may need to run: prepare_gcc_sources.sh"
+ exit 1
+fi
+
+echo "β
Prerequisites for stage 1 GCC met."
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π§ Building full glibc..."
+
+mkdir -p "$GLIBC_BUILD"
+pushd "$GLIBC_BUILD"
+
+"$GLIBC_SRC/configure" \
+ --prefix=/usr \
+ --host="$TARGET" \
+ --build="$(gcc -dumpmachine)" \
+ --with-headers="$SYSROOT/usr/include" \
+ --disable-multilib \
+ --enable-static \
+ --enable-shared \
+ libc_cv_slibdir="/usr/lib"
+
+$MAKE
+DESTDIR="$SYSROOT" $MAKE install
+
+popd
+
+echo "β
Full glibc installed in $SYSROOT"
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π¦ Building glibc startup files (crt*.o)..."
+
+pushd "$GLIBC_BUILD"
+
+ # Confirm that required build artifacts are present
+ if [[ ! -f bits/stdio_lim.h ]]; then
+ echo "β Missing bits/stdio_lim.h β did you run build_glibc_headers.sh?"
+ exit 1
+ fi
+
+ if [[ ! -f csu/Makefile ]]; then
+ echo "β Missing csu/Makefile β glibc configure phase may have failed"
+ exit 1
+ fi
+
+ # Attempt to build the crt startup object files
+ make csu/crt1.o csu/crti.o csu/crtn.o -j"$MAKE_JOBS"
+
+ # Install them to the sysroot
+ install -m 644 csu/crt1.o csu/crti.o csu/crtn.o "$SYSROOT/usr/lib"
+
+ # Create a dummy libc.so to satisfy linker if needed
+ touch "$SYSROOT/usr/lib/libc.so"
+
+ # β
Verify installation
+ for f in crt1.o crti.o crtn.o; do
+ if [[ ! -f "$SYSROOT/usr/lib/$f" ]]; then
+ echo "β Missing startup file after install: $f"
+ exit 1
+ fi
+ done
+
+popd
+
+echo "β
glibc startup files installed to $SYSROOT/usr/lib"
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π¦ Checking requisites for glibc startup file build (crt1.o, crti.o, crtn.o)."
+
+missing_requisite_list=()
+found_requisite_list=()
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# 1. Required tools
+#
+ required_tools=(
+ "gcc"
+ "g++"
+ "make"
+ "ld"
+ "as"
+ )
+
+ for tool in "${required_tools[@]}"; do
+ if location=$(command -v "$tool"); then
+ found_requisite_list+=("$location")
+ else
+ missing_requisite_list+=("$tool")
+ fi
+ done
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# 2. Required directories and sources
+#
+ if [ -d "$GLIBC_SRC" ] && [ "$(ls -A "$GLIBC_SRC")" ]; then
+ found_requisite_list+=("$GLIBC_SRC")
+ else
+ missing_requisite_list+=("$GLIBC_SRC (empty or missing)")
+ fi
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# 3. Required sysroot include path with Linux headers
+#
+ linux_headers=(
+ "$SYSROOT/usr/include/linux/version.h"
+ "$SYSROOT/usr/include/asm/unistd.h"
+ "$SYSROOT/usr/include/bits/types.h"
+ )
+
+ for header in "${linux_headers[@]}"; do
+ if [[ -f "$header" ]]; then
+ found_requisite_list+=("$header")
+ else
+ missing_requisite_list+=("$header")
+ fi
+ done
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# 4. Confirm SYSROOT write access
+#
+ if [[ -w "$SYSROOT/usr/include" ]]; then
+ found_requisite_list+=("SYSROOT writable: $SYSROOT/usr/include")
+ else
+ missing_requisite_list+=("SYSROOT not writable: $SYSROOT/usr/include")
+ fi
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# Additional sanity checks before header & crt build
+#
+
+ # 1. Check that the C preprocessor works and headers can be found
+ echo '#include <stddef.h>' | gcc -E - > /dev/null 2>&1
+ if [[ $? -eq 0 ]]; then
+ found_requisite_list+=("C preprocessor operational: gcc -E works")
+ else
+ missing_requisite_list+=("C preprocessor failed: gcc -E on <stddef.h> failed")
+ fi
+
+ # 2. Check that bits/stdio_lim.h exists after headers install (glibc marker)
+ if [[ -f "$GLIBC_BUILD/bits/stdio_lim.h" ]]; then
+ found_requisite_list+=("$GLIBC_BUILD/bits/stdio_lim.h (glibc headers marker found)")
+ else
+ missing_requisite_list+=("$GLIBC_BUILD/bits/stdio_lim.h missing β headers may not be fully installed")
+ fi
+
+ # 3. Check for crt objects already present (optional)
+ for f in crt1.o crti.o crtn.o; do
+ if [[ -f "$GLIBC_BUILD/csu/$f" ]]; then
+ found_requisite_list+=("$GLIBC_BUILD/csu/$f (already built)")
+ fi
+ done
+
+ # 4. Check that Makefile exists and is non-empty
+ if [[ -f "$GLIBC_BUILD/Makefile" ]]; then
+ if [[ -s "$GLIBC_BUILD/Makefile" ]]; then
+ found_requisite_list+=("$GLIBC_BUILD/Makefile exists and is populated")
+ else
+ missing_requisite_list+=("$GLIBC_BUILD/Makefile exists but is empty β incomplete configure?")
+ fi
+ else
+ missing_requisite_list+=("$GLIBC_BUILD/Makefile missing β did configure run?")
+ fi
+
+ # 5. Check that csu Makefile has rules for crt1.o
+ if [[ -f "$GLIBC_BUILD/csu/Makefile" ]]; then
+ if grep -q 'crt1\.o' "$GLIBC_BUILD/csu/Makefile"; then
+ found_requisite_list+=("csu/Makefile defines crt1.o")
+ else
+ missing_requisite_list+=("csu/Makefile does not define crt1.o β possible misconfigure")
+ fi
+ else
+ missing_requisite_list+=("csu/Makefile missing β subdir config likely failed")
+ fi
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# Print results
+#
+ if (( ${#found_requisite_list[@]} > 0 )); then
+ echo "found:"
+ for item in "${found_requisite_list[@]}"; do
+ echo " $item"
+ done
+ fi
+
+ if (( ${#missing_requisite_list[@]} > 0 )); then
+ echo "missing:"
+ for item in "${missing_requisite_list[@]}"; do
+ echo " $item"
+ done
+ fi
+
+ # Final verdict
+ #
+ if (( ${#missing_requisite_list[@]} > 0 )); then
+ echo "β Missing requisites for glibc bootstrap"
+ exit 1
+ else
+ echo "β
All specified requisites found"
+ exit 0
+ fi
--- /dev/null
+#!/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"
--- /dev/null
+#!/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
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π¦ Building and installing glibc headers..."
+
+mkdir -p "$GLIBC_BUILD"
+pushd "$GLIBC_BUILD"
+
+ # Configure glibc with minimal bootstrap options
+ "$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"
+
+
+ # Install headers into sysroot
+ make install-headers -j"$MAKE_JOBS" DESTDIR="$SYSROOT"
+
+ # β
Verify headers were installed
+ required_headers=(
+ "$SYSROOT/usr/include/gnu/libc-version.h"
+ "$SYSROOT/usr/include/stdio.h"
+ "$SYSROOT/usr/include/unistd.h"
+ )
+
+ missing=()
+ for h in "${required_headers[@]}"; do
+ [[ -f "$h" ]] || missing+=("$h")
+ done
+
+ if (( ${#missing[@]} > 0 )); then
+ echo "β Missing required glibc headers:"
+ printf ' %s\n' "${missing[@]}"
+ exit 1
+ fi
+
+popd
+
+echo "β
glibc headers successfully installed to $SYSROOT/usr/include"
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π¦ Checking requisites for glibc headers installation."
+
+missing_requisite_list=()
+found_requisite_list=()
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# 1. Required tools for headers phase
+#
+required_tools=(
+ "gcc"
+ "g++"
+ "make"
+ "ld"
+ "as"
+)
+
+for tool in "${required_tools[@]}"; do
+ if location=$(command -v "$tool"); then
+ found_requisite_list+=("$location")
+ else
+ missing_requisite_list+=("$tool")
+ fi
+done
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# 2. glibc source directory check
+#
+if [ -d "$GLIBC_SRC" ] && [ "$(ls -A "$GLIBC_SRC")" ]; then
+ found_requisite_list+=("$GLIBC_SRC")
+else
+ missing_requisite_list+=("$GLIBC_SRC (empty or missing)")
+fi
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# 3. Kernel headers required for bootstrap glibc
+#
+linux_headers=(
+ "$SYSROOT/usr/include/linux/version.h"
+ "$SYSROOT/usr/include/asm/unistd.h"
+ "$SYSROOT/usr/include/bits/types.h"
+)
+
+for header in "${linux_headers[@]}"; do
+ if [[ -f "$header" ]]; then
+ found_requisite_list+=("$header")
+ else
+ missing_requisite_list+=("$header")
+ fi
+done
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# 4. Confirm SYSROOT write access for header install
+#
+if [[ -w "$SYSROOT/usr/include" ]]; then
+ found_requisite_list+=("SYSROOT writable: $SYSROOT/usr/include")
+else
+ missing_requisite_list+=("SYSROOT not writable: $SYSROOT/usr/include")
+fi
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# 5. Check C preprocessor is operational
+#
+echo '#include <stddef.h>' | gcc -E - > /dev/null 2>&1
+if [[ $? -eq 0 ]]; then
+ found_requisite_list+=("C preprocessor operational: gcc -E works")
+else
+ missing_requisite_list+=("C preprocessor failed: gcc -E on <stddef.h> failed")
+fi
+
+# ββββββββββββββββββββββββββββββββββββββββββββββββ
+# Print results
+#
+if (( ${#found_requisite_list[@]} > 0 )); then
+ echo "found:"
+ for item in "${found_requisite_list[@]}"; do
+ echo " $item"
+ done
+fi
+
+if (( ${#missing_requisite_list[@]} > 0 )); then
+ echo "missing:"
+ for item in "${missing_requisite_list[@]}"; do
+ echo " $item"
+ done
+fi
+
+# Final verdict
+if (( ${#missing_requisite_list[@]} > 0 )); then
+ echo "β Missing requisites for glibc header install"
+ exit 1
+else
+ echo "β
All specified requisites found for glibc headers"
+ exit 0
+fi
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π¦ Checking prerequisites for glibc..."
+
+required_tools=(gcc make curl tar perl python3 gawk bison)
+missing_tools=()
+
+for tool in "${required_tools[@]}"; do
+ if ! command -v "$tool" > /dev/null; then
+ missing_tools+=("$tool")
+ fi
+done
+
+if (( ${#missing_tools[@]} )); then
+ echo "β Missing required tools:"
+ printf ' %s\n' "${missing_tools[@]}"
+ exit 1
+fi
+
+# Check that expected headers exist
+glibc_headers=(
+ "$SYSROOT/usr/include/stdio.h"
+ "$SYSROOT/usr/include/unistd.h"
+)
+
+# Check that expected startup objects exist
+startup_objects=(
+ "$SYSROOT/usr/lib/crt1.o"
+ "$SYSROOT/usr/lib/crti.o"
+ "$SYSROOT/usr/lib/crtn.o"
+)
+
+missing_files=()
+for f in "${glibc_headers[@]}" "${startup_objects[@]}"; do
+ if [ ! -f "$f" ]; then
+ missing_files+=("$f")
+ fi
+done
+
+if (( ${#missing_files[@]} )); then
+ echo "β Missing required files in sysroot:"
+ printf ' %s\n' "${missing_files[@]}"
+ echo
+ echo "Hint: these files should have been generated by build_glibc_headers.sh"
+ exit 1
+fi
+
+echo "β
All prerequisites for glibc are met and sysroot is correctly populated."
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "π¦ Preparing Linux kernel headers for glibc and GCC..."
+
+pushd "$LINUX_SRC"
+
+ $MAKE mrproper
+ $MAKE headers_install ARCH=x86_64 INSTALL_HDR_PATH="$SYSROOT/usr"
+
+ if [[ -f "$SYSROOT/usr/include/linux/version.h" ]]; then
+ echo "β
Linux headers installed to $SYSROOT/usr/include"
+ exit 0
+ fi
+
+ echo "β Kernel headers not found at expected location."
+ exit 1
+
+popd
--- /dev/null
+#!/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."
--- /dev/null
+#!/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"
--- /dev/null
+#!/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"
--- /dev/null
+#!/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"
--- /dev/null
+# === 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=$(nproc)
+# export MAKE="make -j$MAKE_JOBS"
+ 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 versions
+
+ export LINUX_VER=6.8
+ export BINUTILS_VER=2.42
+ 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
+
+ # 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"
+ )
+
+ # Source directories
+ export LINUX_SRC="$SRC/linux-$LINUX_VER"
+ 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
+ export BINUTILS_BUILD="$BUILD_DIR/binutils"
+ export GCC_BUILD_STAGE1="$BUILD_DIR/gcc-stage1"
+ export GCC_BUILD_FINAL="$BUILD_DIR/gcc-final"
+ export GLIBC_BUILD="$BUILD_DIR/glibc"
+ BUILD_DIR_LIST=(
+ "$BINUTILS_BUILD"
+ "$GCC_BUILD_STAGE1"
+ "$GCC_BUILD_FINAL"
+ "$GLIBC_BUILD"
+ )
+
+#--------------------------------------------------------------------------------
+# upstream -> local stuff
+
+ # see top of this file for the _VER variables
+
+ # Tarball Download Info (Name, URL, Destination Directory)
+ export UPSTREAM_TARBALL_LIST=(
+ "linux-${LINUX_VER}.tar.xz"
+ "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${LINUX_VER}.tar.xz"
+ "$UPSTREAM/linux-$LINUX_VER"
+
+ "binutils-${BINUTILS_VER}.tar.xz"
+ "https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.xz"
+ "$UPSTREAM/binutils-$BINUTILS_VER"
+
+ # 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 Repo Info
+ # Each entry is triple: Repository URL, Branch, Destination Directory
+ # Repos clone directly into $SRC
+ export UPSTREAM_GIT_REPO_LIST=(
+
+ "git://gcc.gnu.org/git/gcc.git"
+ "releases/gcc-15"
+ "$SRC/gcc-$GCC_VER"
+
+ #currently there is no second repo
+ )
+
+
--- /dev/null
+#!/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"
--- /dev/null
+#!/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
--- /dev/null
+#!/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
+
+
--- /dev/null
+#!/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"
--- /dev/null
+
+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.
+
--- /dev/null
+#!/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
--- /dev/null
+#!/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"
--- /dev/null
+#!/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."
--- /dev/null
+#!/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."
--- /dev/null
+#!/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"
--- /dev/null
+#!/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"
--- /dev/null
+#!/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"
--- /dev/null
+# === 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"
+ )
+
+
+
--- /dev/null
+#!/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"
--- /dev/null
+#!/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"
--- /dev/null
+#!/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
--- /dev/null
+#!/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
+
+
--- /dev/null
+#!/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"
+++ /dev/null
-
-# 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.
-
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π Auditing glibc build state..."
-
-declare -a missing
-declare -a present
-
-# GLIBC_BUILD sanity
-[[ -d "$GLIBC_BUILD" ]] && present+=("GLIBC_BUILD exists: $GLIBC_BUILD") || missing+=("GLIBC_BUILD missing")
-
-# Check for Makefile
-if [[ -s "$GLIBC_BUILD/Makefile" ]]; then
- present+=("Makefile exists and non-empty")
-else
- missing+=("Makefile missing or empty in $GLIBC_BUILD")
-fi
-
-# Check bits/stdio_lim.h
-if [[ -f "$GLIBC_BUILD/bits/stdio_lim.h" ]]; then
- present+=("bits/stdio_lim.h exists (post-header install marker)")
-else
- missing+=("bits/stdio_lim.h missing β make install-headers likely incomplete")
-fi
-
-# Check csu/Makefile
-if [[ -f "$GLIBC_BUILD/csu/Makefile" ]]; then
- present+=("csu/Makefile exists")
- grep -q 'crt1\.o' "$GLIBC_BUILD/csu/Makefile" \
- && present+=("csu/Makefile defines crt1.o") \
- || missing+=("csu/Makefile missing rule for crt1.o")
-else
- missing+=("csu/Makefile missing")
-fi
-
-# Show report
-echo "β
Present:"
-for p in "${present[@]}"; do echo " $p"; done
-
-echo
-if (( ${#missing[@]} )); then
- echo "β Missing:"
- for m in "${missing[@]}"; do echo " $m"; done
- exit 1
-else
- echo "π All bootstrap prerequisites are in place"
- exit 0
-fi
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π¦ Checking requisites for Linux kernel headers build."
-
-missing_requisite_list=()
-found_requisite_list=()
-
-# tools required for build
-#
-required_tools=(
- "gcc"
- "g++"
- "make"
-)
-
-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
- found_requisite_list+=("$location")
- else
- missing_requisite_list+=("$tool")
- fi
-done
-
-# source code required for build
-#
-if [ -d "$LINUX_SRC" ] && [ "$(ls -A "$LINUX_SRC")" ]; then
- found_requisite_list+=("$LINUX_SRC")
-else
- missing_requisite_list+=("$LINUX_SRC")
-fi
-
-# print requisites found
-#
-if (( ${#found_requisite_list[@]} != 0 )); then
- echo "found:"
- for found_requisite in "${found_requisite_list[@]}"; do
- echo " $found_requisite"
- done
-fi
-
-# print requisites missing
-#
-if (( ${#missing_requisite_list[@]} != 0 )); then
- echo "missing:"
- for missing_requisite in "${missing_requisite_list[@]}"; do
- echo " $missing_requisite"
- done
-fi
-
-# in conclusion
-#
-if (( ${#missing_requisite_list[@]} > 0 )); then
- echo "β Missing requisites"
- exit 1
-else
- echo "β
All checked specified requisites found"
- exit 0
-fi
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-cd "$(dirname "$0")"
-SCRIPT_DIR="$PWD"
-
-echo "loading environment"
-source "$SCRIPT_DIR/environment.sh"
-
-cd "$SCRIPT_DIR"
-
-./clean_build.sh
-./setup_project.sh
-
-./download_sources.sh
-./extract_from_tar.sh
-
-./build_binutils_requisites.sh
-./build_binutils.sh
-
-./build_linux_requisites.sh
-./build_linux.sh
-
-#./build_glibc_bootstrap_requisites.sh
-./build_glibc_bootstrap.sh
-
-./build_gcc_stage1_requisites.sh
-./build_gcc_stage1.sh
-
-./build_glibc_requisites.sh
-./build_glibc.sh
-
-./build_gcc_final_requisites.sh
-./build_gcc_final.sh
-
-echo "β
Toolchain build complete"
-"$TOOLCHAIN/bin/gcc" --version
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-mkdir -p "$BINUTILS_BUILD"
-pushd "$BINUTILS_BUILD"
-
- "$BINUTILS_SRC/configure" \
- --prefix="$TOOLCHAIN" \
- --with-sysroot="$SYSROOT" \
- --disable-nls \
- --disable-werror \
- --disable-multilib \
- --enable-deterministic-archives \
- --enable-plugins \
- --with-lib-path="$SYSROOT/lib:$SYSROOT/usr/lib"
-
- $MAKE
- $MAKE install
-
- # Verify installation
- if [[ -x "$TOOLCHAIN/bin/ld" ]]; then
- echo "β
Binutils installed in $TOOLCHAIN/bin"
- exit 0
- fi
-
- echo "β Binutils install incomplete"
- exit 1
-
-popd
-
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π¦ Checking requisites for binutils (bootstrap)."
-
-missing_requisite_list=()
-found_requisite_list=()
-
-# tool required for build
-#
- required_tools=(
- "gcc"
- "g++"
- "make"
- )
-
- 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
- found_requisite_list+=("$location")
- else
- missing_requisite_list+=("$tool")
- fi
- done
-
-# source code required for build
-#
- if [ -d "$BINUTILS_SRC" ] && [ "$(ls -A "$BINUTILS_SRC")" ]; then
- found_requisite_list+=("$BINUTILS_SRC")
- else
- missing_requisite_list+=("$BINUTILS_SRC")
- fi
-
-# print requisites found
-#
- if (( ${#found_requisite_list[@]} != 0 )); then
- echo "found:"
- for found_requisite in "${found_requisite_list[@]}"; do
- echo " $found_requisite"
- done
- fi
-
-# print requisites missing
-#
- if (( ${#missing_requisite_list[@]} != 0 )); then
- echo "missing:"
- for missing_requisite in "${missing_requisite_list[@]}"; do
- echo " $missing_requisite"
- done
- fi
-
-# in conclusion
-#
- if (( ${#missing_requisite_list[@]} > 0 )); then
- echo "β Missing requisites"
- exit 1
- else
- echo "β
All checked specified requisites found"
- exit 0
- fi
+++ /dev/null
-#!/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"
+++ /dev/null
-#!/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."
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π§ Starting stage 1 GCC build (native layout)..."
-
-# π§Ό Clean optionally if forced
-if [[ "${CLEAN_STAGE1:-0}" == "1" ]]; then
- echo "π§Ή Forcing rebuild: cleaning $GCC_BUILD_STAGE1"
- rm -rf "$GCC_BUILD_STAGE1"
-fi
-
-mkdir -p "$GCC_BUILD_STAGE1"
-pushd "$GCC_BUILD_STAGE1"
-
-# π οΈ Configure only if not yet configured
-if [[ ! -f Makefile ]]; then
- echo "βοΈ Configuring GCC stage 1..."
- "$GCC_SRC/configure" \
- --prefix="$TOOLCHAIN" \
- --with-sysroot="$SYSROOT" \
- --with-build-sysroot="$SYSROOT" \
- --with-native-system-header-dir=/include \
- --enable-languages=c \
- --disable-nls \
- --disable-shared \
- --disable-threads \
- --disable-libatomic \
- --disable-libgomp \
- --disable-libquadmath \
- --disable-libssp \
- --disable-multilib \
- --disable-bootstrap \
- --disable-libstdcxx \
- --disable-fixincludes \
- --without-headers \
- --with-newlib
-else
- echo "β
GCC already configured, skipping."
-fi
-
-# π§Ύ Ensure proper sysroot handling for internal libgcc
-export CFLAGS_FOR_TARGET="--sysroot=$SYSROOT"
-export CXXFLAGS_FOR_TARGET="--sysroot=$SYSROOT"
-export CPPFLAGS_FOR_TARGET="--sysroot=$SYSROOT"
-export CFLAGS="--sysroot=$SYSROOT"
-export CXXFLAGS="--sysroot=$SYSROOT"
-
-# ποΈ Build only if not built
-if [[ ! -x "$TOOLCHAIN/bin/gcc" ]]; then
- echo "βοΈ Building GCC stage 1..."
- make -j"$(nproc)" all-gcc all-target-libgcc
-
- echo "π¦ Installing GCC stage 1 to $TOOLCHAIN"
- make install-gcc install-target-libgcc
-else
- echo "β
GCC stage 1 already installed at $TOOLCHAIN/bin/gcc, skipping build."
-fi
-
-popd
-
-# β
Final check
-if [[ ! -x "$TOOLCHAIN/bin/gcc" ]]; then
- echo "β Stage 1 GCC not found at $TOOLCHAIN/bin/gcc β build may have failed."
- exit 1
-fi
-
-echo "β
Stage 1 GCC successfully installed in $TOOLCHAIN/bin"
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π¦ Checking prerequisites for stage 1 GCC (bootstrap)..."
-
-required_tools=(gcc g++ make tar gawk bison flex)
-missing=()
-
-for tool in "${required_tools[@]}"; do
- if ! type -P "$tool" &>/dev/null; then
- missing+=("$tool")
- fi
-done
-
-if (( ${#missing[@]} )); then
- echo "β Missing required tools: ${missing[*]}"
- exit 1
-fi
-
-if [ ! -d "$GCC_SRC" ]; then
- echo "β GCC source not found at $GCC_SRC"
- echo "π‘ You may need to run: prepare_gcc_sources.sh"
- exit 1
-fi
-
-echo "β
Prerequisites for stage 1 GCC met."
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π§ Building full glibc..."
-
-mkdir -p "$GLIBC_BUILD"
-pushd "$GLIBC_BUILD"
-
-"$GLIBC_SRC/configure" \
- --prefix=/usr \
- --host="$TARGET" \
- --build="$(gcc -dumpmachine)" \
- --with-headers="$SYSROOT/usr/include" \
- --disable-multilib \
- --enable-static \
- --enable-shared \
- libc_cv_slibdir="/usr/lib"
-
-$MAKE
-DESTDIR="$SYSROOT" $MAKE install
-
-popd
-
-echo "β
Full glibc installed in $SYSROOT"
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π¦ Building glibc startup files (crt*.o)..."
-
-pushd "$GLIBC_BUILD"
-
- # Confirm that required build artifacts are present
- if [[ ! -f bits/stdio_lim.h ]]; then
- echo "β Missing bits/stdio_lim.h β did you run build_glibc_headers.sh?"
- exit 1
- fi
-
- if [[ ! -f csu/Makefile ]]; then
- echo "β Missing csu/Makefile β glibc configure phase may have failed"
- exit 1
- fi
-
- # Attempt to build the crt startup object files
- make csu/crt1.o csu/crti.o csu/crtn.o -j"$MAKE_JOBS"
-
- # Install them to the sysroot
- install -m 644 csu/crt1.o csu/crti.o csu/crtn.o "$SYSROOT/usr/lib"
-
- # Create a dummy libc.so to satisfy linker if needed
- touch "$SYSROOT/usr/lib/libc.so"
-
- # β
Verify installation
- for f in crt1.o crti.o crtn.o; do
- if [[ ! -f "$SYSROOT/usr/lib/$f" ]]; then
- echo "β Missing startup file after install: $f"
- exit 1
- fi
- done
-
-popd
-
-echo "β
glibc startup files installed to $SYSROOT/usr/lib"
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π¦ Checking requisites for glibc startup file build (crt1.o, crti.o, crtn.o)."
-
-missing_requisite_list=()
-found_requisite_list=()
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# 1. Required tools
-#
- required_tools=(
- "gcc"
- "g++"
- "make"
- "ld"
- "as"
- )
-
- for tool in "${required_tools[@]}"; do
- if location=$(command -v "$tool"); then
- found_requisite_list+=("$location")
- else
- missing_requisite_list+=("$tool")
- fi
- done
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# 2. Required directories and sources
-#
- if [ -d "$GLIBC_SRC" ] && [ "$(ls -A "$GLIBC_SRC")" ]; then
- found_requisite_list+=("$GLIBC_SRC")
- else
- missing_requisite_list+=("$GLIBC_SRC (empty or missing)")
- fi
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# 3. Required sysroot include path with Linux headers
-#
- linux_headers=(
- "$SYSROOT/usr/include/linux/version.h"
- "$SYSROOT/usr/include/asm/unistd.h"
- "$SYSROOT/usr/include/bits/types.h"
- )
-
- for header in "${linux_headers[@]}"; do
- if [[ -f "$header" ]]; then
- found_requisite_list+=("$header")
- else
- missing_requisite_list+=("$header")
- fi
- done
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# 4. Confirm SYSROOT write access
-#
- if [[ -w "$SYSROOT/usr/include" ]]; then
- found_requisite_list+=("SYSROOT writable: $SYSROOT/usr/include")
- else
- missing_requisite_list+=("SYSROOT not writable: $SYSROOT/usr/include")
- fi
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# Additional sanity checks before header & crt build
-#
-
- # 1. Check that the C preprocessor works and headers can be found
- echo '#include <stddef.h>' | gcc -E - > /dev/null 2>&1
- if [[ $? -eq 0 ]]; then
- found_requisite_list+=("C preprocessor operational: gcc -E works")
- else
- missing_requisite_list+=("C preprocessor failed: gcc -E on <stddef.h> failed")
- fi
-
- # 2. Check that bits/stdio_lim.h exists after headers install (glibc marker)
- if [[ -f "$GLIBC_BUILD/bits/stdio_lim.h" ]]; then
- found_requisite_list+=("$GLIBC_BUILD/bits/stdio_lim.h (glibc headers marker found)")
- else
- missing_requisite_list+=("$GLIBC_BUILD/bits/stdio_lim.h missing β headers may not be fully installed")
- fi
-
- # 3. Check for crt objects already present (optional)
- for f in crt1.o crti.o crtn.o; do
- if [[ -f "$GLIBC_BUILD/csu/$f" ]]; then
- found_requisite_list+=("$GLIBC_BUILD/csu/$f (already built)")
- fi
- done
-
- # 4. Check that Makefile exists and is non-empty
- if [[ -f "$GLIBC_BUILD/Makefile" ]]; then
- if [[ -s "$GLIBC_BUILD/Makefile" ]]; then
- found_requisite_list+=("$GLIBC_BUILD/Makefile exists and is populated")
- else
- missing_requisite_list+=("$GLIBC_BUILD/Makefile exists but is empty β incomplete configure?")
- fi
- else
- missing_requisite_list+=("$GLIBC_BUILD/Makefile missing β did configure run?")
- fi
-
- # 5. Check that csu Makefile has rules for crt1.o
- if [[ -f "$GLIBC_BUILD/csu/Makefile" ]]; then
- if grep -q 'crt1\.o' "$GLIBC_BUILD/csu/Makefile"; then
- found_requisite_list+=("csu/Makefile defines crt1.o")
- else
- missing_requisite_list+=("csu/Makefile does not define crt1.o β possible misconfigure")
- fi
- else
- missing_requisite_list+=("csu/Makefile missing β subdir config likely failed")
- fi
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# Print results
-#
- if (( ${#found_requisite_list[@]} > 0 )); then
- echo "found:"
- for item in "${found_requisite_list[@]}"; do
- echo " $item"
- done
- fi
-
- if (( ${#missing_requisite_list[@]} > 0 )); then
- echo "missing:"
- for item in "${missing_requisite_list[@]}"; do
- echo " $item"
- done
- fi
-
- # Final verdict
- #
- if (( ${#missing_requisite_list[@]} > 0 )); then
- echo "β Missing requisites for glibc bootstrap"
- exit 1
- else
- echo "β
All specified requisites found"
- exit 0
- fi
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π¦ Building and installing glibc headers..."
-
-mkdir -p "$GLIBC_BUILD"
-pushd "$GLIBC_BUILD"
-
- # Configure glibc with minimal bootstrap options
- "$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"
-
-
- # Install headers into sysroot
- make install-headers -j"$MAKE_JOBS" DESTDIR="$SYSROOT"
-
- # β
Verify headers were installed
- required_headers=(
- "$SYSROOT/usr/include/gnu/libc-version.h"
- "$SYSROOT/usr/include/stdio.h"
- "$SYSROOT/usr/include/unistd.h"
- )
-
- missing=()
- for h in "${required_headers[@]}"; do
- [[ -f "$h" ]] || missing+=("$h")
- done
-
- if (( ${#missing[@]} > 0 )); then
- echo "β Missing required glibc headers:"
- printf ' %s\n' "${missing[@]}"
- exit 1
- fi
-
-popd
-
-echo "β
glibc headers successfully installed to $SYSROOT/usr/include"
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π¦ Checking requisites for glibc headers installation."
-
-missing_requisite_list=()
-found_requisite_list=()
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# 1. Required tools for headers phase
-#
-required_tools=(
- "gcc"
- "g++"
- "make"
- "ld"
- "as"
-)
-
-for tool in "${required_tools[@]}"; do
- if location=$(command -v "$tool"); then
- found_requisite_list+=("$location")
- else
- missing_requisite_list+=("$tool")
- fi
-done
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# 2. glibc source directory check
-#
-if [ -d "$GLIBC_SRC" ] && [ "$(ls -A "$GLIBC_SRC")" ]; then
- found_requisite_list+=("$GLIBC_SRC")
-else
- missing_requisite_list+=("$GLIBC_SRC (empty or missing)")
-fi
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# 3. Kernel headers required for bootstrap glibc
-#
-linux_headers=(
- "$SYSROOT/usr/include/linux/version.h"
- "$SYSROOT/usr/include/asm/unistd.h"
- "$SYSROOT/usr/include/bits/types.h"
-)
-
-for header in "${linux_headers[@]}"; do
- if [[ -f "$header" ]]; then
- found_requisite_list+=("$header")
- else
- missing_requisite_list+=("$header")
- fi
-done
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# 4. Confirm SYSROOT write access for header install
-#
-if [[ -w "$SYSROOT/usr/include" ]]; then
- found_requisite_list+=("SYSROOT writable: $SYSROOT/usr/include")
-else
- missing_requisite_list+=("SYSROOT not writable: $SYSROOT/usr/include")
-fi
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# 5. Check C preprocessor is operational
-#
-echo '#include <stddef.h>' | gcc -E - > /dev/null 2>&1
-if [[ $? -eq 0 ]]; then
- found_requisite_list+=("C preprocessor operational: gcc -E works")
-else
- missing_requisite_list+=("C preprocessor failed: gcc -E on <stddef.h> failed")
-fi
-
-# ββββββββββββββββββββββββββββββββββββββββββββββββ
-# Print results
-#
-if (( ${#found_requisite_list[@]} > 0 )); then
- echo "found:"
- for item in "${found_requisite_list[@]}"; do
- echo " $item"
- done
-fi
-
-if (( ${#missing_requisite_list[@]} > 0 )); then
- echo "missing:"
- for item in "${missing_requisite_list[@]}"; do
- echo " $item"
- done
-fi
-
-# Final verdict
-if (( ${#missing_requisite_list[@]} > 0 )); then
- echo "β Missing requisites for glibc header install"
- exit 1
-else
- echo "β
All specified requisites found for glibc headers"
- exit 0
-fi
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π¦ Checking prerequisites for glibc..."
-
-required_tools=(gcc make curl tar perl python3 gawk bison)
-missing_tools=()
-
-for tool in "${required_tools[@]}"; do
- if ! command -v "$tool" > /dev/null; then
- missing_tools+=("$tool")
- fi
-done
-
-if (( ${#missing_tools[@]} )); then
- echo "β Missing required tools:"
- printf ' %s\n' "${missing_tools[@]}"
- exit 1
-fi
-
-# Check that expected headers exist
-glibc_headers=(
- "$SYSROOT/usr/include/stdio.h"
- "$SYSROOT/usr/include/unistd.h"
-)
-
-# Check that expected startup objects exist
-startup_objects=(
- "$SYSROOT/usr/lib/crt1.o"
- "$SYSROOT/usr/lib/crti.o"
- "$SYSROOT/usr/lib/crtn.o"
-)
-
-missing_files=()
-for f in "${glibc_headers[@]}" "${startup_objects[@]}"; do
- if [ ! -f "$f" ]; then
- missing_files+=("$f")
- fi
-done
-
-if (( ${#missing_files[@]} )); then
- echo "β Missing required files in sysroot:"
- printf ' %s\n' "${missing_files[@]}"
- echo
- echo "Hint: these files should have been generated by build_glibc_headers.sh"
- exit 1
-fi
-
-echo "β
All prerequisites for glibc are met and sysroot is correctly populated."
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "π¦ Preparing Linux kernel headers for glibc and GCC..."
-
-pushd "$LINUX_SRC"
-
- $MAKE mrproper
- $MAKE headers_install ARCH=x86_64 INSTALL_HDR_PATH="$SYSROOT/usr"
-
- if [[ -f "$SYSROOT/usr/include/linux/version.h" ]]; then
- echo "β
Linux headers installed to $SYSROOT/usr/include"
- exit 0
- fi
-
- echo "β Kernel headers not found at expected location."
- exit 1
-
-popd
+++ /dev/null
-#!/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."
+++ /dev/null
-#!/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"
+++ /dev/null
-#!/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"
+++ /dev/null
-#!/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"
+++ /dev/null
-#!/bin/bash
-# This script can be run multiple times to fetch 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
-
-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
-
- # 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)"
- else
- # If not 2xx, print the status code for transparency
- echo "β οΈ Server $url returned HTTP $http_code (proceeding with download anyway)"
- 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 [[ -f "$UPSTREAM/$file" ]]; then
- echo "β
Successfully downloaded $file"
- return 0
- else
- echo "β $file did not appear after download"
- return 1
- fi
- else
- echo "β Failed to download $file"
- return 1
- fi
-}
-
-fetch_tarballs() {
- echo "Starting to download tarballs..."
-
- i=0
- while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do
- tarball="${UPSTREAM_TARBALL_LIST[$i]}"
- url="${UPSTREAM_TARBALL_LIST[$((i+1))]}"
-
- if check_file_exists "$tarball"; then
- echo "β‘ $tarball already exists, skipping download"
- i=$((i + 3))
- continue
- fi
-
- check_server_reachability "$url"
-
- if ! download_file "$tarball" "$url"; then
- echo "β οΈ Skipping $tarball due to previous error"
- fi
-
- i=$((i + 3))
- done
-}
-
-fetch_git_repos() {
- echo "Starting to download Git repositories..."
-
- 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 "β‘ $dir already exists, skipping git clone"
- 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
-}
-
-# 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)"
-
-check_internet_connection
-fetch_tarballs
-fetch_git_repos
-
-echo "β
download_expand_source.sh completed"
+++ /dev/null
-# === 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=$(nproc)
-# export MAKE="make -j$MAKE_JOBS"
- 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 versions
-
- export LINUX_VER=6.8
- export BINUTILS_VER=2.42
- export GCC_VER=15.1.0
- export GLIBC_VER=2.39
-
-#--------------------------------------------------------------------------------
-# 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"
- )
-
- # Source directories
- export LINUX_SRC="$SRC/linux-$LINUX_VER"
- export BINUTILS_SRC="$SRC/binutils-$BINUTILS_VER"
- export GCC_SRC="$SRC/gcc-$GCC_VER"
- export GLIBC_SRC="$SRC/glibc-$GLIBC_VER"
- SOURCE_DIR_LIST=(
- "$LINUX_SRC"
- "$BINUTILS_SRC"
- "$GCC_SRC"
- "$GLIBC_SRC"
- )
-
- # Build directories
- export BINUTILS_BUILD="$BUILD_DIR/binutils"
- export GCC_BUILD_STAGE1="$BUILD_DIR/gcc-stage1"
- export GCC_BUILD_FINAL="$BUILD_DIR/gcc-final"
- export GLIBC_BUILD="$BUILD_DIR/glibc"
- BUILD_DIR_LIST=(
- "$BINUTILS_BUILD"
- "$GCC_BUILD_STAGE1"
- "$GCC_BUILD_FINAL"
- "$GLIBC_BUILD"
- )
-
-#--------------------------------------------------------------------------------
-# upstream -> local stuff
-
- # 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"
- "$UPSTREAM/linux-$LINUX_VER"
-
- "$BINUTILS_TARBALL"
- "https://ftp.gnu.org/gnu/binutils/$BINUTILS_TARBALL"
- "$UPSTREAM/binutils-$BINUTILS_VER"
-
- "$GLIBC_TARBALL"
- "https://ftp.gnu.org/gnu/libc/$GLIBC_TARBALL"
- "$UPSTREAM/glibc-$GLIBC_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
- export UPSTREAM_GIT_REPO_LIST=(
-
- "$GCC_REPO"
- "$GCC_BRANCH"
- "$SRC/gcc-$GCC_VER"
-
- #currently there is no second repo
- )
-
-
-
+++ /dev/null
-#!/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"
+++ /dev/null
-#!/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"