#! /usr/bin/perl

# Usage
#
# 1. debuginfodeps <image_name>
#
#   Reads build ids from tmp/<image_name>.debugids and writes debuginfo
#   requires to images/instsys/usr/share/debuginfodeps/<image_name>.
#


$image = shift;
$dst = "$ENV{DESTDIR}/usr/share/debuginfodeps";

die "$image: no package list" unless -f "tmp/$image.rpmlog";
die "$dst: no debuginfodeps directory\n" unless -d $dst;

open $f, "tmp/$image.debugids";
my %ids;
while ( <$f> ){
 chomp;
 next unless (m/^(.*) (.*)/);
 my $id = $1;
 my $file = $2;

 # black list strange binaries
 next if ($file =~ m,/usr/bin/syslinux,);
 next if ($file =~ m,/sbin/lilo,);
 next if ($file =~ m,/usr/lib/getconf/,);
 # non-stripped
 next if ($file =~ m,/usr/lib/pt_chown,);
 # faked ELF binary with just data
 next if ($file =~ m,/libicudata.so.,);

 # too large to be useful
 next if ($file =~ m,/usr/lib.*/dri/,);
 $ids{$id} = $file;
}
close $f;

open $d, ">", "$dst/$image";

for (sort keys %ids) {
  print $d "# $ids{$_}\n";
  print $d "debuginfo(build-id) = $_\n";
}

close($d);
