checkpoint working on standalone build scripts
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Mon, 5 May 2025 05:25:56 +0000 (22:25 -0700)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Mon, 5 May 2025 05:25:56 +0000 (22:25 -0700)
14 files changed:
script🖉/build_Linux_requisites.sh [new file with mode: 0644]
script🖉/build_all.sh
script🖉/build_binutils.sh
script🖉/build_binutils_requisites.sh
script🖉/build_linux.sh [new file with mode: 0755]
script🖉/build_linux_headers.sh [deleted file]
script🖉/clean_dist.sh
script🖉/clean_source.sh
script🖉/clean_source_expansion.sh [deleted file]
script🖉/clean_upstream.sh
script🖉/download_sources.sh
script🖉/environment.sh
script🖉/prepare_gcc_sources.sh [deleted file]
script🖉/prepare_glibc_sources.sh [deleted file]

diff --git a/script🖉/build_Linux_requisites.sh b/script🖉/build_Linux_requisites.sh
new file mode 100644 (file)
index 0000000..42fa7b7
--- /dev/null
@@ -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
index af88bf6..920a8f7 100755 (executable)
@@ -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
index 114bc94..959e91c 100755 (executable)
@@ -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
+
index 7a3e116..871c68c 100755 (executable)
@@ -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🖉/build_linux.sh b/script🖉/build_linux.sh
new file mode 100755 (executable)
index 0000000..4b7ac0c
--- /dev/null
@@ -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🖉/build_linux_headers.sh b/script🖉/build_linux_headers.sh
deleted file mode 100755 (executable)
index 0e739e4..0000000
+++ /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"
index 33ef605..009e01e 100755 (executable)
@@ -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
 
index 7144f15..2f5beb0 100755 (executable)
@@ -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🖉/clean_source_expansion.sh b/script🖉/clean_source_expansion.sh
deleted file mode 100755 (executable)
index 847b33c..0000000
+++ /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"
index 466aa2e..50e8d98 100755 (executable)
@@ -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"
index 17ce49e..2dd2dbc 100755 (executable)
@@ -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"
index 93ad8a9..95747db 100755 (executable)
@@ -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🖉/prepare_gcc_sources.sh b/script🖉/prepare_gcc_sources.sh
deleted file mode 100755 (executable)
index d769c93..0000000
+++ /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🖉/prepare_glibc_sources.sh b/script🖉/prepare_glibc_sources.sh
deleted file mode 100755 (executable)
index 6f287c5..0000000
+++ /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