From 904aee35a85b6d22cc77f9dcae259e00b7fb1275 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Mon, 30 Jan 2012 19:54:06 -0500 Subject: Fix oh-strip and add error handling. Well I feel stupid now... Thanks, shell interpreter and POSIX.1 XCU, for not warning me about my use of an uninitialized parameter. --- diff --git a/TODO b/TODO index e67605e..e1180fc 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ TODO: - * Fix oh-strip. * Make oh-strip obey a missing '-l' option. * Check on file ownership and modes. diff --git a/src/oh-strip b/src/oh-strip index 86e59b9..c03fb43 100644 --- a/src/oh-strip +++ b/src/oh-strip @@ -24,6 +24,12 @@ print_usage() printf 'Usage: %s [-g] [-l] binaryfile...\n' "$1" } +error() +{ + printf 'oh-strip: Error: %s\n' "${1}" + exit 1 +} + opts=$(getopt -n "${0}" -o 'gl' -- "${@}") if [ ${?} -ne 0 ]; then print_usage "${0}" >&2 @@ -51,8 +57,8 @@ while true; do esac done -if [ -z "${make_dbg_pkg}" ]; then - make_dbg_pkg=false +if [ -z "${make_dbg_obj}" ]; then + make_dbg_obj=false fi if [ -z "${is_lib}" ]; then is_lib=false @@ -67,17 +73,20 @@ fi while [ ${#} -gt 0 ]; do printf 'oh-strip: Stripping symbols from file "%s"...\n' "${1}" - # XXX: For some reason, this doesn't seem to work. - - if ${make_dbg_pkg}; then + if ${make_dbg_obj}; then # Copy debugging symbols into a debugging object file and add a GDB link # from the original object file to the debugging object file. - objcopy --only-keep-debug "dest/${1}" "dest/usr/lib/debug/${1}" - objcopy --add-gnu-debuglink="/usr/lib/debug/${1}" "dest/${1}" - chmod 644 "dest/usr/lib/debug/${1}" + mkdir -p "$(dirname "dest/usr/lib/debug/${1}")" || \ + error 'Cannot make directory path to debugging object' + objcopy --only-keep-debug --compress-debug-sections "dest/${1}" \ + "dest/usr/lib/debug/${1}" || error 'Cannot make debugging object' + objcopy --add-gnu-debuglink="dest/usr/lib/debug/${1}" "dest/${1}" || \ + error 'Cannot add GDB link' + chmod 644 "dest/usr/lib/debug/${1}" || \ + error 'Cannot set mode on debugging object' fi # Strip the object file of symbols. # TODO: If the file is not a library, strip it of all symbols. - strip -g "dest/${1}" + strip -g "dest/${1}" || error 'Cannot strip object' shift done -- cgit v0.9.1