~ Less code repetition ~ Drop -t flag; OPTIONS=(splitdbg) only ~ secure_dir isn't really secure but I couldn't think of a better name Signed-off-by: Arerep Serdna <aepd87@gmail.com> --- Original by Jan M. (funkyou): http://bugs.archlinux.org/task/10975 etc/makepkg.conf.in | 1 + scripts/makepkg.sh.in | 134 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 89 insertions(+), 46 deletions(-) diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in index f0d1c44..f744ac3 100644 --- a/etc/makepkg.conf.in +++ b/etc/makepkg.conf.in @@ -62,6 +62,7 @@ BUILDENV=(fakeroot !distcc color !ccache) # A negated option will do the opposite of the comments below. # #-- strip: Strip symbols from binaries/libraries in STRIP_DIRS +#-- splitdbg: Same as above, while keeping the symbols in usr/lib/debug #-- docs: Save doc directories specified by DOC_DIRS #-- libtool: Leave libtool (.la) files in packages #-- emptydirs: Leave empty directories in packages diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 1707245..93548ef 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -43,8 +43,9 @@ BUILDSCRIPT='@BUILDSCRIPT@' 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' \ @@ -808,6 +809,28 @@ run_package() { run_function "$pkgfunc" } +secure_dir() { + [[ -d $1 ]] || mkdir -p "$1"; chmod a-s "$1" +} + +# strip_flags must be declared local in the inclosing function +pre_strip() { + local binary + while read binary; do + case "$(file -biz "$binary")" in + *application/x-sharedlib*) # Libraries (.so) + strip_flags="$STRIP_SHARED";; + *application/x-archive*) # Libraries (.a) + strip_flags="$STRIP_STATIC";; + *application/x-executable*) # Binaries + strip_flags="$STRIP_BINARIES";; + *) + continue;; + esac + echo "$binary" + done < <(find "${STRIP_DIRS[@]}" -type f -perm -u+w 2>/dev/null) +} + tidy_install() { cd "$pkgdir" msg "$(gettext "Tidying install...")" @@ -865,21 +888,32 @@ tidy_install() { done fi - if [[ $(check_option strip) = y && -n ${STRIP_DIRS[*]} ]]; then - msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")" - local binary - find ${STRIP_DIRS[@]} -type f -perm -u+w 2>/dev/null | while read binary ; do - case "$(file -biz "$binary")" in - *compressed-encoding*) # Skip compressed binaries - ;; - *application/x-sharedlib*) # Libraries (.so) - /usr/bin/strip $STRIP_SHARED "$binary";; - *application/x-archive*) # Libraries (.a) - /usr/bin/strip $STRIP_STATIC "$binary";; - *application/x-executable*) # Binaries - /usr/bin/strip $STRIP_BINARIES "$binary";; - esac - done + if [[ -n ${STRIP_DIRS[*]} ]]; then + local strip_flags + if [[ $(check_option splitdbg) = "y" ]]; then + msg2 "$(gettext "Moving debugging symbols from binaries and libraries into separate files...")" + pre_strip | while read binary; do + basename="${binary%%*/}" + dirname="${dirname%/*}" + dbg_file="$basename.debug" + dbg_dest="$dbgdir/usr/lib/debug/$binary.debug" + dbg_destdir="${dbg_dest%/*}" + pushd "$dirname" &>/dev/null + /usr/bin/objcopy --only-keep-debug "$basename" "$dbg_file" + /usr/bin/strip $strip_flags "$basename" + /usr/bin/objcopy --add-gnu-debuglink="$dbg_file" "$basename" + if [[ ! -d $dbg_destdir ]]; then + mkdir -p "$dbg_destdir" + fi + mv "$dbg_file" "$dbg_dest" + popd &>/dev/null + done + elif [[ $(check_option strip) = "y" ]]; then + msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")" + pre_strip | while read binary; do + /usr/bin/strip $strip_flags "$binary" + done + fi fi if [[ $(check_option libtool) = "n" ]]; then @@ -1070,12 +1104,23 @@ create_package() { fi } +create_dbgpackage() { + [[ -n $(find "$dbgdir" -type f -name \*.debug -print -quit) && + $(check_option splitdbg) = "y" ]] || return 0 + local pkg="${1:-$pkgname}" + pkgdesc+=" (Debug symbols)" + pkgdir="$dbgdir" + depends=("$pkg") + unset backup build changelog conflicts install optdepends \ + provides replaces source + create_package "$pkg-debug" +} + create_srcpackage() { cd "$startdir" # Get back to our src directory so we can begin with sources. - mkdir -p "$srcdir" - chmod a-s "$srcdir" + secure_dir "$srcdir" cd "$srcdir" if (( ! SKIPINTEG || SOURCEONLY == 2 )); then download_sources @@ -1417,6 +1462,24 @@ restore_package_variables() { done } +process_splitpkg() { + for pkg in ${pkgname[@]}; do + for dir in {pkg,dbg}dir; do + read $dir <<<"${!dir}/$pkg" + secure_dir "${!dir}" + done + backup_package_variables + run_package $pkg + tidy_install + create_package $pkg + create_dbgpackage $pkg + restore_package_variables + for dir in {pkg,dbg}dir; do + read $dir <<<"${!dir%/*}" + done + done +} + # getopt like parser parse_options() { local short_options=$1; shift; @@ -1782,8 +1845,7 @@ else fi if (( GENINTEG )); then - mkdir -p "$srcdir" - chmod a-s "$srcdir" + secure_dir "$srcdir" cd "$srcdir" download_sources generate_checksums @@ -1884,18 +1946,9 @@ if (( INFAKEROOT )); then tidy_install fi create_package + create_dbgpackage else - for pkg in ${pkgname[@]}; do - pkgdir="$pkgdir/$pkg" - mkdir -p "$pkgdir" - chmod a-s "$pkgdir" - backup_package_variables - run_package $pkg - tidy_install - create_package $pkg - restore_package_variables - pkgdir="${pkgdir%/*}" - done + process_splitpkg fi msg "$(gettext "Leaving fakeroot environment.")" @@ -1949,8 +2002,7 @@ fi umask 0022 # get back to our src directory so we can begin with sources -mkdir -p "$srcdir" -chmod a-s "$srcdir" +secure_dir "$srcdir" cd "$srcdir" if (( NOEXTRACT )); then @@ -1989,8 +2041,7 @@ else msg "$(gettext "Removing existing pkg/ directory...")" rm -rf "$pkgdir" fi - mkdir -p "$pkgdir" - chmod a-s "$pkgdir" + secure_dir "$pkgdir" cd "$startdir" # if we are root or if fakeroot is not enabled, then we don't use it @@ -2012,18 +2063,9 @@ else fi fi create_package + create_dbgpackage else - for pkg in ${pkgname[@]}; do - pkgdir="$pkgdir/$pkg" - mkdir -p "$pkgdir" - chmod a-s "$pkgdir" - backup_package_variables - run_package $pkg - tidy_install - create_package $pkg - restore_package_variables - pkgdir="${pkgdir%/*}" - done + process_splitpkg fi else if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then -- 1.7.1