--- /usr/bin/makepkg 2010-06-21 14:54:14.000000000 +0200 +++ makepkg2 2010-07-28 14:34:53.000000000 +0200 @@ -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' 'makeflags' 'force') splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \ 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \ @@ -862,21 +863,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 && -n ${STRIP_DIRS[*]} ]]; 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_opts find ${STRIP_DIRS[@]} -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_opts=$STRIP_SHARED ;; *application/x-archive*) # Libraries (.a) - /usr/bin/strip $STRIP_STATIC "$binary";; + strip_opts=$STRIP_STATIC ;; *application/x-executable*) # Binaries - /usr/bin/strip $STRIP_BINARIES "$binary";; + strip_opts=$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 @@ -991,13 +1021,13 @@ check_package cd "$pkgdir" - msg "$(gettext "Creating package...")" if [[ -z $1 ]]; then nameofpkg="$pkgname" else nameofpkg="$1" fi + msg "$(gettext "Creating package $nameofpkg...")" if [[ $arch = "any" ]]; then PKGARCH="any" @@ -1070,6 +1100,38 @@ 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 (debug info)" + depends=("$pkgname=$pkgver-$pkgrel") + groups=('debug' ${groups[@]/%/-debug}) + optdepends=() + replaces=() + provides=() # ${provides[@]/%/-dbg} + conflicts=() # ${conflicts[@]/%/-dbg} + # Make it! + create_package $nameofdbgpkg + pkgdir="$oldpkgdir" +} + create_srcpackage() { cd "$startdir" @@ -1541,11 +1603,11 @@ ARGLIST=("$@") # Parse Command Line Options. -OPT_SHORT="AcCdefFghiLmop:rRsV" +OPT_SHORT="AcCdefFghiLmop:rRstV" OPT_LONG="allsource,asroot,ignorearch,clean,cleancache,nodeps" OPT_LONG="$OPT_LONG,noextract,force,forcever:,geninteg,help,holdver" OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,pkg:,rmdeps,repackage,skipinteg" -OPT_LONG="$OPT_LONG,source,syncdeps,version,config:" +OPT_LONG="$OPT_LONG,source,syncdeps,splitdbg,version,config:" # Pacman Options OPT_LONG="$OPT_LONG,noconfirm,noprogressbar" OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')" @@ -1588,6 +1650,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 @@ -1861,17 +1924,25 @@ tidy_install fi create_package + if [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ]; then + backup_package_variables + create_dbgpackage + restore_package_variables + fi else for pkg in ${pkgname[@]}; do pkgdir="$pkgdir/$pkg" + dbgdir="$dbgdir/$pkg" mkdir -p "$pkgdir" chmod a-s "$pkgdir" backup_package_variables run_package $pkg tidy_install create_package $pkg + [ "$(check_option splitdbg)" = "y" ] || [ "$SPLIT_DBG" = "1" ] && create_dbgpackage $pkg restore_package_variables pkgdir="${pkgdir%/*}" + dbgdir="${dbgdir%/*}" done fi @@ -1966,6 +2037,10 @@ msg "$(gettext "Removing existing pkg/ directory...")" rm -rf "$pkgdir" fi + if [[ -d $dbgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then + msg "$(gettext "Removing existing dbg/ directory...")" + rm -rf "$dbgdir" + fi mkdir -p "$pkgdir" chmod a-s "$pkgdir" cd "$startdir" @@ -1989,17 +2064,25 @@ fi fi create_package + if (( SPLIT_DBG )); then + backup_package_variables + create_dbgpackage $pkgname + restore_package_variables + fi else for pkg in ${pkgname[@]}; do pkgdir="$pkgdir/$pkg" + dbgdir="$dbgdir/$pkg" mkdir -p "$pkgdir" chmod a-s "$pkgdir" backup_package_variables run_package $pkg tidy_install create_package $pkg + (( SPLIT_DBG )) && create_dbgpackage $pkg restore_package_variables pkgdir="${pkgdir%/*}" + dbgdir="${dbgdir%/*}" done fi else