#!/usr/bin/env bash # scripts/01-toolchain.sh — cross toolchain in $AEROS_TOOLS (LFS ch. 5). # Builds: binutils (pass1) -> gcc (pass1) -> linux headers -> glibc -> libstdc++. # Run as the unprivileged build user with write access to $AEROS_ROOT. source "$(dirname "${BASH_SOURCE[0]}")/lib/common.sh" deny_root export LFS="$AEROS_ROOT" export LC_ALL=POSIX export AEROS_TGT="$AEROS_TARGET_TRIPLET" export PATH="$AEROS_TOOLS/bin:/usr/bin:/bin" export CONFIG_SITE="$LFS/usr/share/config.site" WORK="$AEROS_SOURCES/work-toolchain" mkdir -p "$WORK"; cd "$WORK" # ---------------------------------------------------------------- binutils p1 build_binutils_pass1() { local d; d="$(cd "$WORK" && unpack binutils)"; cd "$WORK/$d" mkdir -v build; cd build ../configure --prefix="$AEROS_TOOLS" \ --with-sysroot="$LFS" --target="$AEROS_TGT" \ --disable-nls --enable-gprofng=no --disable-werror \ --enable-new-dtags --enable-default-hash-style=gnu make make install } # ---------------------------------------------------------------- gcc pass1 build_gcc_pass1() { local d; d="$(cd "$WORK" && unpack gcc)"; cd "$WORK/$d" ( cd "$WORK/$d"; tar -xf "$AEROS_SOURCES/$(pkg_tarball mpfr)"; mv -v "$(pkg_srcdir mpfr)" mpfr tar -xf "$AEROS_SOURCES/$(pkg_tarball gmp)"; mv -v "$(pkg_srcdir gmp)" gmp tar -xf "$AEROS_SOURCES/$(pkg_tarball mpc)"; mv -v "$(pkg_srcdir mpc)" mpc ) case "$AEROS_ARCH" in x86_64) sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64 ;; esac mkdir -v build; cd build ../configure --target="$AEROS_TGT" --prefix="$AEROS_TOOLS" \ --with-glibc-version=2.41 --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 # full internal headers (limits.h) local gccsrc="$WORK/$d" cat "$gccsrc"/gcc/limitx.h "$gccsrc"/gcc/glimits.h "$gccsrc"/gcc/limity.h > \ "$(dirname "$("$AEROS_TGT"-gcc -print-libgcc-file-name)")/include/limits.h" } # ---------------------------------------------------------------- linux headers build_linux_headers() { local d; d="$(cd "$WORK" && unpack linux)"; cd "$WORK/$d" make mrproper make headers find usr/include -type f ! -name '*.h' -delete mkdir -p "$LFS/usr" cp -rv usr/include "$LFS/usr" } # ---------------------------------------------------------------- glibc build_glibc() { local d; d="$(cd "$WORK" && unpack glibc)"; cd "$WORK/$d" case "$AEROS_ARCH" in x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 "$LFS/lib64" ln -sfv ../lib/ld-linux-x86-64.so.2 "$LFS/lib64/ld-lsb-x86-64.so.3" ;; esac # glibc <= 2.41 unconditionally redefines OPEN_TREE_CLONE (and a couple of # siblings) *after* including . Linux >= 7.x defines # OPEN_TREE_CLONE with different macro text, so -Werror aborts. Keep the # include (so linux/mount.h's guard coordinates struct mount_attr) and just # guard the conflicting macros with #ifndef. sed -i -E 's@^#define (OPEN_TREE_CLONE|OPEN_TREE_CLOEXEC|FSOPEN_CLOEXEC)([ \t].*)?$@#ifndef \1\n#define \1\2\n#endif@' \ sysdeps/unix/sysv/linux/sys/mount.h mkdir -v build; cd build echo "rootsbindir=/usr/sbin" > configparms ../configure --prefix=/usr --host="$AEROS_TGT" --build="$(../scripts/config.guess)" \ --enable-kernel=5.4 --with-headers="$LFS/usr/include" \ --disable-nscd libc_cv_slibdir=/usr/lib make make DESTDIR="$LFS" install sed '/RTLDLIST=/s@/usr@@g' -i "$LFS/usr/bin/ldd" # sanity check echo 'int main(){}' > /tmp/aeros-dummy.c "$AEROS_TGT"-gcc /tmp/aeros-dummy.c -o /tmp/aeros-dummy readelf -l /tmp/aeros-dummy | grep -q 'ld-linux' \ && ok "glibc toolchain links correctly" || die "toolchain sanity check FAILED" rm -f /tmp/aeros-dummy* } # ---------------------------------------------------------------- libstdc++ build_libstdcxx() { local d; d="$(cd "$WORK" && unpack gcc)"; cd "$WORK/$d" mkdir -v build-libstdcxx; cd build-libstdcxx ../libstdc++-v3/configure --host="$AEROS_TGT" --build="$(../config.guess)" \ --prefix=/usr --disable-multilib --disable-nls \ --disable-libstdcxx-pch \ --with-gxx-include-dir="/tools/$AEROS_TGT/include/c++/15.1.0" make make DESTDIR="$LFS" install rm -v "$LFS"/usr/lib/lib{stdc++{,exp,fs},supc++}.la 2>/dev/null || true } step "AeroOS cross-toolchain → $AEROS_TOOLS" once tc-binutils-pass1 build_binutils_pass1 once tc-gcc-pass1 build_gcc_pass1 once tc-linux-headers build_linux_headers once tc-glibc build_glibc once tc-libstdcxx build_libstdcxx ok "cross-toolchain complete"