Files
nixpkgs/pkgs/development/compilers/gcc/ng/common/libiberty/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

74 lines
1.3 KiB
Nix

{
lib,
stdenv,
gcc_meta,
release_version,
version,
monorepoSrc ? null,
runCommand,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "libiberty";
inherit version;
src = runCommand "libiberty-src-${version}" { src = monorepoSrc; } (
''
runPhase unpackPhase
mkdir -p "$out/gcc"
cp gcc/BASE-VER "$out/gcc"
cp gcc/DATESTAMP "$out/gcc"
cp -r include "$out"
cp -r libiberty "$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"
];
enableParallelBuilding = true;
sourceRoot = "${finalAttrs.src.name}/libiberty";
preConfigure = ''
mkdir ../../build
cd ../../build
configureScript=../$sourceRoot/configure
'';
configureFlags = [
"--enable-install-libiberty"
]
++ lib.optional (!stdenv.hostPlatform.isStatic) "--enable-shared";
postInstall = ''
cp pic/libiberty.a $out/lib/libiberty_pic.a
'';
doCheck = true;
passthru = {
isGNU = true;
};
meta = gcc_meta // {
homepage = "https://gcc.gnu.org/";
};
})