From: Thomas Walker Lynch Date: Mon, 5 May 2025 05:25:56 +0000 (-0700) Subject: checkpoint working on standalone build scripts X-Git-Url: https://git.reasoningtechnology.com/usr/lib/python2.7/encodings/iso8859_14.py?a=commitdiff_plain;h=0733bd318a87cc68cb79a065dd77872e6204e8dd;p=RT-gcc checkpoint working on standalone build scripts --- diff --git "a/script\360\237\226\211/build_Linux_requisites.sh" "b/script\360\237\226\211/build_Linux_requisites.sh" new file mode 100644 index 0000000..42fa7b7 --- /dev/null +++ "b/script\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\360\237\226\211/build_all.sh" "b/script\360\237\226\211/build_all.sh" index af88bf6..920a8f7 100755 --- "a/script\360\237\226\211/build_all.sh" +++ "b/script\360\237\226\211/build_all.sh" @@ -9,38 +9,29 @@ source "$SCRIPT_DIR/environment.sh" cd "$SCRIPT_DIR" -echo "cleaning ..." - # Run before a rebuild; skips source deletion - ./clean_build.sh - -echo "setting up the project ..." - # Creates directory structure; idempotent - ./make_project_structure.sh - -echo "downloading and expanding upstream sources" - # Downloads tarballs and clones repos - ./download_sources.sh - -echo "building binutils" - ./build_binutils_requisites.sh - ./build_binutils.sh - -echo "Step 3: glibc headers installed" - ./build_linux_headers.sh - ./prepare_glibc_sources.sh - ./build_glibc_headers.sh - -echo "Step 4: GCC Stage 1" - ./build_gcc_stage1_requisites.sh - ./build_gcc_stage1.sh - -echo "Step 5: Build glibc (full libc build)" - ./build_glibc_requisites.sh - ./build_glibc.sh - -echo "Step 6: Final GCC" - ./build_gcc_final_requisites.sh - ./build_gcc_final.sh +./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 + +./prepare_glibc_sources.sh +./build_glibc_headers.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" index 114bc94..959e91c 100755 --- "a/script\360\237\226\211/build_binutils.sh" +++ "b/script\360\237\226\211/build_binutils.sh" @@ -1,46 +1,32 @@ #!/bin/bash set -euo pipefail -# Load shared environment source "$(dirname "$0")/environment.sh" -mkdir -p "$BINUTILS_SRC" -pushd "$BINUTILS_SRC" - -if [ ! -f "$BINUTILS_TARBALL" ]; then - echo "⤵️ Downloading $BINUTILS_TARBALL..." - curl -LO "$BINUTILS_URL" -else - echo "✅ $BINUTILS_TARBALL already exists. Skipping download." -fi - -if [ ! -f configure ]; then - echo "📦 Extracting binutils..." - tar -xzf "$BINUTILS_TARBALL" --strip-components=1 -else - echo "✅ Binutils source already extracted." -fi - -popd - 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" + "$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 -$MAKE -$MAKE install + # Verify installation + if [[ -x "$TOOLCHAIN/bin/ld" ]]; then + echo "✅ Binutils installed in $TOOLCHAIN/bin" + exit 0 + fi -[[ -x "$TOOLCHAIN/bin/ld" ]] && echo "✅ Binutils installed in $TOOLCHAIN/bin" || { - echo "❌ Binutils install incomplete"; exit 1; -} + 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" index 7a3e116..871c68c 100755 --- "a/script\360\237\226\211/build_binutils_requisites.sh" +++ "b/script\360\237\226\211/build_binutils_requisites.sh" @@ -3,22 +3,60 @@ set -euo pipefail source "$(dirname "$0")/environment.sh" -echo "📦 Checking prerequisites for binutils (bootstrap)..." - -required_tools=(gcc g++ make curl tar xz) -missing=() - -for tool in "${required_tools[@]}"; do - if ! type -P "$tool" &>/dev/null; then - missing+=("$tool") +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 -done - -if (( ${#missing[@]} )); then - echo "❌ Missing required tools: ${missing[*]}" - exit 1 -fi -echo -e "✅ All required tools found: ${required_tools[*]}" +# 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_linux.sh" "b/script\360\237\226\211/build_linux.sh" new file mode 100755 index 0000000..4b7ac0c --- /dev/null +++ "b/script\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\360\237\226\211/build_linux_headers.sh" "b/script\360\237\226\211/build_linux_headers.sh" deleted file mode 100755 index 0e739e4..0000000 --- "a/script\360\237\226\211/build_linux_headers.sh" +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -set -euo pipefail - -source "$(dirname "$0")/environment.sh" - -echo "📦 Preparing Linux kernel headers for glibc and GCC..." - -mkdir -p "$LINUX_SRC" -pushd "$LINUX_SRC" - -if [ ! -f "$LINUX_TARBALL" ]; then - echo "⤵️ Downloading Linux $LINUX_VER headers..." - curl -LO "$LINUX_URL" -else - echo "✅ Kernel tarball already exists." -fi - -if [ ! -f Makefile ]; then - echo "📂 Extracting kernel sources..." - tar -xf "$LINUX_TARBALL" --strip-components=1 -else - echo "✅ Kernel source already extracted." -fi - -$MAKE mrproper -$MAKE headers_install ARCH=x86_64 INSTALL_HDR_PATH="$SYSROOT/usr" - -# Optional: check for successful header installation -if [[ ! -f "$SYSROOT/usr/include/linux/version.h" ]]; then - echo "❌ Kernel headers not found at expected location." - exit 1 -fi - -popd -echo "✅ Linux headers installed to $SYSROOT/usr/include" diff --git "a/script\360\237\226\211/clean_dist.sh" "b/script\360\237\226\211/clean_dist.sh" index 33ef605..009e01e 100755 --- "a/script\360\237\226\211/clean_dist.sh" +++ "b/script\360\237\226\211/clean_dist.sh" @@ -11,41 +11,20 @@ source "$(dirname "$0")/environment.sh" ! ! rmdir "$BUILD_DIR" >& /dev/null && echo "rmdir $BUILD_DIR" # Remove source +# note that repos are removed with clean_upstream # - for dir in "${SOURCE_DIR_LIST[@]}"; do - if [[ -d "$dir" ]]; then - echo "rm -r $dir" - rm -r "$dir" - fi - done + "./clean_source.sh" + "./clean_upstream.sh" + ! ! rmdir "$SRC" >& /dev/null && echo "rmdir $SRC" - -# Remove upstream -# - # walk the UPSTREAM_TARBALL_LIST triples - i=0 - while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do - tarball="${UPSTREAM_TARBALL_LIST[$i]}" - # skip URL at index i+1 - dir="${UPSTREAM_TARBALL_LIST[$((i+2))]}" - - tarball_path="$dir/$tarball" - if [[ -f "$tarball_path" ]]; then - echo "rm $tarball_path" - rm "$tarball_path" - fi - - i=$((i + 3)) - done ! ! 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" + ! rm -rf "$dir" && echo "could not remove $dir" fi done diff --git "a/script\360\237\226\211/clean_source.sh" "b/script\360\237\226\211/clean_source.sh" index 7144f15..2f5beb0 100755 --- "a/script\360\237\226\211/clean_source.sh" +++ "b/script\360\237\226\211/clean_source.sh" @@ -1,6 +1,6 @@ #!/bin/bash -# removes only the tarball expansions from upstream -# git repos are removed with `clean_upstream` +# removes project tarball expansions from source/ +# git repos are part of `upstream` so are not removed set -euo pipefail @@ -26,4 +26,4 @@ while [ $i -lt ${#UPSTREAM_TARBALL_LIST[@]} ]; do i=$((i + 1)) done -echo "✅ clean_source_expansion.sh" +echo "✅ clean_source.sh" diff --git "a/script\360\237\226\211/clean_source_expansion.sh" "b/script\360\237\226\211/clean_source_expansion.sh" deleted file mode 100755 index 847b33c..0000000 --- "a/script\360\237\226\211/clean_source_expansion.sh" +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -euo pipefail - -source "$(dirname "$0")/environment.sh" - -for dir in "${SOURCE_DIR_LIST[@]}"; do - if [[ -d "$dir" ]]; then - echo "rm -rf $dir" - rm -rf "$dir" - fi -done - -echo "✅ clean_source_expansion.sh" diff --git "a/script\360\237\226\211/clean_upstream.sh" "b/script\360\237\226\211/clean_upstream.sh" index 466aa2e..50e8d98 100755 --- "a/script\360\237\226\211/clean_upstream.sh" +++ "b/script\360\237\226\211/clean_upstream.sh" @@ -1,4 +1,9 @@ #!/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" diff --git "a/script\360\237\226\211/download_sources.sh" "b/script\360\237\226\211/download_sources.sh" index 17ce49e..2dd2dbc 100755 --- "a/script\360\237\226\211/download_sources.sh" +++ "b/script\360\237\226\211/download_sources.sh" @@ -1,22 +1,41 @@ #!/bin/bash -# this script can be run multiple times so as 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 +# 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() { - if ! curl -s --connect-timeout 5 https://example.com > /dev/null; then - echo "⚠️ No internet connection detected" + 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 - if ! curl -s --head "$url" | head -n 1 | grep -q "HTTP/1.1 200 OK"; then - echo "⚠️ Cannot reach $url" + + # Attempt to get the HTTP response code without following redirects + http_code=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 "$url") + + # If the HTTP code is between 200 and 299, consider it reachable + if [[ "$http_code" -ge 200 && "$http_code" -lt 300 ]]; then + echo "✅ Server $url is reachable (HTTP $http_code)" + else + # If not 2xx, print the status code for transparency + echo "⚠️ Server $url returned HTTP $http_code (proceeding with download anyway)" fi } @@ -29,9 +48,10 @@ download_file() { local file=$1 local url=$2 - echo "curl -LO $url" + 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" @@ -44,12 +64,15 @@ download_file() { } 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 @@ -65,6 +88,8 @@ fetch_tarballs() { } 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]}" @@ -72,11 +97,12 @@ fetch_git_repos() { 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 "git clone --branch $branch $repo $dir" + echo "Cloning $repo into $dir..." if ! git clone --branch "$branch" "$repo" "$dir"; then echo "❌ Failed to clone $repo → $dir" fi @@ -85,8 +111,15 @@ fetch_git_repos() { done } +# Show what will be downloaded +echo "Preparing to download the following sources:" +echo " - Linux kernel: $LINUX_TARBALL" +echo " - Binutils: $BINUTILS_TARBALL" +echo " - Glibc: $GLIBC_TARBALL" +echo " - GCC source: $GCC_REPO (branch $GCC_BRANCH)" + check_internet_connection fetch_tarballs fetch_git_repos -echo "✅ download_expand_source.sh" +echo "✅ download_expand_source.sh completed" diff --git "a/script\360\237\226\211/environment.sh" "b/script\360\237\226\211/environment.sh" index 93ad8a9..95747db 100755 --- "a/script\360\237\226\211/environment.sh" +++ "b/script\360\237\226\211/environment.sh" @@ -4,6 +4,22 @@ 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 @@ -105,16 +121,3 @@ cd $SCRIPT_DIR -#-------------------------------------------------------------------------------- -# tools - - # machine target - export HOST=$(gcc -dumpmachine) - - export MAKE_JOBS=$(nproc) - export MAKE="make -j$MAKE_JOBS" - - # Compiler path prefixes - export CC_FOR_BUILD=$(command -v gcc) - export CXX_FOR_BUILD=$(command -v g++) - diff --git "a/script\360\237\226\211/prepare_gcc_sources.sh" "b/script\360\237\226\211/prepare_gcc_sources.sh" deleted file mode 100755 index d769c93..0000000 --- "a/script\360\237\226\211/prepare_gcc_sources.sh" +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -set -euo pipefail -source "$(dirname "$0")/environment.sh" - -mkdir -p "$GCC_SRC" -pushd "$GCC_SRC" - -if [ ! -d .git ]; then - echo "⤵️ Cloning GCC source..." - git clone "$GCC_REPO" "$GCC_SRC" - git checkout -b RT_mods origin/"$GCC_BRANCH" -else - echo "✅ GCC repository already exists." - git fetch origin - if git show-ref --quiet refs/heads/RT_mods; then - git checkout RT_mods - else - git checkout -b RT_mods origin/"$GCC_BRANCH" - fi -fi - -./contrib/download_prerequisites - -popd diff --git "a/script\360\237\226\211/prepare_glibc_sources.sh" "b/script\360\237\226\211/prepare_glibc_sources.sh" deleted file mode 100755 index 6f287c5..0000000 --- "a/script\360\237\226\211/prepare_glibc_sources.sh" +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -set -euo pipefail - -source "$(dirname "$0")/environment.sh" - -mkdir -p "$GLIBC_SRC" -pushd "$GLIBC_SRC" - -if [ ! -f "$GLIBC_TARBALL" ]; then - echo "⤵️ Downloading glibc $GLIBC_VER..." - curl -LO "$GLIBC_URL" -else - echo "✅ $GLIBC_TARBALL already exists." -fi - -if [ ! -f configure ]; then - echo "📦 Extracting glibc $GLIBC_VER..." - tar -xzf "$GLIBC_TARBALL" --strip-components=1 - if [[ ! -f configure || ! -d elf ]]; then - echo "❌ glibc extraction failed." - exit 1 - fi -else - echo "✅ glibc source already extracted." -fi - -popd