[BACK]Return to ctfstrip CVS log [TXT][DIR] Up to [local] / src / usr.bin / ctfconv

Annotation of src/usr.bin/ctfconv/ctfstrip, Revision 1.9

1.1       mpi         1: #!/bin/sh
1.2       mpi         2: #
1.9     ! sunil       3: # $OpenBSD: ctfstrip,v 1.8 2017/08/15 15:48:10 jasper Exp $
1.2       mpi         4: #
1.4       jasper      5: # Copyright (c) 2017 Martin Pieuchot
1.2       mpi         6: #
                      7: # Permission to use, copy, modify, and distribute this software for any
                      8: # purpose with or without fee is hereby granted, provided that the above
                      9: # copyright notice and this permission notice appear in all copies.
                     10: #
                     11: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     12: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     13: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     14: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     15: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     16: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     17: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       mpi        18:
1.3       jasper     19: set -o posix
                     20:
                     21: cleanup() {
                     22:        rm -f ${TMPFILE}
                     23:        exit 1
                     24: }
                     25:
                     26: trap "cleanup" 1 2 3 13 15
1.1       mpi        27:
                     28: USAGE="usage: ${0##*/} [-S] [-o outfile] file"
                     29:
1.4       jasper     30: for arg in "$@"; do
                     31:        if [ -n "$OSET" ]; then
                     32:                OUTFILE="$arg"
                     33:                unset OSET
                     34:                shift
                     35:                continue
                     36:        fi
                     37:        case "$arg" in
                     38:        -o)     OSET=1; shift; continue;;
                     39:        -S)     STRIPFLAG=-g; shift; continue;;
1.1       mpi        40:        esac
1.4       jasper     41:        shift
1.8       jasper     42:        set -- "$@" "$arg"
1.5       jasper     43:        INFILE="$arg"
1.1       mpi        44: done
                     45:
1.5       jasper     46: if [ $# -eq 0 ]; then
                     47:        echo "${USAGE}" >&2
1.1       mpi        48:        exit 1
                     49: fi
                     50:
                     51: LABEL="unknown"
1.3       jasper     52: TMPFILE=$(mktemp /tmp/.ctf.XXXXXXXXXX)
1.1       mpi        53:
1.3       jasper     54: # Extract kernel version
1.5       jasper     55: if [ -z "${INFILE##bsd*}" ]; then
1.8       jasper     56:        LABEL=`what "$INFILE" | sed -n '$s/^   //p'`
1.1       mpi        57: fi
                     58:
1.4       jasper     59: # If ctfstrip was passed a file that lacks useful debug sections, ctfconv will fail.
                     60: # So try to run ctfconv and silently fallback to plain strip(1) if that failed.
1.8       jasper     61: ctfconv -o ${TMPFILE} -l "${LABEL}" "${INFILE}" 2> /dev/null
1.4       jasper     62:
1.5       jasper     63: if [ $? -eq 0 ]; then
1.9     ! sunil      64:        objcopy --add-section .SUNW_ctf=${TMPFILE} ${STRIPFLAG} "${INFILE}" ${OUTFILE}
1.4       jasper     65: else
1.9     ! sunil      66:        strip ${STRIPFLAG} ${OUTFILE:+"-o${OUTFILE}"} "${INFILE}"
1.4       jasper     67: fi
1.1       mpi        68:
                     69: rm -f ${TMPFILE}