halflife25-sdk/linux/gendbg.sh

61 lines
945 B
Bash
Raw Permalink Normal View History

2013-08-30 20:34:05 +00:00
#!/bin/bash
p4_edit () {
chmod -R +w "$@" || true
}
p4_revert () {
true
}
2024-08-21 02:58:27 +00:00
UNAME=$(uname)
2013-08-30 20:34:05 +00:00
if [ "$UNAME" == "Darwin" ]; then
2024-08-21 02:58:27 +00:00
p4_edit "$1.dSYM/..."
dsymutil "$1"
p4 revert -a "$1.dSYM/..."
2013-08-30 20:34:05 +00:00
exit 0;
fi
OBJCOPY=objcopy
2013-08-30 20:34:05 +00:00
function usage {
echo "$0 /path/to/input/file [-o /path/to/output/file ]"
echo ""
}
if [ $# == 0 ]; then
usage
exit 2
fi
2024-08-21 02:58:27 +00:00
if [ $(basename "$1") == "$1" ]; then
2013-08-30 20:34:05 +00:00
INFILEDIR=$PWD
else
2024-08-21 02:58:27 +00:00
INFILEDIR=$(cd "${1%/*}" && echo "$PWD")
2013-08-30 20:34:05 +00:00
fi
2024-08-21 02:58:27 +00:00
INFILE=$(basename "$1")
2013-08-30 20:34:05 +00:00
OUTFILEDIR=$INFILEDIR
OUTFILE=$INFILE.dbg
while getopts "o:" opt; do
case $opt in
o)
2024-08-21 02:58:27 +00:00
OUTFILEDIR=$(cd "${OPTARG%/*}" && echo "$PWD")
OUTFILE=$(basename "$OPTARG")
2013-08-30 20:34:05 +00:00
;;
esac
done
if [ "$OUTFILEDIR" != "$INFILEDIR" ]; then
INFILE=${INFILEDIR}/${INFILE}
OUTFILE=${OUTFILEDIR}/${OUTFILE}
fi
2024-08-21 02:58:27 +00:00
pushd "$INFILEDIR" || exit
p4_edit "$OUTFILE"
2013-08-30 20:34:05 +00:00
$OBJCOPY "$INFILE" "$OUTFILE"
$OBJCOPY --add-gnu-debuglink="$OUTFILE" "$INFILE"
2024-08-21 02:58:27 +00:00
p4_revert -a "$OUTFILE"
popd || exit