2023-08-08 04:51:23 +00:00
|
|
|
{ lib, stdenvNoLibs, buildPackages
|
|
|
|
, gcc, glibc
|
|
|
|
, libiberty
|
|
|
|
}:
|
|
|
|
|
2023-08-08 09:01:43 +00:00
|
|
|
let
|
|
|
|
gccConfigureFlags = gcc.cc.configureFlags ++ [
|
|
|
|
"--build=${stdenvNoLibs.buildPlatform.config}"
|
|
|
|
"--host=${stdenvNoLibs.buildPlatform.config}"
|
|
|
|
"--target=${stdenvNoLibs.hostPlatform.config}"
|
|
|
|
|
|
|
|
"--disable-bootstrap"
|
|
|
|
"--disable-multilib" "--with-multilib-list="
|
|
|
|
"--enable-languages=c"
|
|
|
|
|
|
|
|
"--disable-fixincludes"
|
|
|
|
"--disable-intl"
|
|
|
|
"--disable-lto"
|
|
|
|
"--disable-libatomic"
|
|
|
|
"--disable-libbacktrace"
|
|
|
|
"--disable-libcpp"
|
|
|
|
"--disable-libssp"
|
|
|
|
"--disable-libquadmath"
|
|
|
|
"--disable-libgomp"
|
|
|
|
"--disable-libvtv"
|
|
|
|
"--disable-vtable-verify"
|
|
|
|
|
|
|
|
"--with-system-zlib"
|
|
|
|
] ++ lib.optional (stdenvNoLibs.hostPlatform.libc == "glibc")
|
|
|
|
"--with-glibc-version=${glibc.version}";
|
|
|
|
|
|
|
|
in stdenvNoLibs.mkDerivation (finalAttrs: {
|
2023-08-08 04:51:23 +00:00
|
|
|
pname = "libgcc";
|
|
|
|
inherit (gcc.cc) src version;
|
|
|
|
|
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
|
|
|
nativeBuildInputs = [ libiberty ];
|
2023-08-08 09:02:04 +00:00
|
|
|
buildInputs = [ glibc ];
|
2023-08-08 04:51:23 +00:00
|
|
|
|
|
|
|
postUnpack = ''
|
|
|
|
mkdir -p ./build
|
|
|
|
buildRoot=$(readlink -e "./build")
|
|
|
|
'';
|
|
|
|
|
2023-08-08 09:02:46 +00:00
|
|
|
postPatch =
|
|
|
|
gcc.cc.passthru.forceLibgccToBuildCrtStuff
|
|
|
|
+ ''
|
|
|
|
sourceRoot=$(readlink -e "./libgcc")
|
|
|
|
'';
|
2023-08-08 04:51:23 +00:00
|
|
|
|
|
|
|
hardeningDisable = [ "pie" ];
|
|
|
|
|
2023-08-08 08:59:55 +00:00
|
|
|
preConfigure =
|
2023-08-08 04:51:23 +00:00
|
|
|
''
|
2023-08-08 08:59:55 +00:00
|
|
|
# Drop in libiberty, as external builds are not expected
|
|
|
|
cd "$buildRoot"
|
2023-08-08 04:51:23 +00:00
|
|
|
(
|
|
|
|
mkdir -p build-${stdenvNoLibs.buildPlatform.config}/libiberty/
|
|
|
|
cd build-${stdenvNoLibs.buildPlatform.config}/libiberty/
|
|
|
|
ln -s ${buildPackages.libiberty}/lib/libiberty.a ./
|
|
|
|
)
|
|
|
|
mkdir -p "$buildRoot/gcc"
|
|
|
|
cd "$buildRoot/gcc"
|
|
|
|
(
|
2023-08-08 08:59:55 +00:00
|
|
|
# We "shift" the tools over to fake platforms perspective from the previous stage.
|
2023-08-08 04:51:23 +00:00
|
|
|
export AS_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$AS_FOR_BUILD
|
|
|
|
export CC_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CC_FOR_BUILD
|
|
|
|
export CPP_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CPP_FOR_BUILD
|
|
|
|
export CXX_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CXX_FOR_BUILD
|
|
|
|
export LD_FOR_BUILD=${buildPackages.stdenv.cc.bintools}/bin/$LD_FOR_BUILD
|
|
|
|
|
|
|
|
export AS=$AS_FOR_BUILD
|
|
|
|
export CC=$CC_FOR_BUILD
|
|
|
|
export CPP=$CPP_FOR_BUILD
|
|
|
|
export CXX=$CXX_FOR_BUILD
|
|
|
|
export LD=$LD_FOR_BUILD
|
|
|
|
|
|
|
|
export AS_FOR_TARGET=${stdenvNoLibs.cc}/bin/$AS
|
|
|
|
export CC_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CC
|
|
|
|
export CPP_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CPP
|
|
|
|
export LD_FOR_TARGET=${stdenvNoLibs.cc.bintools}/bin/$LD
|
|
|
|
|
2023-08-08 08:59:55 +00:00
|
|
|
# We define GENERATOR_FILE so nothing bothers looking for GNU GMP.
|
2023-08-08 04:51:23 +00:00
|
|
|
export NIX_CFLAGS_COMPILE_FOR_BUILD+=' -DGENERATOR_FILE=1'
|
|
|
|
|
2023-08-08 09:01:43 +00:00
|
|
|
"$sourceRoot/../gcc/configure" ${lib.concatStringsSep " " gccConfigureFlags}
|
2023-08-08 04:51:23 +00:00
|
|
|
|
2023-08-08 08:59:55 +00:00
|
|
|
# We remove the `libgcc.mvar` deps so that the bootstrap xgcc isn't built.
|
2023-08-08 04:51:23 +00:00
|
|
|
sed -e 's,libgcc.mvars:.*$,libgcc.mvars:,' -i Makefile
|
|
|
|
|
|
|
|
make \
|
|
|
|
config.h \
|
|
|
|
libgcc.mvars \
|
|
|
|
tconfig.h \
|
|
|
|
tm.h \
|
|
|
|
options.h \
|
|
|
|
insn-constants.h \
|
|
|
|
insn-modes.h
|
|
|
|
)
|
|
|
|
mkdir -p "$buildRoot/gcc/include"
|
2023-08-08 08:59:55 +00:00
|
|
|
|
|
|
|
# Preparing to configure + build libgcc itself
|
2023-08-08 04:51:23 +00:00
|
|
|
mkdir -p "$buildRoot/gcc/${stdenvNoLibs.hostPlatform.config}/libgcc"
|
|
|
|
cd "$buildRoot/gcc/${stdenvNoLibs.hostPlatform.config}/libgcc"
|
|
|
|
configureScript=$sourceRoot/configure
|
|
|
|
chmod +x "$configureScript"
|
|
|
|
|
|
|
|
export AS_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$AS_FOR_BUILD
|
|
|
|
export CC_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CC_FOR_BUILD
|
|
|
|
export CPP_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CPP_FOR_BUILD
|
|
|
|
export CXX_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CXX_FOR_BUILD
|
|
|
|
export LD_FOR_BUILD=${buildPackages.stdenv.cc.bintools}/bin/$LD_FOR_BUILD
|
|
|
|
|
|
|
|
export AS=${stdenvNoLibs.cc}/bin/$AS
|
|
|
|
export CC=${stdenvNoLibs.cc}/bin/$CC
|
|
|
|
export CPP=${stdenvNoLibs.cc}/bin/$CPP
|
|
|
|
export CXX=${stdenvNoLibs.cc}/bin/$CXX
|
|
|
|
export LD=${stdenvNoLibs.cc.bintools}/bin/$LD
|
|
|
|
|
|
|
|
export AS_FOR_TARGET=${stdenvNoLibs.cc}/bin/$AS_FOR_TARGET
|
|
|
|
export CC_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CC_FOR_TARGET
|
|
|
|
export CPP_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CPP_FOR_TARGET
|
|
|
|
export LD_FOR_TARGET=${stdenvNoLibs.cc.bintools}/bin/$LD_FOR_TARGET
|
|
|
|
'';
|
|
|
|
|
|
|
|
configurePlatforms = [ "build" "host" ];
|
|
|
|
configureFlags = [
|
|
|
|
"cross_compiling=true"
|
|
|
|
"--disable-gcov"
|
2023-08-08 09:03:40 +00:00
|
|
|
"--with-glibc-version=${glibc.version}"
|
2023-08-08 04:51:23 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
makeFlags = [ "MULTIBUILDTOP:=../" ];
|
|
|
|
|
|
|
|
postInstall = ''
|
2023-08-08 09:00:33 +00:00
|
|
|
moveToOutput "lib/gcc/${stdenvNoLibs.hostPlatform.config}/${finalAttrs.version}/include" "$dev"
|
2023-08-08 04:51:23 +00:00
|
|
|
mkdir -p "$out/lib" "$dev/include"
|
2023-08-08 09:00:33 +00:00
|
|
|
ln -s "$out/lib/gcc/${stdenvNoLibs.hostPlatform.config}/${finalAttrs.version}"/* "$out/lib"
|
|
|
|
ln -s "$dev/lib/gcc/${stdenvNoLibs.hostPlatform.config}/${finalAttrs.version}/include"/* "$dev/include/"
|
2023-08-08 04:51:23 +00:00
|
|
|
'';
|
2023-08-08 09:00:33 +00:00
|
|
|
})
|