--- makepkg.orig 2008-07-21 23:36:36.000000000 +0200 +++ makepkg 2008-07-21 23:36:06.000000000 +0200 @@ -38,6 +38,7 @@ startdir="$PWD" srcdir="$startdir/src" pkgdir="$startdir/pkg" +dbgdir="$startdir/dbg" # Options ASROOT=0 @@ -750,15 +751,77 @@ if [ "$(check_option strip)" = "y" ]; then - msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")" - for file in $(find {,usr/{,local/},opt/*/}{bin,lib,sbin} -type f 2>/dev/null || true); do - case "$(file -biz "$file")" in - *application/x-sharedlib*) # Libraries - /usr/bin/strip --strip-debug "$file";; - *application/x-executable*) # Binaries - /usr/bin/strip "$file";; - esac - done + if [ "$(check_option splitdebug)" = "y" ]; then + msg2 "$(gettext "Moving debugging symbols from binaries and libraries into separate files...")" + for file in $(find {,usr/{,local/},opt/*/}{bin,lib,sbin} -type f 2>/dev/null || true); do + case "$(file -biz "$file")" in + *application/x-sharedlib*) # Libraries + # create external file with debug symbols + /usr/bin/objcopy --only-keep-debug "$file" "$file.debug" + # now strip the debug symbols from the binary + /usr/bin/strip --strip-debug "$file" + # now we need to add the gnu debuglink flag to the binary, + # so gdb knows where to find the debug symbols... + # + # as we cannot use the full path to the file with the debug + # symbols, we need to operate directly in the path where the + # files are, as --add-gnu-debuglink doesnt work with full path + # + # at first, create some variables + debug_basefile=`echo "$file" | awk -F '/' '{print $NF}'` + debug_symbolfile=`echo "$file.debug" | awk -F '/' '{print $NF}'` + debug_basedir=`dirname "$file.debug"` + # move into the dir with the file and its debug file + pushd $debug_basedir &>/dev/null + # now add the debuglink flag + /usr/bin/objcopy --add-gnu-debuglink="$debug_symbolfile" "$debug_basefile" + popd &>/dev/null + # here we create the necessary target dir for the debug file + if [ ! -d "${dbgdir}/${debug_basedir}" ]; then + mkdir -p "${dbgdir}/${debug_basedir}" + fi + # and as a last step, we move the debug file to its destination + mv "$file.debug" "${dbgdir}/${debug_basedir}/$debug_symbolfile";; + *application/x-executable*) # Binaries + # create external file with debug symbols + /usr/bin/objcopy --only-keep-debug "$file" "$file.debug" + # now strip the debug symbols from the binary + /usr/bin/strip "$file" + # now we need to add the gnu debuglink flag to the binary, + # so gdb knows where to find the debug symbols... + # + # as we cannot use the full path to the file with the debug + # symbols, we need to operate directly in the path where the + # files are, as --add-gnu-debuglink doesnt work with full path + # + # at first, create some variables + debug_basefile=`echo "$file" | awk -F '/' '{print $NF}'` + debug_symbolfile=`echo "$file.debug" | awk -F '/' '{print $NF}'` + debug_basedir=`dirname "$file.debug"` + # move into the dir with the file and its debug file + pushd $debug_basedir &>/dev/null + # now add the debuglink flag + /usr/bin/objcopy --add-gnu-debuglink="$debug_symbolfile" "$debug_basefile" + popd &>/dev/null + # here we create the necessary target dir for the debug file + if [ ! -d "${dbgdir}/${debug_basedir}" ]; then + mkdir -p "${dbgdir}/${debug_basedir}" + fi + # and as a last step, we move the debug file to its destination + mv "$file.debug" "${dbgdir}/${debug_basedir}/$debug_symbolfile";; + esac + done + else + msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")" + for file in $(find {,usr/{,local/},opt/*/}{bin,lib,sbin} -type f 2>/dev/null || true); do + case "$(file -biz "$file")" in + *application/x-sharedlib*) # Libraries + /usr/bin/strip --strip-debug "$file";; + *application/x-executable*) # Binaries + /usr/bin/strip "$file";; + esac + done + fi fi if [ "$(check_option libtool)" = "n" ]; then @@ -872,6 +935,70 @@ fi } +create_debug_package() { + if [ ! -d "$dbgdir" ]; then + error "$(gettext "Missing dbg/ directory.")" + plain "$(gettext "Aborting...")" + exit 1 # $E_MISSING_PKGDIR + fi + + cd "$dbgdir" + msg "$(gettext "Creating separate debug package...")" + + local builddate=$(date -u "+%s") + if [ "$PACKAGER" != "" ]; then + local packager="$PACKAGER" + else + local packager="Unknown Packager" + fi + local size=$(du -sb | awk '{print $1}') + + # write the .PKGINFO file + msg2 "$(gettext "Generating .PKGINFO file...")" + echo "# Generated by makepkg $myver" >.PKGINFO + if [ "$INFAKEROOT" = "1" ]; then + echo "# using $(fakeroot -v)" >>.PKGINFO + fi + echo "# $(LC_ALL= LANG= date -u)" >>.PKGINFO + echo "pkgname = $pkgname-debug" >>.PKGINFO + echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO + echo "pkgdesc = $pkgdesc - Debug Symbols" >>.PKGINFO + echo "url = $url" >>.PKGINFO + echo "builddate = $builddate" >>.PKGINFO + echo "packager = $packager" >>.PKGINFO + echo "size = $size" >>.PKGINFO + if [ "$CARCH" != "" ]; then + echo "arch = $CARCH" >>.PKGINFO + fi + if [ "$(check_option force)" = "y" ]; then + echo "force = true" >> .PKGINFO + fi + + local it + for it in "${license[@]}"; do + echo "license = $it" >>.PKGINFO + done + + # TODO maybe remove this at some point + # warn if license array is not present or empty + if [ "$license" = "" ]; then + warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT" + plain "$(gettext "Example for GPL'ed software: license=('GPL').")" + fi + + local comp_files=".PKGINFO" + + # tar it up + msg2 "$(gettext "Compressing separate debug package...")" + + local pkg_file="$PKGDEST/${pkgname}-debug-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" + + if ! bsdtar -czf "$pkg_file" $comp_files $(ls); then + error "$(gettext "Failed to create debug package file.")" + exit 1 # TODO: error code + fi +} + create_xdelta() { if [ "$(check_buildenv xdelta)" != "y" ]; then return @@ -1375,7 +1502,14 @@ tidy_install fi - create_package + if [ "$(check_option strip)" = "y" ]; then + if [ "$(check_option splitdebug)" = "y" ]; then + create_package + create_debug_package + fi + else + create_package + fi msg "$(gettext "Leaving fakeroot environment.")" exit 0 # $E_OK @@ -1466,6 +1600,14 @@ rm -rf "$pkgdir" fi mkdir -p "$pkgdir" + + # check for existing dbg directory; don't remove if we are repackaging + if [ -d "$dbgdir" -a "$REPKG" = "0" ]; then + msg "$(gettext "Removing existing dbg/ directory...")" + rm -rf "$dbgdir" + fi + mkdir -p "$dbgdir" + cd "$startdir" if [ $EUID -eq 0 ]; then @@ -1478,7 +1620,14 @@ tidy_install fi - create_package + if [ "$(check_option strip)" = "y" ]; then + if [ "$(check_option splitdebug)" = "y" ]; then + create_package + create_debug_package + fi + else + create_package + fi else msg "$(gettext "Entering fakeroot environment...")"