2011-07-12 18:25:27 -06:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# NOTE: This is dfhack's modification of the normal invocation script,
|
|
|
|
# changed to properly set LD_PRELOAD so as to run DFHACK.
|
2011-07-13 00:37:49 -06:00
|
|
|
#
|
|
|
|
# You can run DF under gdb by passing -g or --gdb as the first argument.
|
2011-07-17 16:50:31 -06:00
|
|
|
#
|
|
|
|
# If the file ".dfhackrc" exists in the DF directory or your home directory
|
|
|
|
# it will be sourced by this script, to let you set environmental variables.
|
|
|
|
# If it exists in both places it will first source the one in your home
|
|
|
|
# directory, then the on in the game directory.
|
|
|
|
#
|
|
|
|
# Shell variables .dfhackrc can set to affect this script:
|
|
|
|
# DF_GDB_OPTS: Options to pass to gdb, if it's being run
|
|
|
|
# DF_VALGRIND_OPTS: Options to pass to valgrind, if it's being run
|
|
|
|
# DF_HELGRIND_OPTS: Options to pass to helgrind, if it's being run
|
|
|
|
# DF_POST_CMD: Shell command to be run at very end of script
|
2016-01-18 07:18:32 -07:00
|
|
|
# DFHACK_NO_RENAME_LIBSTDCXX: Non-empty to prevent automatically renaming libstdc++
|
2011-07-12 18:25:27 -06:00
|
|
|
|
|
|
|
DF_DIR=$(dirname "$0")
|
|
|
|
cd "${DF_DIR}"
|
|
|
|
export SDL_DISABLE_LOCK_KEYS=1 # Work around for bug in Debian/Ubuntu SDL patch.
|
|
|
|
#export SDL_VIDEO_CENTERED=1 # Centre the screen. Messes up resizing.
|
|
|
|
|
2011-07-17 16:50:31 -06:00
|
|
|
# User config files
|
|
|
|
RC=".dfhackrc"
|
|
|
|
|
|
|
|
if [ -r "$HOME/$RC" ]; then
|
|
|
|
. $HOME/$RC
|
|
|
|
fi
|
|
|
|
if [ -r "./$RC" ]; then
|
|
|
|
. "./$RC"
|
|
|
|
fi
|
|
|
|
|
2016-01-18 07:18:32 -07:00
|
|
|
# Disable bundled libstdc++
|
|
|
|
libcxx_orig="libs/libstdc++.so.6"
|
|
|
|
libcxx_backup="libs/libstdc++.so.6.backup"
|
|
|
|
if [ -z "${DFHACK_NO_RENAME_LIBSTDCXX:-}" ] && [ -e "$libcxx_orig" ] && [ ! -e "$libcxx_backup" ]; then
|
|
|
|
mv "$libcxx_orig" "$libcxx_backup"
|
|
|
|
cat <<EOF
|
|
|
|
NOTICE: $libcxx_orig has been moved to $libcxx_backup
|
|
|
|
for better compatibility. If you are using an older distro and this breaks,
|
|
|
|
run "cp $libcxx_backup $libcxx_orig", or add this to
|
|
|
|
$HOME/$RC to affect future DFHack installations:
|
|
|
|
|
|
|
|
export DFHACK_NO_RENAME_LIBSTDCXX=1
|
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2020-03-26 20:58:43 -06:00
|
|
|
if [ ! -t 0 ]; then
|
|
|
|
stty() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2012-07-12 05:00:01 -06:00
|
|
|
# Save current terminal settings
|
|
|
|
old_tty_settings=$(stty -g)
|
|
|
|
|
2015-12-22 12:08:03 -07:00
|
|
|
# Use distro_fixes.sh from LNP if it exists
|
|
|
|
DISTROFIXES="distro_fixes.sh"
|
|
|
|
if [ -r "$DISTROFIXES" ]; then
|
|
|
|
. "./$DISTROFIXES"
|
|
|
|
fi
|
|
|
|
|
2011-07-17 16:50:31 -06:00
|
|
|
# Now run
|
|
|
|
|
2016-10-22 11:04:15 -06:00
|
|
|
export LD_LIBRARY_PATH="./hack/libs:./hack:$LD_LIBRARY_PATH"
|
2011-08-20 05:37:14 -06:00
|
|
|
|
2018-07-05 08:54:49 -06:00
|
|
|
LIB="./hack/libdfhack.so"
|
|
|
|
LIBSAN=""
|
|
|
|
if which objdump > /dev/null; then
|
|
|
|
LIBSAN="$(objdump -p $LIB | sed -n 's/^.*NEEDED.*\(lib[a-z]san[a-z.0-9]*\).*$/\1/p' | head -n1):"
|
|
|
|
fi
|
|
|
|
PRELOAD_LIB="${PRELOAD_LIB:+$PRELOAD_LIB:}${LIBSAN}${LIB}"
|
2014-04-20 23:33:13 -06:00
|
|
|
|
2017-08-21 17:34:46 -06:00
|
|
|
setarch_arch=$(cat hack/dfhack_setarch.txt || printf i386)
|
2020-01-14 21:54:51 -07:00
|
|
|
if ! setarch "$setarch_arch" -R true 2>/dev/null; then
|
|
|
|
echo "warn: architecture '$setarch_arch' not supported by setarch" >&2
|
|
|
|
if [ "$setarch_arch" = "i386" ]; then
|
|
|
|
setarch_arch=linux32
|
|
|
|
else
|
|
|
|
setarch_arch=linux64
|
|
|
|
fi
|
|
|
|
echo "using '$setarch_arch' instead. To silence this warning, edit" >&2
|
|
|
|
echo "hack/dfhack_setarch.txt to contain an architecture that works on your system." >&2
|
|
|
|
fi
|
2017-08-21 17:34:46 -06:00
|
|
|
|
2011-07-13 00:37:49 -06:00
|
|
|
case "$1" in
|
|
|
|
-g | --gdb)
|
|
|
|
shift
|
2018-06-12 11:44:21 -06:00
|
|
|
echo "set exec-wrapper env LD_LIBRARY_PATH='$LD_LIBRARY_PATH' LD_PRELOAD='$PRELOAD_LIB' MALLOC_PERTURB_=45" > gdbcmd.tmp
|
|
|
|
gdb $DF_GDB_OPTS -x gdbcmd.tmp --args ./libs/Dwarf_Fortress "$@"
|
2011-07-15 07:55:01 -06:00
|
|
|
rm gdbcmd.tmp
|
2011-07-13 00:37:49 -06:00
|
|
|
ret=$?
|
|
|
|
;;
|
2018-06-12 11:45:47 -06:00
|
|
|
-r | --remotegdb)
|
|
|
|
shift
|
|
|
|
if [ "$#" -gt 0 ]; then
|
|
|
|
echo "****"
|
|
|
|
echo "gdbserver doesn't support spaces in arguments."
|
|
|
|
echo "If your world gen name has spaces you need to remove spaces from the name in data/init/world_gen.txt"
|
|
|
|
echo "****"
|
|
|
|
fi
|
|
|
|
echo "set environment LD_LIBRARY_PATH $LD_LIBRARY_PATH" > gdbcmd.tmp
|
|
|
|
echo "set environment LD_PRELOAD $PRELOAD_LIB" >> gdbcmd.tmp
|
|
|
|
echo "set environment MALLOC_PERTURB_ 45" >> gdbcmd.tmp
|
|
|
|
echo "set startup-with-shell off" >> gdbcmd.tmp
|
|
|
|
echo "target extended-remote localhost:12345" >> gdbcmd.tmp
|
|
|
|
echo "set remote exec-file ./libs/Dwarf_Fortress" >> gdbcmd.tmp
|
|
|
|
# For some reason gdb ignores sysroot setting if it is from same file as
|
|
|
|
# target extended-remote command
|
|
|
|
echo "set sysroot /" > gdbcmd_sysroot.tmp
|
|
|
|
gdb $DF_GDB_OPTS -x gdbcmd.tmp -x gdbcmd_sysroot.tmp --args ./libs/Dwarf_Fortress "$@"
|
|
|
|
rm gdbcmd.tmp gdbcmd_sysroot.tmp
|
|
|
|
ret=$?
|
|
|
|
;;
|
|
|
|
-s | --gdbserver) # -s for server
|
|
|
|
shift
|
|
|
|
echo "Starting gdbserver in multi mode."
|
|
|
|
echo "To exit the gdbserver you can enter 'monitor exit' command to gdb or use kill signal"
|
|
|
|
gdbserver --multi localhost:12345
|
|
|
|
ret=$?
|
|
|
|
;;
|
2011-07-14 00:02:29 -06:00
|
|
|
-h | --helgrind)
|
|
|
|
shift
|
2017-08-21 17:34:46 -06:00
|
|
|
LD_PRELOAD="$PRELOAD_LIB" setarch "$setarch_arch" -R valgrind $DF_HELGRIND_OPTS --tool=helgrind --log-file=helgrind.log ./libs/Dwarf_Fortress "$@"
|
2011-07-14 00:02:29 -06:00
|
|
|
ret=$?
|
|
|
|
;;
|
|
|
|
-v | --valgrind)
|
|
|
|
shift
|
2017-08-21 17:34:46 -06:00
|
|
|
LD_PRELOAD="$PRELOAD_LIB" setarch "$setarch_arch" -R valgrind $DF_VALGRIND_OPTS --log-file=valgrind.log ./libs/Dwarf_Fortress "$@"
|
2011-07-14 00:02:29 -06:00
|
|
|
ret=$?
|
|
|
|
;;
|
2011-07-21 03:29:26 -06:00
|
|
|
-c | --callgrind)
|
|
|
|
shift
|
2017-08-21 17:34:46 -06:00
|
|
|
LD_PRELOAD="$PRELOAD_LIB" setarch "$setarch_arch" -R valgrind $DF_CALLGRIND_OPTS --tool=callgrind --separate-threads=yes --dump-instr=yes --instr-atstart=no --log-file=callgrind.log ./libs/Dwarf_Fortress "$@"
|
2011-07-21 03:29:26 -06:00
|
|
|
ret=$?
|
|
|
|
;;
|
2018-06-12 11:42:12 -06:00
|
|
|
--strace)
|
|
|
|
shift
|
|
|
|
strace -f setarch "$setarch_arch" -R env LD_PRELOAD="$PRELOAD_LIB" ./libs/Dwarf_Fortress "$@" 2> strace.log
|
|
|
|
ret=$?
|
|
|
|
;;
|
2020-02-09 17:12:38 -07:00
|
|
|
-x | --exec)
|
2020-02-09 17:01:24 -07:00
|
|
|
exec setarch "$setarch_arch" -R env LD_PRELOAD="$PRELOAD_LIB" ./libs/Dwarf_Fortress "$@"
|
|
|
|
# script does not resume
|
|
|
|
;;
|
2020-08-07 22:31:33 -06:00
|
|
|
--sc | --sizecheck)
|
|
|
|
PRELOAD_LIB="${PRELOAD_LIB:+$PRELOAD_LIB:}./hack/libsizecheck.so"
|
|
|
|
MALLOC_PERTURB_=45 setarch "$setarch_arch" -R env LD_PRELOAD="$PRELOAD_LIB" ./libs/Dwarf_Fortress "$@"
|
|
|
|
ret=$?
|
|
|
|
;;
|
2011-07-13 00:37:49 -06:00
|
|
|
*)
|
2017-08-21 17:34:46 -06:00
|
|
|
setarch "$setarch_arch" -R env LD_PRELOAD="$PRELOAD_LIB" ./libs/Dwarf_Fortress "$@"
|
2011-07-13 00:37:49 -06:00
|
|
|
ret=$?
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2012-07-12 05:00:01 -06:00
|
|
|
# Restore previous terminal settings
|
|
|
|
stty "$old_tty_settings"
|
2016-05-14 17:39:10 -06:00
|
|
|
tput sgr0
|
2014-09-17 19:29:47 -06:00
|
|
|
echo
|
2011-07-17 16:50:31 -06:00
|
|
|
|
|
|
|
if [ -n "$DF_POST_CMD" ]; then
|
|
|
|
eval $DF_POST_CMD
|
|
|
|
fi
|
2011-07-13 00:37:49 -06:00
|
|
|
|
|
|
|
exit $ret
|