Files
nixpkgs/pkgs/development/compilers/gcc/ng/common/libssp/default.nix
John Ericson be82056397 gcc/ng: cope with a source tree that is a VCS checkout
A release tarball carries generated files that a git tree does not, and
two of those bit us.

`MD5SUMS` is generated when a tarball is rolled. Each sub-source
extractor asserted `[[ -f MD5SUMS ]]` before copying it, so every one of
them failed outright the moment `monorepoSrc` was a git tree:

    unpacking source archive /nix/store/...-source
    source root is source
    <exit 1>

Copy it only when it is there.

The generated sources are the other half: a checkout lacks
`gengtype-lex.cc` and friends, which a tarball ships pre-built, so they
have to be regenerated. Take flex and bison as native inputs when
`fromVCS` says the source is a checkout.

Tarball builds are unaffected either way.

Assisted-by: Claude Code (Claude Opus 5)
2026-08-12 16:58:43 -04:00

107 lines
1.9 KiB
Nix

{
lib,
stdenv,
gcc_meta,
release_version,
version,
getVersionFile,
monorepoSrc ? null,
fetchpatch,
autoreconfHook269,
runCommand,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "libssp";
inherit version;
src = runCommand "libssp-src-${version}" { src = monorepoSrc; } (
''
runPhase unpackPhase
mkdir -p "$out/gcc"
cp gcc/BASE-VER "$out/gcc"
cp gcc/DATESTAMP "$out/gcc"
cp -r libssp "$out"
cp -r config "$out"
cp -r multilib.am "$out"
cp config.guess "$out"
cp config.rpath "$out"
cp config.sub "$out"
cp config-ml.in "$out"
cp ltmain.sh "$out"
cp install-sh "$out"
cp mkinstalldirs "$out"
''
# `MD5SUMS` exists only in release tarballs, not in a VCS checkout.
+ ''
if [[ -f MD5SUMS ]]; then cp MD5SUMS "$out"; fi
''
);
outputs = [
"out"
"dev"
];
patches = [
(fetchpatch {
name = "regular-libdir-includedir.patch";
url = "https://inbox.sourceware.org/gcc-patches/20250720172933.2404828-1-git@JohnEricson.me/raw";
hash = "sha256-W7dcy1Tm3O2reK7kx83DRv8W97qUfaqDbKLiLXIegRw=";
})
(getVersionFile "libssp/force-regular-dirs.patch")
];
postUnpack = ''
mkdir -p ./build
buildRoot=$(readlink -e "./build")
'';
preAutoreconf = ''
sourceRoot=$(readlink -e "./libssp")
cd $sourceRoot
'';
enableParallelBuilding = true;
nativeBuildInputs = [
autoreconfHook269
];
configurePlatforms = [
"build"
"host"
];
configureFlags = [
"--disable-dependency-tracking"
"cross_compiling=true"
"--disable-multilib"
];
preConfigure = ''
cd "$buildRoot"
configureScript=$sourceRoot/configure
'';
hardeningDisable = [
"fortify"
# Because we are building it!
"stackprotector"
];
doCheck = true;
passthru = {
isGNU = true;
};
meta = gcc_meta // {
homepage = "https://gcc.gnu.org/";
};
})