--- makepkg.orig 2008-07-24 02:14:39.000000000 +0200 +++ makepkg 2008-07-24 02:14:18.000000000 +0200 @@ -38,6 +38,8 @@ startdir="$PWD" srcdir="$startdir/src" pkgdir="$startdir/pkg" +# add support for splitting debug symbols +dbgdir="$startdir/dbg" # Options ASROOT=0 @@ -748,6 +750,70 @@ fi done + # add support for splitting debug files + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; 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 + # 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}/usr/lib/debug/${debug_basedir}" ]; then + mkdir -p "${dbgdir}/usr/lib/debug/${debug_basedir}" + fi + # and as a last step, we move the debug file to its destination + mv "$file.debug" "${dbgdir}/usr/lib/debug/${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}/usr/lib/debug/${debug_basedir}" ]; then + mkdir -p "${dbgdir}/usr/lib/debug/${debug_basedir}" + fi + # and as a last step, we move the debug file to its destination + mv "$file.debug" "${dbgdir}/usr/lib/debug/${debug_basedir}/$debug_symbolfile";; + esac + done + fi if [ "$(check_option strip)" = "y" ]; then msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")" @@ -872,6 +938,74 @@ fi } +# add support for splitting debug symbols +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...")" + + # make debug files non-executable + find . -type f -exec chmod 644 {} \; + + 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 @@ -1086,6 +1220,8 @@ # fix flyspray feature request #2978 echo "$(gettext " -R, --repackage Repackage contents of pkg/ without building")" echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")" + # add support for splitting debug symbols + echo "$(gettext " -t, --splitdbg Puts debug symbols into a separate package")" echo "$(gettext " --asroot Allow makepkg to run as root user")" echo "$(gettext " --holdver Prevent automatic version bumping for development PKGBUILDs")" echo "$(gettext " --source Do not build package; generate a source-only tarball")" @@ -1143,9 +1279,11 @@ SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined # Parse Command Line Options. -OPT_SHORT="AbcCdefFghiLmop:rRsSV" +# add support for splitting debug symbols +OPT_SHORT="AbcCdefFghiLmop:rRstSV" OPT_LONG="ignorearch,asroot,builddeps,clean,cleancache,nodeps,noextract,force,forcever:,geninteg,help,holdver" -OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source,syncdeps,usesudo,version" +# add support for splitting debug symbols +OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source,splitdbg,syncdeps,usesudo,version" # Pacman Options OPT_LONG="$OPT_LONG,noconfirm,noprogressbar" OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')" @@ -1185,6 +1323,8 @@ -R|--repackage) REPKG=1 ;; --source) SOURCEONLY=1 ;; -s|--syncdeps) DEP_BIN=1 ;; + # add support for splitting debug symbols + -t|--splitdbg) SPLIT_DBG=1 ;; # BEGIN DEPRECATED -S|--usesudo) @@ -1375,7 +1515,20 @@ tidy_install fi - create_package + # add support for splitting debug symbols + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + create_package + # second check, if there are any files + check_dbg_files=`find $dbgdir/ -name "*.debug"` + if [ -z "$check_dbg_files" ]; then + msg2 "$(gettext "No .debug files found, skipping creation of the debug pkg...")" + else + msg2 "$(gettext "Moving debugging symbols from binaries and libraries into a separate pkg...")" + create_debug_package + fi + else + create_package + fi msg "$(gettext "Leaving fakeroot environment.")" exit 0 # $E_OK @@ -1466,6 +1619,15 @@ rm -rf "$pkgdir" fi mkdir -p "$pkgdir" + + # add support for splitting debug symbols + # 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 +1640,20 @@ tidy_install fi - create_package + # add support for splitting debug symbols + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + create_package + # second check, if there are any files + check_dbg_files=`find $dbgdir/ -name "*.debug"` + if [ -z "$check_dbg_files" ]; then + msg2 "$(gettext "No .debug files found, skipping creation of the debug pkg...")" + else + msg2 "$(gettext "Moving debugging symbols from binaries and libraries into a separate pkg...")" + create_debug_package + fi + else + create_package + fi else msg "$(gettext "Entering fakeroot environment...")"