d9bad00
#!/bin/sh
0c1e1f9
# mingw-find-debuginfo.sh - automagically generate debug info and file list
0c1e1f9
# for inclusion in an rpm spec file for mingw-* packages.
d9bad00
d9bad00
if [ -z "$1" ] ; then BUILDDIR="."
d9bad00
else BUILDDIR=$1
d9bad00
fi
d9bad00
0c1e1f9
if [ "$2" = "old" ] ; then USE_OLD_METHOD=true; else USE_OLD_METHOD=false; fi
0c1e1f9
d9bad00
for f in `find $RPM_BUILD_ROOT -type f -name "*.exe" -or -name "*.dll"`
d9bad00
do
0c1e1f9
	case $(mingw-objdump -h $f 2>/dev/null | egrep -o '(debug[\.a-z_]*|gnu.version)') in
d9bad00
	    *debuglink*) continue ;;
d9bad00
	    *debug*) ;;
d9bad00
	    *gnu.version*)
d9bad00
		echo "WARNING: "`echo $f | sed -e "s,^$RPM_BUILD_ROOT/*,/,"`" is already stripped!"
d9bad00
		continue
d9bad00
		;;
d9bad00
	    *) continue ;;
d9bad00
	esac
d9bad00
d9bad00
	echo extracting debug info from $f
0c1e1f9
	mingw-objcopy --only-keep-debug $f $f.debug || :
d9bad00
	pushd `dirname $f`
0c1e1f9
	mingw-objcopy --add-gnu-debuglink=`basename $f.debug` --strip-unneeded `basename $f` || :
d9bad00
	popd
d9bad00
done
d9bad00
0c1e1f9
if [ "$USE_OLD_METHOD" = "true" ] ; then
0c1e1f9
	find $RPM_BUILD_ROOT -type f -name "*.exe.debug" -or -name "*.dll.debug" |
0c1e1f9
            sed -n -e "s#^$RPM_BUILD_ROOT##p" > $BUILDDIR/debugfiles.list
0c1e1f9
else
0c1e1f9
	shift
0c1e1f9
	for target in $@; do
0c1e1f9
		prefix=`rpm --eval "%{${target}_prefix}"`
0c1e1f9
		find $RPM_BUILD_ROOT$prefix -type f -name "*.exe.debug" -or -name "*.dll.debug" |
0c1e1f9
			sed -n -e "s#^$RPM_BUILD_ROOT##p" > $BUILDDIR/${target}-debugfiles.list
0c1e1f9
	done
0c1e1f9
fi