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