#!/bin/bash # ============================================================================ # DarkForge Linux — Phase 0, Chapter 5: GCC Pass 1 # ============================================================================ # Purpose: Build the cross-compiler (GCC) as the second component of the # cross-toolchain. This produces a C/C++ compiler that runs on the # host but generates code for the target (x86_64-darkforge-linux-gnu). # No hardware-specific flags (-march=znver5) yet — those come later # when we have a native compiler. # Inputs: ${LFS}/sources/gcc-15.2.0.tar.xz, mpfr, gmp, mpc tarballs # Outputs: Cross-GCC installed to ${LFS}/tools/ # Assumes: Binutils Pass 1 complete, running as 'lfs' user # Ref: LFS 13.0 §5.3 # ============================================================================ set -euo pipefail source "${LFS}/sources/darkforge-env.sh" PACKAGE="gcc" VERSION="15.2.0" SRCDIR="${LFS}/sources" echo "=== Building ${PACKAGE}-${VERSION} (Cross-Toolchain Pass 1) ===" 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 on x86_64 # GCC defaults to installing 64-bit libraries in lib64, but LFS/DarkForge # uses a unified /usr/lib directory. This sed changes the default. case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64 ;; esac mkdir -v build cd build # Configure cross-compiler # --target=$LFS_TGT: cross-compile for our target # --with-glibc-version=2.43: tell GCC which glibc version to expect # --with-newlib: inhibit building libc-dependent code (no libc yet) # --without-headers: don't look for system headers yet # --enable-default-pie: position-independent executables by default (security) # --enable-default-ssp: stack smashing protection by default (security) # --disable-shared: static link GCC internal libraries # --disable-multilib: no 32-bit support in the cross-compiler # (multilib will be addressed later for Steam/Wine compatibility) # --disable-threads: no threading support yet (no glibc/pthreads) # --disable-lib*: disable libraries that aren't needed at this stage # --enable-languages=c,c++: only C and C++ compilers needed ../configure \ --target="${LFS_TGT}" \ --prefix="${LFS}/tools" \ --with-glibc-version=2.43 \ --with-sysroot="${LFS}" \ --with-newlib \ --without-headers \ --enable-default-pie \ --enable-default-ssp \ --disable-nls \ --disable-shared \ --disable-multilib \ --disable-threads \ --disable-libatomic \ --disable-libgomp \ --disable-libquadmath \ --disable-libssp \ --disable-libvtv \ --disable-libstdcxx \ --enable-languages=c,c++ make make install # Create the full version of the internal limits.h header # GCC needs this to properly handle system limits.h cd .. cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \ "$(dirname "$("${LFS_TGT}-gcc" -print-libgcc-file-name)")/include/limits.h" # Cleanup cd "${SRCDIR}" rm -rf "${PACKAGE}-${VERSION}" echo "=== ${PACKAGE}-${VERSION} Pass 1 complete ==="