--- makepkg 2011-06-07 22:49:37.000000000 +0300 +++ ../local/bin/makepkg2 2011-08-06 10:02:50.000000000 +0300 @@ -43,8 +43,9 @@ startdir="$PWD" srcdir="$startdir/src" pkgdir="$startdir/pkg" +dbgdir="$startdir/dbg" -packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge') +packaging_options=('strip' 'splitdbg' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge') other_options=('ccache' 'distcc' 'buildflags' 'makeflags') splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \ 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \ @@ -74,6 +75,7 @@ CHECKFUNC=0 PKGFUNC=0 SPLITPKG=0 +SPLIT_DBG=0 PKGLIST=() # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call @@ -140,7 +142,7 @@ # If it's a clean exit and -c/--clean has been passed... msg "$(gettext "Cleaning up...")" - rm -rf "$pkgdir" "$srcdir" + rm -rf "$pkgdir" "$srcdir" "$dbgdir" if [[ -n $pkgbase ]]; then # TODO: this wasn't properly fixed in commit 2020e629 local fullver=$(get_full_version $epoch $pkgver $pkgrel) @@ -902,21 +904,50 @@ done fi + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + keep_symbols=yes + else + keep_symbols=no + fi + if [[ $(check_option strip) = y ]]; then msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")" # make sure library stripping variables are defined to prevent excess stripping [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S" [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S" - local binary + local binary hardlink strip_opt find . -type f -perm -u+w 2>/dev/null | while read binary ; do case "$(file -bi "$binary")" in *application/x-sharedlib*) # Libraries (.so) - /usr/bin/strip $STRIP_SHARED "$binary";; + strip_opt=$STRIP_SHARED;; *application/x-archive*) # Libraries (.a) - /usr/bin/strip $STRIP_STATIC "$binary";; + strip_opt=$STRIP_STATIC;; *application/x-executable*) # Binaries - /usr/bin/strip $STRIP_BINARIES "$binary";; + strip_opt=$STRIP_BINARIES;; + *) continue ;; esac + # Strip symbols + if [ "x$keep_symbols" = "xyes" ]; then + # Create directory for the symbol file + mkdir -p "${dbgdir}/usr/lib/debug/${binary%/*}" + if readelf -S $binary | grep "\.gnu_debuglink" &>/dev/null; then + # An already stripped binary is a hard link + find ${STRIP_DIRS[@]} -samefile "$binary" 2>/dev/null | while read hardlink ; do + # Is the symbol file for the hardlink in the right dir ? + [ -e "${dbgdir}/usr/lib/debug/${hardlink#/}.debug" ] && \ + [ "${hardlink%/*}" != "${binary%/*}" ] && \ + ln "${dbgdir}/usr/lib/debug/${hardlink#/}.debug" "${dbgdir}/usr/lib/debug/${binary%/*}" && break + done + else + # Strip the file + /usr/bin/objcopy --only-keep-debug "$binary" "${dbgdir}/usr/lib/debug/${binary#/}.debug" + /usr/bin/strip $strip_opts "$binary" + /usr/bin/objcopy --add-gnu-debuglink="${dbgdir}/usr/lib/debug/${binary#/}.debug" "$binary" + chmod 644 "${dbgdir}/usr/lib/debug/${binary#/}.debug" + fi + else + /usr/bin/strip $strip_opts "$binary" + fi done fi @@ -1017,7 +1048,6 @@ check_package cd "$pkgdir" - msg "$(gettext "Creating package...")" local nameofpkg if [[ -z $1 ]]; then @@ -1026,6 +1056,8 @@ nameofpkg="$1" fi + msg "$(gettext "Creating package") $nameofpkg" + if [[ $arch = "any" ]]; then PKGARCH="any" else @@ -1096,6 +1128,39 @@ fi } +create_dbgpackage() { + local oldpkgdir + # don't forget to backup pkg vars before calling me + oldpkgdir="$pkgdir" + pkgdir="$dbgdir" + mkdir -p "$dbgdir" + chmod a-s "$dbgdir" + + if [[ -z $1 ]]; then + nameofdbgpkg="${pkgname}-dbg" + else + nameofdbgpkg="$1-dbg" + fi + + check_dbg_files=`find $pkgdir/ -name "*.debug"` + if [ -z "$check_dbg_files" ]; then + warning "$(gettext "No .debug files, skipping!")" + return + fi + # Variables for the debug info package + pkgdesc="$pkgdesc (debugging symbols)" + depends=("$pkgname=$pkgver-$pkgrel") + groups=('debug' ${groups[@]/%/-debug}) + optdepends=() + replaces=() + provides=() # ${provides[@]/%/-dbg} + conflicts=() # ${conflicts[@]/%/-dbg} + backup=() + # Make it! + create_package $nameofdbgpkg + pkgdir="$oldpkgdir" +} + create_srcpackage() { cd "$startdir" @@ -1446,14 +1511,17 @@ local pkgname_backup=${pkgname[@]} for pkgname in ${pkgname_backup[@]}; do pkgdir="$pkgdir/$pkgname" + dbgdir="$dbgdir/$pkgname" mkdir -p "$pkgdir" chmod a-s "$pkgdir" backup_package_variables run_package $pkgname tidy_install create_package $pkgname + [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ] && create_dbgpackage $pkgname restore_package_variables pkgdir="${pkgdir%/*}" + dbgdir="${dbgdir%/*}" done pkgname=${pkgname_backup[@]} } @@ -1582,6 +1650,7 @@ echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")" echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")" echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")" + echo "$(gettext " -t, --splitdbg Split debugging symbols into separate package")" echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")" echo "$(gettext " --asroot Allow makepkg to run as root user")" printf "$(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT" @@ -1622,11 +1691,11 @@ ARGLIST=("$@") # Parse Command Line Options. -OPT_SHORT="AcCdefFghiLmop:rRsV" +OPT_SHORT="AcCdefFghiLmop:rRstV" OPT_LONG="allsource,asroot,ignorearch,check,clean,cleancache,nodeps" OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver" OPT_LONG+=",install,log,nocolor,nobuild,nocheck,pkg:,rmdeps" -OPT_LONG+=",repackage,skipinteg,source,syncdeps,version,config:" +OPT_LONG+=",repackage,skipinteg,source,syncdeps,splitdbg,version,config:" # Pacman Options OPT_LONG+=",noconfirm,noprogressbar" OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')" @@ -1671,6 +1740,7 @@ --skipinteg) SKIPINTEG=1 ;; --source) SOURCEONLY=1 ;; -s|--syncdeps) DEP_BIN=1 ;; + -t|--splitdbg) SPLIT_DBG=1 ;; -h|--help) usage; exit 0 ;; # E_OK -V|--version) version; exit 0 ;; # E_OK @@ -1964,6 +2034,11 @@ tidy_install fi create_package + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + backup_package_variables + create_dbgpackage + restore_package_variables + fi else run_split_packaging fi @@ -2064,6 +2139,10 @@ msg "$(gettext "Removing existing pkg/ directory...")" rm -rf "$pkgdir" fi + if [[ -d $dbgdir ]] && (( ! REPKG || PKGFUNC || SPLIT_DBG )); then + msg "$(gettext "Removing existing dbg/ directory...")" + rm -rf "$dbgdir" + fi mkdir -p "$pkgdir" chmod a-s "$pkgdir" cd "$startdir" @@ -2088,6 +2167,11 @@ fi fi create_package + if (( SPLIT_DBG )); then + backup_package_variables + create_dbgpackage + restore_package_variables + fi else run_split_packaging fi