{ pkgs, binutils }: let stdenv = pkgs.stdenv; nativePackages = with pkgs; [ cmake zlib bison ]; name = "gcc"; version = "15.2.0"; src = pkgs.fetchurl { url = "https://ftp.fau.de/gnu/${name}/${name}-${version}/${name}-${version}.tar.xz"; hash = "sha256-Q4/ZloJrDIJIWinaA6ctcdbjVBqD7HAt9Ccfb+Al0k4="; }; # Attributes for stdenv.mkDerivation can be found at: # https://nixos.org/manual/nixpkgs/stable/#sec-tools-of-stdenv gccPkg = stdenv.mkDerivation { /* Nixpkgs derivations automatically enable a few hardening flags, including some that cause non-literal format strings to become errors. https://nixos.org/manual/nixpkgs/stable/#sec-hardening-in-nixpkgs You can disable this particular one with */ hardeningDisable = [ "format" ]; /* But really the package author should be notified of the issue, and a patch should be applied. Even if it's clear that it's safe (it's probably not), NixOS is far from the only organization that enables hardening flags like this by default. */ inherit name version src; secondarySrcs = [ (pkgs.fetchurl { url = "https://ftp.fau.de/gnu/mpfr/mpfr-4.2.2.tar.xz"; hash = "sha256-tnugOD736KhWNzTi6InvXsPDuJigHQD6CmhprYHGzgE="; }) (pkgs.fetchurl { url = "https://ftp.fau.de/gnu/gmp/gmp-6.3.0.tar.xz"; hash = "sha256-o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg="; }) (pkgs.fetchurl { url = "https://ftp.fau.de/gnu/mpc/mpc-1.3.1.tar.gz"; hash = "sha256-q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; }) ]; nativeBuildInputs = nativePackages ++ [ binutils ]; buildInputs = with pkgs; [ gcc ]; prePhases = " prepEnvironmentPhase "; prepEnvironmentPhase = '' export LFS_TGT=$(uname -m)-lfs-linux-gnu export BINTOOLS=${binutils} export LFS=$(pwd) export LFSTOOLS=$(pwd)/tools export PATH=$LFSTOOLS/bin:$PATH export CONFIG_SITE=$LFS/usr/share/config.site cp -r $BINTOOLS/* $LFS chmod -R u+w $LFS ''; # Adding mpc, gmp, and mpfr to gcc source repo. patchPhase = '' export SOURCE=/build/$sourceRoot for secSrc in $secondarySrcs; do case $secSrc in *.xz) tar -xJf $secSrc -C ../$sourceRoot/ ;; *.gz) tar -xzf $secSrc -C ../$sourceRoot/ ;; *) echo " Invalid filetype: $secSrc " exit 1 ;; esac srcDir=$(echo $secSrc | sed 's/^[^-]*-\(.*\)\.tar.*/\1/') echo " Src: $srcDir " newDir=$(echo $secSrc | cut -d'-' -f2) echo " newDir: $newDir " mv -v ./$srcDir ./$newDir done sed -e '/m64=/s/lib64/lib/' \ -e '/m32=/s/m32=.*/m32=..\/lib32$(call if_multiarch,:i386-linux-gnu)/' \ -i.orig gcc/config/i386/t-linux64 sed '/STACK_REALIGN_DEFAULT/s/0/(!TARGET_64BIT \&\& TARGET_SSE)/' \ -i gcc/config/i386/i386.h ''; # CFLAGS and CXXFLAGS added to dodge string literal warning error. configurePhase = '' echo " Starting config " mkdir -v build cd build mlist=m64,m32 ../configure \ --target=$LFS_TGT \ --prefix=$LFSTOOLS \ --with-glibc-version=2.42 \ --with-sysroot=$LFS \ --with-newlib \ --without-headers \ --enable-default-pie \ --enable-default-ssp \ --enable-initfini-array \ --disable-nls \ --disable-shared \ --enable-multilib --with-multilib-list=$mlist \ --disable-decimal-float \ --disable-threads \ --disable-libatomic \ --disable-libgomp \ --disable-libquadmath \ --disable-libssp \ --disable-libvtv \ --disable-libstdcxx \ --enable-languages=c,c++ ''; # Path to the GCC source headers is in gcc dir of source folder. # Concatenate these to create/populate internal limits.h of crossGcc postInstall = '' echo " Install complete." cat $LFS/$sourceRoot/gcc/limitx.h $LFS/$sourceRoot/gcc/glimits.h $LFS/$sourceRoot/gcc/limity.h > \ $(dirname $($LFSTOOLS/bin/$LFS_TGT-gcc -print-libgcc-file-name))/include/limits.h rm -r $LFS/$sourceRoot cp -rvp $LFS/* $out/ ''; shellHook = '' echo -e "\033 [ 31 mNix Develop -> $name: Loading...\033 [ 0 m " if [[ "$(basename $(pwd)) " != "$name " ]]; then mkdir -p "$name " cd "$name " fi eval "$prepEnvironmentPhase " echo -e "\033 [ 36 mNix Develop -> $name: Loaded.\033[0m " echo -e "\033 [ 36 mNix Develop -> Current directory: $(pwd)\033 [ 0 m " ''; }; in gccPkg