rpm-build/scripts/brp-debuginfo.in

80 lines
2.6 KiB
Plaintext
Raw Normal View History

#!/bin/sh -efu
#
# brp-debuginfo - generate /usr/lib/debug and /usr/src/debug contents
# for debuginfo packages
#
# Written by Alexey Tourbin <at@altlinux.org>. Based on find-debuginfo.sh
# by Jeff Johnson <jbj@rpm5.org> and Roland McGrath <roland@redhat.com>.
# Copyright (c) 2020 Vitaly Chikunov <vt@altlinux.org>.
# License: GPLv2+.
. @RPMCONFIGDIR@/functions
ValidateBuildRoot
cd "$RPM_BUILD_ROOT"
2011-01-14 06:45:20 +03:00
rm -rf .tmp
mkdir .tmp
# Strip binaries, create .debug files under /usr/lib/debug and install sources into /usr/src/debug.
: ${RPM_DEBUGINFO_SKIPLIST:=}
prune_paths="/lib/firmware /usr/lib/debug /usr/share /usr/src $RPM_DEBUGINFO_SKIPLIST"
prune_tests="$(printf %s "$prune_paths" |
tr '[:space:]' '\n' |
sort -u |
sed -n '/^\// s/.*/ -o -path .&/p')"
find . '(' -path './.*' $prune_tests ')' -prune -o -type f -print |sort |
file -NF$'\t' -f - |
sed -n -e '/ ELF .* shared object, no machine, /d' \
-e 's/\t.* ELF .* \(executable\|shared object\), .*, not stripped.*//p' \
-e 's/^\(\.\/lib\/modules\/[^[:space:]]\+\.ko\)\t.* ELF .* relocatable, .*, not stripped.*/\1/p' \
-e 's/^\(\.\/lib\/modules\/[^[:space:]]\+\.ko\.[gx]z\)\t.* \(gzip\|xz\) compressed data.*/\1/p' \
-e 's/^\(\.\/boot\/vmlinuz-[^[:space:]]\+\)\t.*/\1/p' |
xargs -r --delimiter='\n' stat -c '%h %i %n' >.tmp/flist
# Filter out what will be hard-linked later and process the rest.
while read -r nlink ino f; do
if [ "$nlink" -gt 1 ]; then
eval f0="\${f0_$ino-}"
if [ -n "$f0" ]; then
printf '%u %s\n' "$ino" "$f" >&3
continue
else
eval f0_$ino="\$f"
fi
fi
printf '%s\n' "$f"
done <.tmp/flist \
>.tmp/xargs-list \
3>.tmp/link-list
xargs -r -P$(nproc) -n1 @RPMCONFIGDIR@/process-debuginfo <.tmp/xargs-list
# Hard-link debuginfo for hard-linked binaries
while read -r ino f; do
debugf=./usr/lib/debug${f#.}.debug
eval f0="\${f0_$ino-}"
debugf0=./usr/lib/debug${f0#.}.debug
if [ -f "$debugf0" ]; then
mkdir -p "${debugf%/*}"
ln -nf "$debugf0" "$debugf"
fi
mkdir -p .debuginfo/src/"${f%/*}"
ln -nf .debuginfo/src/"$f0" .debuginfo/src/"$f"
done <.tmp/link-list
2011-01-14 06:43:13 +03:00
# Make symbolic links that mimic the original tree.
find . '(' -path './.*' $prune_tests ')' -prune -o -type l -print |sort >.tmp/flist
2011-01-14 06:43:13 +03:00
while read -r l; do
f=$(readlink -vm "$l")
f=${f#$RPM_BUILD_ROOT}
debugf=./usr/lib/debug$f.debug
[ -f "$debugf" ] || continue
debugl=./usr/lib/debug${l#.}.debug
mkdir -p "${debugl%/*}"
ln -snf "$(relative "${debugf#.}" "${debugl#.}")" "$debugl"
mkdir -p .debuginfo/links/"${debugf%/*}"
printf '%s\n' "${debugl#.}" >>.debuginfo/links/"$debugf"
done <.tmp/flist