2011-01-08 14:33:04 +03:00
#!/bin/sh -efu
2011-01-30 04:20:31 +03:00
#
# 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>.
# License: GPLv2+.
2011-01-08 14:33:04 +03:00
. @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.
2013-10-29 04:36:46 +04:00
: ${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 |
2017-04-18 19:42:41 +03:00
file -NF$'\t' -f - |
sed -n -e '/ ELF .* shared object, no machine, /d' \
-e 's/\t.* ELF .* \(executable\|shared object\), .*, not stripped.*//p' |
2011-02-05 00:33:25 +03:00
xargs -r --delimiter='\n' stat -c '%h %i %n' >.tmp/flist
2011-01-08 14:33:04 +03:00
while read -r nlink ino f; do
debugf=./usr/lib/debug${f#.}.debug
if [ "$nlink" -gt 1 ]; then
eval f0="\${f0_$ino-}"
if [ -n "$f0" ]; then
2011-02-05 00:33:25 +03:00
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"
2011-01-08 14:33:04 +03:00
continue
else
eval f0_$ino="\$f"
fi
fi
2011-02-03 10:29:08 +03:00
strip='--strip-all'
for pat in ${RPM_BRP_STRIP_DEBUG-}; do
if [ -z "${f##.$pat}" ]; then
strip='--strip-debug'
break
fi
done
for pat in ${RPM_BRP_STRIP_NONE-}; do
if [ -z "${f##.$pat}" ]; then
strip=
break
fi
done
2011-01-30 03:35:57 +03:00
touch -r "$f" .tmp/stamp
2011-01-14 06:45:20 +03:00
@RPMCONFIGDIR@/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug -l .tmp/src "$f"
2011-02-03 10:29:08 +03:00
if [ -n "$strip" ]; then
2011-02-05 00:33:25 +03:00
mkdir -p "${debugf%/*}"
2011-02-05 23:34:11 +03:00
LD_ORIGIN_PATH=/usr/bin eu-strip $strip --remove-comment -f "$debugf" "$f"
2011-02-03 10:29:08 +03:00
touch -r .tmp/stamp "$debugf" "$f"
chmod 644 "$debugf"
else
touch -r .tmp/stamp "$f"
fi
mkdir -p .debuginfo/src/"${f%/*}"
2011-01-14 06:45:20 +03:00
awk 'BEGIN{RS="\0";ORS="\n"}{print}' .tmp/src |LC_ALL=C sort -u |
while read -r src; do
[ -f "$RPM_BUILD_DIR"/"$src" ] || continue
[ -f ./usr/src/debug/"$src" ] ||
install -pD -m644 "$RPM_BUILD_DIR"/"$src" ./usr/src/debug/"$src"
printf '%s\n' /usr/src/debug/"$src"
2011-02-03 10:29:08 +03:00
done >.debuginfo/src/"$f"
2011-01-14 06:45:20 +03:00
rm .tmp/src
2011-02-05 00:33:25 +03:00
done <.tmp/flist
2011-01-14 06:43:13 +03:00
# Make symbolic links that mimic the original tree.
2013-10-29 04:36:46 +04:00
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"
2011-02-05 00:33:25 +03:00
done <.tmp/flist