1 --- rpm-4.5/macros.in.org 2009-03-23 09:25:24.383581794 +0100
2 +++ rpm-4.5/macros.in 2009-03-23 09:25:19.403234944 +0100
4 # Path to script that creates debug symbols in a /usr/lib/debug
6 %__debug_install_post \
7 - %{_rpmhome}/find-debuginfo.sh %{_builddir}/%{?buildsubdir}\
8 + %{_rpmhome}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
11 # Template for debug information sub-package.
12 --- rpm-4.5/scripts/find-debuginfo.sh.orig 2007-08-31 03:07:02.000000000 +0200
13 +++ rpm-4.5/scripts/find-debuginfo.sh 2009-09-17 15:22:30.299290490 +0200
17 #find-debuginfo.sh - automagically generate debug info and file list
18 #for inclusion in an rpm spec file.
20 +# Usage: find-debuginfo.sh [--strict-build-id]
21 +# [-o debugfiles.list]
22 +# [[-l filelist]... [-p 'pattern'] -o debuginfo.list]
25 +# The --strict-build-id flag says to exit with failure status if
26 +# any ELF binary processed fails to contain a build-id note.
28 +# A single -o switch before any -l or -p switches simply renames
29 +# the primary output file from debugfiles.list to something else.
30 +# A -o switch that follows a -p switch or some -l switches produces
31 +# an additional output file with the debuginfo for the files in
32 +# the -l filelist file, or whose names match the -p pattern.
33 +# The -p argument is an egrep-style regexp matching the a file name,
34 +# and must not use anchors (^ or $).
36 +# All file names in switches are relative to builddir (. if not given).
39 +# Barf on missing build IDs.
45 +while [ $# -gt 0 ]; do
51 + if [ -z "${lists[$nout]}" -a -z "${ptns[$nout]}" ]; then
60 + lists[$nout]="${lists[$nout]} $2"
76 -if [ -z "$1" ] ; then BUILDDIR="."
80 +while ((i < nout)); do
81 + outs[$i]="$BUILDDIR/${outs[$i]}"
83 + for f in ${lists[$i]}; do
90 -LISTFILE=$BUILDDIR/debugfiles.list
91 -SOURCEFILE=$BUILDDIR/debugsources.list
92 +LISTFILE="$BUILDDIR/$out"
93 +SOURCEFILE="$BUILDDIR/debugsources.list"
94 +LINKSFILE="$BUILDDIR/debuglinks.list"
100 debugdir="${RPM_BUILD_ROOT}/usr/lib/debug"
102 -echo -n > $SOURCEFILE
106 - eu-strip --remove-comment -f "$1" "$2" || :
107 + local t=$(mktemp "/tmp/rpm.stripped.XXXXXX")
108 + eu-strip --remove-comment -f "$1" "$2" -o "$t" || exit
112 +# Make a relative symlink to $1 called $3$2
116 + local t="$1" f="$2" pfx="$3"
117 + local fn="${f#/}" tn="${t#/}"
120 + while fd="${fn%%/*}"; td="${tn%%/*}"; [ "$fd" = "$td" ]; do
126 + if [ "$d" != "$fn" ]; then
127 + d="${d//+([!\/])/..}"
131 + mkdir -p "$(dirname "$pfx$f")" && ln -snf "$tn" "$pfx$f"
134 +# Make a symlink in /usr/lib/debug/$2 to $1
137 + local l="/usr/lib/debug$2"
139 + echo >> "$LINKSFILE" "$l $t"
140 + link_relative "$t" "$l" "$RPM_BUILD_ROOT"
143 +# Make a build-id symlink for id $1 with suffix $3 to file $2.
146 + local id="$1" file="$2"
147 + local idfile=".build-id/${id:0:2}/${id:2}"
148 + [ $# -eq 3 ] && idfile="${idfile}$3"
149 + local root_idfile="$RPM_BUILD_ROOT/usr/lib/debug/$idfile"
151 + if [ ! -L "$root_idfile" ]; then
152 + debug_link "$file" "/$idfile"
156 + [ $# -eq 3 ] && return 0
158 + local other=$(readlink -m "$root_idfile")
159 + other=${other#$RPM_BUILD_ROOT}
160 + if cmp -s "$root_idfile" "$RPM_BUILD_ROOT$file" ||
161 + eu-elfcmp -q "$root_idfile" "$RPM_BUILD_ROOT$file" 2> /dev/null; then
162 + # Two copies. Maybe one has to be setuid or something.
163 + echo >&2 "*** WARNING: identical binaries are copied, not linked:"
165 + echo >&2 " and $other"
167 + # This is pathological, break the build.
168 + echo >&2 "*** ERROR: same build ID in nonidentical files!"
170 + echo >&2 " and $other"
177 + dn=$(dirname "${1#$RPM_BUILD_ROOT}")
178 + bn=$(basename "$1" .debug).debug
180 + debugdn=${debugdir}${dn}
181 + debugfn=${debugdn}/${bn}
187 +$strict || strict_error=WARNING
190 -for f in `find $RPM_BUILD_ROOT ! -path "${debugdir}/*.debug" -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) -exec file {} \; | \
191 - sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped/\1/p'`
192 +find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \
193 + \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
195 +file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped/\1/p' |
196 +xargs --no-run-if-empty stat -c '%h %D_%i %n' |
197 +while read nlinks inum f; do
199 + [ -f "${debugfn}" ] && continue
201 + # If this file has multiple links, keep track and make
202 + # the corresponding .debug files all links to one file too.
203 + if [ $nlinks -gt 1 ]; then
204 + eval linked=\$linked_$inum
205 + if [ -n "$linked" ]; then
207 + get_debugfn "$linked"
208 + echo "hard linked $link to $debugfn"
209 + ln -nf "$debugfn" "$link"
212 + eval linked_$inum=\$f
213 + echo "file $f has $[$nlinks - 1] other hard links"
217 + echo "extracting debug info from $f"
218 + id=$(/usr/lib/rpm/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug \
219 + -i -l "$SOURCEFILE" "$f") || exit
220 + if [ -z "$id" ]; then
221 + echo >&2 "*** ${strict_error}: No build ID note found in $f"
225 + # A binary already copied into /usr/lib/debug doesn't get stripped,
226 + # just has its file names collected and adjusted.
229 + [ -z "$id" ] || make_id_link "$id" "$dn/$(basename $f)"
233 + mkdir -p "${debugdn}"
234 + if test -w "$f"; then
235 + strip_to_debug "${debugfn}" "$f"
238 + strip_to_debug "${debugfn}" "$f"
242 + if [ -n "$id" ]; then
243 + make_id_link "$id" "$dn/$(basename $f)"
244 + make_id_link "$id" "/usr/lib/debug$dn/$bn" .debug
248 +# For each symlink whose target has a .debug file,
249 +# make a .debug symlink to that file.
250 +find $RPM_BUILD_ROOT ! -path "${debugdir}/*" -type l -print |
253 - dn=$(dirname $f | sed -n -e "s#^$RPM_BUILD_ROOT##p")
254 - bn=$(basename $f .debug).debug
256 - debugdn="${debugdir}${dn}"
257 - debugfn="${debugdn}/${bn}"
258 - [ -f "${debugfn}" ] && continue
260 - echo extracting debug info from $f
261 - /usr/lib/rpm/4.5/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug -l "$SOURCEFILE" "$f"
263 - # A binary already copied into /usr/lib/debug doesn't get stripped,
264 - # just has its file names collected and adjusted.
266 - /usr/lib/debug/*) continue ;;
269 - mkdir -p "${debugdn}"
270 - if test -w "$f"; then
271 - strip_to_debug "${debugfn}" "$f"
274 - strip_to_debug "${debugfn}" "$f"
277 + t=$(readlink -m "$f").debug
278 + f=${f#$RPM_BUILD_ROOT}
279 + t=${t#$RPM_BUILD_ROOT}
280 + if [ -f "$debugdir$t" ]; then
281 + echo "symlinked /usr/lib/debug$t to /usr/lib/debug${f}.debug"
282 + debug_link "/usr/lib/debug$t" "${f}.debug"
286 -mkdir -p ${RPM_BUILD_ROOT}/usr/src/debug
287 -cat $SOURCEFILE | (cd $RPM_BUILD_DIR; LANG=C sort -z -u | cpio -pd0mL ${RPM_BUILD_ROOT}/usr/src/debug)
288 -# stupid cpio creates new directories in mode 0700, fixup
289 -find ${RPM_BUILD_ROOT}/usr/src/debug -type d -print0 | xargs -0 chmod a+rx
290 +if [ -s "$SOURCEFILE" ]; then
291 + mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug"
292 + LC_ALL=C sort -z -u "$SOURCEFILE" | egrep -v -z '(<internal>|<built-in>)$' |
293 + (cd "$RPM_BUILD_DIR"; cpio -pd0mL "${RPM_BUILD_ROOT}/usr/src/debug")
294 + # stupid cpio creates new directories in mode 0700, fixup
295 + find "${RPM_BUILD_ROOT}/usr/src/debug" -type d -print0 |
296 + xargs --no-run-if-empty -0 chmod a+rx
299 +if [ -d "${RPM_BUILD_ROOT}/usr/lib" -o -d "${RPM_BUILD_ROOT}/usr/src" ]; then
301 + test ! -d "${RPM_BUILD_ROOT}/usr/lib" ||
302 + (cd "${RPM_BUILD_ROOT}/usr/lib"; find debug -type d) |
303 + sed 's,^,%dir /usr/lib/,' >> "$LISTFILE"
305 + (cd "${RPM_BUILD_ROOT}/usr"
306 + test ! -d lib/debug || find lib/debug ! -type d
307 + test ! -d src/debug || find src/debug -mindepth 1 -maxdepth 1
308 + ) | sed 's,^,/usr/,' >> "$LISTFILE"
311 +# Append to $1 only the lines from stdin not already in the file.
314 + fgrep -f "$1" -x -v >> "$1"
317 -find ${RPM_BUILD_ROOT}/usr/lib/debug -type f | sed -n -e "s#^$RPM_BUILD_ROOT##p" > $LISTFILE
318 -find ${RPM_BUILD_ROOT}/usr/src/debug -mindepth 1 -maxdepth 1 | sed -n -e "s#^$RPM_BUILD_ROOT##p" >> $LISTFILE
319 +# Helper to generate list of corresponding .debug files from a file list.
320 +filelist_debugfiles()
324 + sed 's/^%[a-z0-9_][a-z0-9_]*([^)]*) *//
325 +s/^%[a-z0-9_][a-z0-9_]* *//
330 +# Write an output debuginfo file list based on given input file lists.
335 + test $# -gt 0 || return
336 + fgrep -f <(filelist_debugfiles 's,^.*$,/usr/lib/debug&.debug,' "$@") \
337 + -x $LISTFILE >> $out
338 + sed -n -f <(filelist_debugfiles 's/[\\.*+#]/\\&/g
342 +s,^.*$,s# /usr/lib/debug&.debug$##p,p
343 +' "$@") "$LINKSFILE" | append_uniq "$out"
346 +# Write an output debuginfo file list based on an egrep-style regexp.
349 + local out="$1" ptn="$2"
350 + test -n "$ptn" || return
351 + egrep -x -e "$ptn" "$LISTFILE" >> "$out"
352 + sed -n -r "\#^$ptn #s/ .*\$//p" "$LINKSFILE" | append_uniq "$out"
356 +# When given multiple -o switches, split up the output as directed.
359 +while ((i < nout)); do
361 + filtered_list ${outs[$i]} ${lists[$i]}
362 + pattern_list ${outs[$i]} "${ptns[$i]}"
363 + fgrep -vx -f ${outs[$i]} "$LISTFILE" > "${LISTFILE}.new"
364 + mv "${LISTFILE}.new" "$LISTFILE"
367 +if ((nout > 0)); then
368 + # Now add the right %dir lines to each output list.
369 + (cd "${RPM_BUILD_ROOT}"; find usr/lib/debug -type d) |
370 + sed 's#^.*$#\\@^/&/@{h;s@^.*$@%dir /&@p;g;}#' |
371 + LC_ALL=C sort -ur > "${LISTFILE}.dirs.sed"
373 + while ((i < nout)); do
374 + sed -n -f "${LISTFILE}.dirs.sed" "${outs[$i]}" | sort -u > "${outs[$i]}.new"
375 + cat "${outs[$i]}" >> "${outs[$i]}.new"
376 + mv -f "${outs[$i]}.new" "${outs[$i]}"
379 + sed -n -f "${LISTFILE}.dirs.sed" "${LISTFILE}" | sort -u > "${LISTFILE}.new"
380 + cat "$LISTFILE" >> "${LISTFILE}.new"
381 + mv "${LISTFILE}.new" "$LISTFILE"