--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "📦 Checking requisites for Linux kernel headers build."
+
+missing_requisite_list=()
+found_requisite_list=()
+
+# tools required for build
+#
+required_tools=(
+ "gcc"
+ "g++"
+ "make"
+)
+
+for tool in "${required_tools[@]}"; do
+ location=$(command -v "$tool") # Fixed this part to use $tool instead of "tool"
+ if [ $? -eq 0 ]; then # Check if the command was successful
+ found_requisite_list+=("$location")
+ else
+ missing_requisite_list+=("$tool")
+ fi
+done
+
+# source code required for build
+#
+if [ -d "$LINUX_SRC" ] && [ "$(ls -A "$LINUX_SRC")" ]; then
+ found_requisite_list+=("$LINUX_SRC")
+else
+ missing_requisite_list+=("$LINUX_SRC")
+fi
+
+# print requisites found
+#
+if (( ${#found_requisite_list[@]} != 0 )); then
+ echo "found:"
+ for found_requisite in "${found_requisite_list[@]}"; do
+ echo " $found_requisite"
+ done
+fi
+
+# print requisites missing
+#
+if (( ${#missing_requisite_list[@]} != 0 )); then
+ echo "missing:"
+ for missing_requisite in "${missing_requisite_list[@]}"; do
+ echo " $missing_requisite"
+ done
+fi
+
+# in conclusion
+#
+if (( ${#missing_requisite_list[@]} > 0 )); then
+ echo "❌ Missing requisites"
+ exit 1
+else
+ echo "✅ All checked specified requisites found"
+ exit 0
+fi
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
#!/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
+
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
--- /dev/null
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "📦 Preparing Linux kernel headers for glibc and GCC..."
+
+pushd "$LINUX_SRC"
+
+ $MAKE mrproper
+ $MAKE headers_install ARCH=x86_64 INSTALL_HDR_PATH="$SYSROOT/usr"
+
+ if [[ -f "$SYSROOT/usr/include/linux/version.h" ]]; then
+ echo "✅ Linux headers installed to $SYSROOT/usr/include"
+ exit 0
+ fi
+
+ echo "❌ Kernel headers not found at expected location."
+ exit 1
+
+popd
+++ /dev/null
-#!/bin/bash
-set -euo pipefail
-
-source "$(dirname "$0")/environment.sh"
-
-echo "📦 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"
! ! 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
#!/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
i=$((i + 1))
done
-echo "✅ clean_source_expansion.sh"
+echo "✅ clean_source.sh"
+++ /dev/null
-#!/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"
#!/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"
#!/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
}
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"
}
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
}
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]}"
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
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"
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
-#--------------------------------------------------------------------------------
-# 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++)
-
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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