+sub make_debug {
+ my $file=shift;
+ my $tmp=shift;
+ my $desttmp=shift;
+
+ # Don't try to copy debug symbols out if the file is already
+ # stripped.
+ return unless get_file_type($file) =~ /not stripped/;
+
+ my ($base_file)=$file=~/^\Q$tmp\E(.*)/;
+ my $debug_path;
+ if (! compat(8) &&
+ `readelf -n $file`=~ /^\s+Build ID: ([0-9a-f]{2})([0-9a-f]+)$/m) {
+ $debug_path=$desttmp."/usr/lib/debug/.build-id/$1/$2.debug"
+ }
+ else {
+ $debug_path=$desttmp."/usr/lib/debug/".$base_file;
+ }
+ my $debug_dir=dirname($debug_path);
+ if (! -d $debug_dir) {
+ doit("install", "-d", $debug_dir);
+ }
+ if (compat(8)) {
+ doit($objcopy, "--only-keep-debug", $file, $debug_path);
+ }
+ else {
+ doit($objcopy, "--only-keep-debug", "--compress-debug-sections", $file, $debug_path);
+ }
+ # No reason for this to be executable.
+ doit("chmod", 644, $debug_path);
+ return $debug_path;
+}
+
+sub attach_debug {
+ my $file=shift;
+ my $debug_path=shift;
+ doit($objcopy, "--add-gnu-debuglink", $debug_path, $file);
+}
+