halflife25-sdk/linux/gendbg.sh

73 lines
1.1 KiB
Bash
Raw Normal View History

2013-08-30 20:34:05 +00:00
#!/bin/bash
2024-08-21 02:58:27 +00:00
if [[ -n "$VALVE_NO_AUTO_P4" ]]; then
p4_edit () {
chmod -R +w "$@" || true
}
p4_revert () {
true
}
else
p4_edit () {
p4 edit "$@"
}
p4_revert () {
p4 revert "$@"
}
fi
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
2024-08-21 02:58:27 +00:00
if [[ -z "$USE_STEAM_RUNTIME" ]]; then
OBJCOPY=/valve/bin/objcopy
else
OBJCOPY=objcopy
fi
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