aboutsummaryrefslogtreecommitdiffstats
path: root/find-debuginfo.sh
blob: 30bb3114413b103651c62b2f11ec741401315e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
#find-debuginfo.sh - automagically generate debug info and file list
#for inclusion in an rpm spec file.

if [ -z "$1" ] ; then BUILDDIR="."
else BUILDDIR=$1
fi

LISTFILE=$BUILDDIR/debugfiles.list
SOURCEFILE=$BUILDDIR/debugsources.list

debugedit=/usr/lib/rpm/debugedit
if [ ! -x $debugedit ]; then
    # rpm5 since 5.2 has moved these binaries to a separate 'bin' subdirectory
    if [ -x /usr/lib/rpm/bin/debugedit ]; then
	debugedit=/usr/lib/rpm/bin/debugedit
    fi
fi

debugdir="${RPM_BUILD_ROOT}/usr/lib/debug"

echo -n > $SOURCEFILE

[[ -n "$EXCLUDE_FROM_STRIP" ]] && \
EXCLUDE_REGEXP=`perl -e 'print "(", join("|", @ARGV), ")"' $EXCLUDE_FROM_STRIP`

# Strip ELF binaries and shared libs
for f in `find $RPM_BUILD_ROOT -path "${debugdir}" -prune -o -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) -exec file {} \; | \
	sed -n -e 's/^\(.*\):[ 	]*.*ELF.* \(executable\|shared object\).*, not stripped/\1/p'`
do
	[[ -n "$EXCLUDE_REGEXP" ]] && egrep -q "$EXCLUDE_REGEXP" <<< "$f" && \
	    continue

	dn=$(dirname $f | sed -n -e "s#^$RPM_BUILD_ROOT##p")
	bn=$(basename $f .debug).debug

	debugdn="${debugdir}${dn}"
	debugfn="${debugdn}/${bn}"
	[ -f "${debugfn}" ] && continue

	mkdir -p "${debugdn}"
	echo extracting debug info from $f
	$debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug -l "$SOURCEFILE" "$f"
	if test -w "$f"; then
		eu-strip -f "${debugfn}" "$f" || :
	else
		chmod u+w "$f"
		eu-strip -f "${debugfn}" "$f" || :
		chmod u-w "$f"
	fi
done

[[ -d ${debugdir} ]] && \
find ${debugdir} -type f | sed -n -e "s#^$RPM_BUILD_ROOT##p" > $LISTFILE

if [ -s $SOURCEFILE ]; then
    mkdir -p ${RPM_BUILD_ROOT}/usr/src/debug
    cat $SOURCEFILE | (cd $RPM_BUILD_DIR; LANG=C sort -z -u | cpio -pd0m ${RPM_BUILD_ROOT}/usr/src/debug)
    # stupid cpio creates new directories in mode 0700, fixup
    find ${RPM_BUILD_ROOT}/usr/src/debug -type d -print0 | xargs -0 chmod a+rx
    find ${RPM_BUILD_ROOT}/usr/src/debug -type f -print0 | xargs -0 -r chmod a+r
    
    find ${RPM_BUILD_ROOT}/usr/src/debug -mindepth 1 -maxdepth 1 | sed -n -e "s#^$RPM_BUILD_ROOT##p" >> $LISTFILE
fi