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 + objcopy --compress-debug-sections "$2" || exit
109 + eu-strip --remove-comment -f "$1" "$2" -o "$t" || exit
113 +# Make a relative symlink to $1 called $3$2
117 + local t="$1" f="$2" pfx="$3"
118 + local fn="${f#/}" tn="${t#/}"
121 + while fd="${fn%%/*}"; td="${tn%%/*}"; [ "$fd" = "$td" ]; do
127 + if [ "$d" != "$fn" ]; then
128 + d="${d//+([!\/])/..}"
132 + mkdir -p "$(dirname "$pfx$f")" && ln -snf "$tn" "$pfx$f"
135 +# Make a symlink in /usr/lib/debug/$2 to $1
138 + local l="/usr/lib/debug$2"
140 + echo >> "$LINKSFILE" "$l $t"
141 + link_relative "$t" "$l" "$RPM_BUILD_ROOT"
144 +# Make a build-id symlink for id $1 with suffix $3 to file $2.
147 + local id="$1" file="$2"
148 + local idfile=".build-id/${id:0:2}/${id:2}"
149 + [ $# -eq 3 ] && idfile="${idfile}$3"
150 + local root_idfile="$RPM_BUILD_ROOT/usr/lib/debug/$idfile"
152 + if [ ! -L "$root_idfile" ]; then
153 + debug_link "$file" "/$idfile"
157 + [ $# -eq 3 ] && return 0
159 + local other=$(readlink -m "$root_idfile")
160 + other=${other#$RPM_BUILD_ROOT}
161 + if cmp -s "$root_idfile" "$RPM_BUILD_ROOT$file" ||
162 + eu-elfcmp -q "$root_idfile" "$RPM_BUILD_ROOT$file" 2> /dev/null; then
163 + # Two copies. Maybe one has to be setuid or something.
164 + echo >&2 "*** WARNING: identical binaries are copied, not linked:"
166 + echo >&2 " and $other"
168 + # This is pathological, break the build.
169 + echo >&2 "*** ERROR: same build ID in nonidentical files!"
171 + echo >&2 " and $other"
178 + dn=$(dirname "${1#$RPM_BUILD_ROOT}")
179 + bn=$(basename "$1" .debug).debug
181 + debugdn=${debugdir}${dn}
182 + debugfn=${debugdn}/${bn}
188 +$strict || strict_error=WARNING
191 -for f in `find $RPM_BUILD_ROOT ! -path "${debugdir}/*.debug" -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) -exec file {} \; | \
192 - sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped/\1/p'`
193 +find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \
194 + \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
196 +file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped/\1/p' |
197 +xargs --no-run-if-empty stat -c '%h %D_%i %n' |
198 +while read nlinks inum f; do
200 + [ -f "${debugfn}" ] && continue
202 + # If this file has multiple links, keep track and make
203 + # the corresponding .debug files all links to one file too.
204 + if [ $nlinks -gt 1 ]; then
205 + eval linked=\$linked_$inum
206 + if [ -n "$linked" ]; then
208 + get_debugfn "$linked"
209 + echo "hard linked $link to $debugfn"
210 + ln -nf "$debugfn" "$link"
213 + eval linked_$inum=\$f
214 + echo "file $f has $[$nlinks - 1] other hard links"
218 + echo "extracting debug info from $f"
219 + id=$(/usr/lib/rpm/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug \
220 + -i -l "$SOURCEFILE" "$f") || exit
221 + if [ -z "$id" ]; then
222 + echo >&2 "*** ${strict_error}: No build ID note found in $f"
226 + # A binary already copied into /usr/lib/debug doesn't get stripped,
227 + # just has its file names collected and adjusted.
230 + [ -z "$id" ] || make_id_link "$id" "$dn/$(basename $f)"
234 + mkdir -p "${debugdn}"
235 + if test -w "$f"; then
236 + strip_to_debug "${debugfn}" "$f"
239 + strip_to_debug "${debugfn}" "$f"
243 + if [ -n "$id" ]; then
244 + make_id_link "$id" "$dn/$(basename $f)"
245 + make_id_link "$id" "/usr/lib/debug$dn/$bn" .debug
249 +# For each symlink whose target has a .debug file,
250 +# make a .debug symlink to that file.
251 +find $RPM_BUILD_ROOT ! -path "${debugdir}/*" -type l -print |
254 - dn=$(dirname $f | sed -n -e "s#^$RPM_BUILD_ROOT##p")
255 - bn=$(basename $f .debug).debug
257 - debugdn="${debugdir}${dn}"
258 - debugfn="${debugdn}/${bn}"
259 - [ -f "${debugfn}" ] && continue
261 - echo extracting debug info from $f
262 - /usr/lib/rpm/4.5/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug -l "$SOURCEFILE" "$f"
264 - # A binary already copied into /usr/lib/debug doesn't get stripped,
265 - # just has its file names collected and adjusted.
267 - /usr/lib/debug/*) continue ;;
270 - mkdir -p "${debugdn}"
271 - if test -w "$f"; then
272 - strip_to_debug "${debugfn}" "$f"
275 - strip_to_debug "${debugfn}" "$f"
278 + t=$(readlink -m "$f").debug
279 + f=${f#$RPM_BUILD_ROOT}
280 + t=${t#$RPM_BUILD_ROOT}
281 + if [ -f "$debugdir$t" ]; then
282 + echo "symlinked /usr/lib/debug$t to /usr/lib/debug${f}.debug"
283 + debug_link "/usr/lib/debug$t" "${f}.debug"
287 -mkdir -p ${RPM_BUILD_ROOT}/usr/src/debug
288 -cat $SOURCEFILE | (cd $RPM_BUILD_DIR; LANG=C sort -z -u | cpio -pd0mL ${RPM_BUILD_ROOT}/usr/src/debug)
289 -# stupid cpio creates new directories in mode 0700, fixup
290 -find ${RPM_BUILD_ROOT}/usr/src/debug -type d -print0 | xargs -0 chmod a+rx
291 +if [ -s "$SOURCEFILE" ]; then
292 + mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug"
293 + LC_ALL=C sort -z -u "$SOURCEFILE" | egrep -v -z '(<internal>|<built-in>)$' |
294 + (cd "$RPM_BUILD_DIR"; cpio -pd0mL "${RPM_BUILD_ROOT}/usr/src/debug")
295 + # stupid cpio creates new directories in mode 0700, fixup
296 + find "${RPM_BUILD_ROOT}/usr/src/debug" -type d -print0 |
297 + xargs --no-run-if-empty -0 chmod a+rx
300 +if [ -d "${RPM_BUILD_ROOT}/usr/lib" -o -d "${RPM_BUILD_ROOT}/usr/src" ]; then
302 + test ! -d "${RPM_BUILD_ROOT}/usr/lib" ||
303 + (cd "${RPM_BUILD_ROOT}/usr/lib"; find debug -type d) |
304 + sed 's,^,%dir /usr/lib/,' >> "$LISTFILE"
306 + (cd "${RPM_BUILD_ROOT}/usr"
307 + test ! -d lib/debug || find lib/debug ! -type d
308 + test ! -d src/debug || find src/debug -mindepth 1 -maxdepth 1
309 + ) | sed 's,^,/usr/,' >> "$LISTFILE"
312 +# Append to $1 only the lines from stdin not already in the file.
315 + fgrep -f "$1" -x -v >> "$1"
318 -find ${RPM_BUILD_ROOT}/usr/lib/debug -type f | sed -n -e "s#^$RPM_BUILD_ROOT##p" > $LISTFILE
319 -find ${RPM_BUILD_ROOT}/usr/src/debug -mindepth 1 -maxdepth 1 | sed -n -e "s#^$RPM_BUILD_ROOT##p" >> $LISTFILE
320 +# Helper to generate list of corresponding .debug files from a file list.
321 +filelist_debugfiles()
325 + sed 's/^%[a-z0-9_][a-z0-9_]*([^)]*) *//
326 +s/^%[a-z0-9_][a-z0-9_]* *//
331 +# Write an output debuginfo file list based on given input file lists.
336 + test $# -gt 0 || return
337 + fgrep -f <(filelist_debugfiles 's,^.*$,/usr/lib/debug&.debug,' "$@") \
338 + -x $LISTFILE >> $out
339 + sed -n -f <(filelist_debugfiles 's/[\\.*+#]/\\&/g
343 +s,^.*$,s# /usr/lib/debug&.debug$##p,p
344 +' "$@") "$LINKSFILE" | append_uniq "$out"
347 +# Write an output debuginfo file list based on an egrep-style regexp.
350 + local out="$1" ptn="$2"
351 + test -n "$ptn" || return
352 + egrep -x -e "$ptn" "$LISTFILE" >> "$out"
353 + sed -n -r "\#^$ptn #s/ .*\$//p" "$LINKSFILE" | append_uniq "$out"
357 +# When given multiple -o switches, split up the output as directed.
360 +while ((i < nout)); do
362 + filtered_list ${outs[$i]} ${lists[$i]}
363 + pattern_list ${outs[$i]} "${ptns[$i]}"
364 + fgrep -vx -f ${outs[$i]} "$LISTFILE" > "${LISTFILE}.new"
365 + mv "${LISTFILE}.new" "$LISTFILE"
368 +if ((nout > 0)); then
369 + # Now add the right %dir lines to each output list.
370 + (cd "${RPM_BUILD_ROOT}"; find usr/lib/debug -type d) |
371 + sed 's#^.*$#\\@^/&/@{h;s@^.*$@%dir /&@p;g;}#' |
372 + LC_ALL=C sort -ur > "${LISTFILE}.dirs.sed"
374 + while ((i < nout)); do
375 + sed -n -f "${LISTFILE}.dirs.sed" "${outs[$i]}" | sort -u > "${outs[$i]}.new"
376 + cat "${outs[$i]}" >> "${outs[$i]}.new"
377 + mv -f "${outs[$i]}.new" "${outs[$i]}"
380 + sed -n -f "${LISTFILE}.dirs.sed" "${LISTFILE}" | sort -u > "${LISTFILE}.new"
381 + cat "$LISTFILE" >> "${LISTFILE}.new"
382 + mv "${LISTFILE}.new" "$LISTFILE"