Home | History | Annotate | Download | only in src
      1 #!/bin/sh
      2 #
      3 # Script to make an offline archive for debugging with libdwfl-based tools.
      4 #
      5 #	make-debug-archive ARCHIVE {options}
      6 #	make-debug-archive --kernel [--force] [RELEASE]
      7 #
      8 # Valid options are those listed under 'Input selection options'
      9 # by running @UNSTRIP@ --help.
     10 #
     11 # The archive installed by --kernel be used automatically by -K.
     12 # An offline archive can be used via -e in any tool that accepts those options.
     13 #
     14 
     15 UNSTRIP=${UNSTRIP:-@UNSTRIP@}
     16 AR=${AR:-@AR@}
     17 SUDO=${SUDO:-/usr/bin/sudo}
     18 
     19 LS=/bin/ls
     20 RM=/bin/rm
     21 MV=/bin/mv
     22 MKDIR=/bin/mkdir
     23 XARGS=/usr/bin/xargs
     24 
     25 outdir=${TMPDIR:-/tmp}/debugar$$
     26 
     27 usage()
     28 {
     29   echo "Usage: $0 ARCHIVE {options}"
     30   echo "   or: $0 --kernel [--sudo] [--force] [RELEASE]"
     31   echo
     32   echo "Valid options are listed under 'Input selection options'"
     33   echo "when running: $UNSTRIP --help"
     34   echo
     35   echo "The --kernel form updates the file used by -K if the"
     36   echo "kernel installation has changed, or always with --force."
     37   echo "With --sudo, touches the installed file via $SUDO."
     38 }
     39 
     40 fatal_usage()
     41 {
     42   usage >&2
     43   exit 2
     44 }
     45 
     46 script_version()
     47 {
     48   echo "`basename $0` (@PACKAGE_NAME@) @PACKAGE_VERSION@"
     49   echo "Copyright (C) 2007 Red Hat, Inc."
     50   echo "This is free software; see the source for copying conditions."
     51   echo "There is NO warranty; not even for MERCHANTABILITY or"
     52   echo "FITNESS FOR A PARTICULAR PURPOSE."
     53   echo "Written by Roland McGrath."
     54 }
     55 
     56 sudo=
     57 kernel=no
     58 force_kernel=no
     59 while [ $# -gt 0 ]; do
     60   case "x$1" in
     61   x--help) usage; exit 0 ;;
     62   x--version) script_version; exit 0 ;;
     63   x--kernel) kernel=yes ;;
     64   x--force) force_kernel=yes ;;
     65   x--sudo) sudo=$SUDO ;;
     66   *) break ;;
     67   esac
     68   shift
     69 done
     70 
     71 if [ $kernel = no ] && [ $force_kernel = yes -o -n "$sudo" ]; then
     72   usage
     73 fi
     74 
     75 if [ $kernel = yes ]; then
     76   if [ $# -eq 0 ]; then
     77     release=`uname -r`
     78   elif [ $# -eq 1 ]; then
     79     release=$1
     80   else
     81     fatal_usage
     82   fi
     83 
     84   dir=/usr/lib/debug/lib/modules/$release
     85   archive=$dir/debug.a
     86   dep=/lib/modules/$release/modules.dep
     87 
     88   if [ ! -d $dir ]; then
     89     echo >&2 "$0: $dir not installed"
     90     exit 1
     91   fi
     92 
     93   # Without --force, bail if the kernel installation is not newer.
     94   # This file is normally touched by installing new kernels or modules.
     95   if [ $force_kernel = no -a "$archive" -nt "$dep" ]; then
     96     exit 0
     97   fi
     98 
     99   # We have to kill the old one first, because our own -K would use it.
    100   [ ! -e "$archive" ] || $sudo $RM -f "$archive" || exit
    101 
    102   set "$archive" "-K$release"
    103 fi
    104 
    105 if [ $# -lt 2 ]; then
    106   fatal_usage
    107 fi
    108 
    109 archive="$1"
    110 shift
    111 
    112 case "$archive" in
    113 /*) ;;
    114 *) archive="`/bin/pwd`/$archive" ;;
    115 esac
    116 
    117 if [ -z "$sudo" ]; then
    118   new_archive="$archive.new"
    119 else
    120   new_archive="$outdir.a"
    121 fi
    122 
    123 $RM -f "$new_archive" || exit
    124 
    125 trap '$RM -rf "$outdir" "$new_archive"' 0 1 2 15
    126 
    127 $MKDIR "$outdir" &&
    128 $UNSTRIP -d "$outdir" -m -a -R "$@" &&
    129 (cd "$outdir" && $LS | $XARGS $AR cq "$new_archive") &&
    130 $sudo $MV -f "$new_archive" "$archive"
    131 
    132 exit
    133