#!/bin/bash # ============================================================================ # DarkForge Linux — Phase 0, Chapter 6: GCC Pass 2 # ============================================================================ # Purpose: Rebuild GCC with the temporary toolchain. This produces a # compiler that runs on the target and generates code for the target. # Unlike Pass 1, this includes libstdc++, threading, and shared libs. # Hardware-specific flags (-march=znver5) are STILL not applied here; # they come when we build the final native GCC in the chroot. # Inputs: ${LFS}/sources/gcc-15.2.0.tar.xz + mpfr, gmp, mpc # Outputs: Full GCC in ${LFS}/usr/ # Assumes: All Chapter 5 + Chapter 6 packages (006-021) complete # Ref: LFS 13.0 §6.18 # ============================================================================ set -euo pipefail source "${LFS}/sources/darkforge-env.sh" PACKAGE="gcc" VERSION="15.2.0" SRCDIR="${LFS}/sources" echo "=== Building ${PACKAGE}-${VERSION} (Pass 2) ===" cd "${SRCDIR}" tar -xf "${PACKAGE}-${VERSION}.tar.xz" cd "${PACKAGE}-${VERSION}" # Extract and link GCC's arithmetic library dependencies tar -xf ../mpfr-4.2.2.tar.xz mv -v mpfr-4.2.2 mpfr tar -xf ../gmp-6.3.0.tar.xz mv -v gmp-6.3.0 gmp tar -xf ../mpc-1.3.1.tar.gz mv -v mpc-1.3.1 mpc # Fix lib64 directory naming (same as Pass 1) case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64 ;; esac # Override the default build rule for libgcc and libstdc++ headers # to use our target-specific header directory sed '/thread_header =/s/@.*@/gthr-posix.h/' \ -i libgcc/Makefile.in libstdc++-v3/include/Makefile.in mkdir -v build cd build # Configure GCC Pass 2 # Key differences from Pass 1: # --with-build-sysroot=$LFS: use target sysroot during build # --enable-default-pie/ssp: security hardening # --disable-bootstrap: skip the 3-stage bootstrap (not building natively yet) ../configure \ --build="$(../config.guess)" \ --host="${LFS_TGT}" \ --target="${LFS_TGT}" \ LDFLAGS_FOR_TARGET=-L"${PWD}/${LFS_TGT}/libgcc" \ --prefix=/usr \ --with-build-sysroot="${LFS}" \ --enable-default-pie \ --enable-default-ssp \ --disable-nls \ --disable-multilib \ --disable-libatomic \ --disable-libgomp \ --disable-libquadmath \ --disable-libsanitizer \ --disable-libssp \ --disable-libvtv \ --enable-languages=c,c++ make make DESTDIR="${LFS}" install # Create cc symlink (many build systems expect 'cc' to exist) ln -sfv gcc "${LFS}/usr/bin/cc" # Cleanup cd "${SRCDIR}" rm -rf "${PACKAGE}-${VERSION}" echo "=== ${PACKAGE}-${VERSION} Pass 2 complete ===" echo "" echo ">>> Cross-compilation phase (Chapters 5+6) COMPLETE." echo ">>> Next: Enter chroot environment (Chapter 7 scripts)."