forked from SpaceManiac/HamSandwich
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·274 lines (263 loc) · 7.37 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
set -euo pipefail
# Help
show_help() {
echo "Usage: $0 [<setting=value>] <project> [-- <arguments>]"
echo "Settings:"
echo " os= One of: windows linux macos emscripten"
echo " arch= One of: i686 x86_64"
echo " mode= One of: debug release"
echo " preset= Set os, arch, and mode together, ex: windows-i686-release"
echo " nobuild=1 Skip compiling before running."
echo " tool=gdb Start GDB prepared to debug the game."
echo " tool=valgrind Run the game under valgrind memory checker (slow)."
echo " tool=callgrind Run the game under callgrind profiler (slow)."
echo " tool=two Run two instances of the game at once."
echo " tool=deck Upload to and run on a Steam Deck over SSH. Linux only."
}
# Default settings.
project=launcher
os=
arch=
mode=debug
preset=
nobuild=
tool=
override_args=
# Read command-line arguments.
while test $# -ne 0; do
arg="$1"; shift
case "$arg" in
# settings
project=* | os=* | arch=* | mode=* | preset=* | nobuild=* | tool=*)
declare "$arg"
;;
# show help on demand
--help)
show_help; exit
;;
--)
# -- indicates the start of overriden arguments
override_args=1
break
;;
# transitional adapters from ./run
"--fullscreen")
override_args=1
;;
"--release")
mode=release
;;
"--gdb")
tool=gdb
;;
"--valgrind")
tool=valgrind
;;
"--callgrind")
tool=callgrind
;;
"--nobuild")
nobuild=1
;;
"--web")
os=emscripten
;;
"--two")
tool=two
;;
# show help for unsupported settings or flags
*=* | -*)
show_help; exit 1
;;
# a setting without a variable name is $project
*)
project="$arg"
;;
esac
done
# Abort if no project was specified.
if test -z "$project"; then
show_help; exit 1
fi
# Fallback settings. Keep this in sync with `Makefile`!
container=
if test -z "$preset"; then
if test -z "$os"; then
# Detect OS and architecture.
case "$(uname -sm)" in
MSYS*|MINGW32*)
# Note: MSYS not actually supported, but `install-deps` & `make` will report that.
os=windows
arch=${arch:-i686}
;;
MINGW64*)
os=windows
arch=${arch:-x86_64}
;;
"Linux x86_64")
os=linux
container=./container
arch=${arch:-x86_64}
;;
"Darwin x86_64")
os=macos
arch=${arch:-x86_64}
;;
*)
echo "Unknown \`uname -sm\`: $(uname -sm)"
exit 1
esac
elif test -z "$arch"; then
# Use default architecture for chosen OS.
case "$os" in
windows|emscripten)
arch=i686
;;
linux|macos)
arch=x86_64
;;
esac
fi
preset="$os-$arch-$mode"
fi
tools/build/install-deps.sh
if test -z "$tool" && test "$os" = "emscripten"; then
tool=emrun
source ./tools/emscripten/install-emsdk.sh
fi
debugext=
if test "$os" = "windows"; then
debugext=".exe"
fi
# Default debug configuration
debugdir="$PWD/build/install"
cmakedir="$PWD/build/cmake-$preset"
debugcommand="$debugdir/$project$debugext"
debugargs=()
debugenvs=()
# Build and install
cmake() {
tools/bootstrap/cmake "$@"
}
if test -z "$nobuild"; then
if test "$os" = "emscripten"; then
# Web.
debugdir="$PWD/build/webroot"
if test "$project" != "launcher"; then
# Single project: build and install just that project.
make preset="$preset" "$project"
cmake --install "$cmakedir" --component "$project"/web --config Debug
else
# Otherwise, build and install everything.
make preset="$preset" install
fi
else
# Desktop.
case "$project" in
launcher)
# Launcher: build everything that isn't excluded, because that's
# what will be presented in the launcher UI.
$container make preset="$preset" install
;;
jfttool|jspedit|lunaticpal|mini_xxd)
# Tool: build just that project. Don't bother installing it.
$container make preset="$preset" "$project" sdl2_rpath
$container cmake --install "$cmakedir" --component generic/executables --config Debug
$container cmake --install "$cmakedir" --component "$project"/executables --config Debug
;;
*)
# Single game project: build the launcher and that project.
debugargs=("window")
$container make preset="$preset" "$project" launcher sdl2_rpath
# Install the launcher so that it can be used to download assets.
$container cmake --install "$cmakedir" --component Unspecified --config Debug
$container cmake --install "$cmakedir" --component generic/executables --config Debug
$container cmake --install "$cmakedir" --component launcher/executables --config Debug
$container cmake --install "$cmakedir" --component "$project"/executables --config Debug
;;
esac
fi
fi
# Handle ./run jfttool and lunaticpal which don't have CMake install scripts.
if ! test -f "$debugcommand"; then
cp "$cmakedir/source/$project/$project$debugext" "$debugcommand"
if test "$os" = "linux"; then
patchelf --add-rpath "\$ORIGIN" "$debugcommand"
fi
fi
# Run the game executable or tool.
mkdir -p "$debugdir"
cd "$debugdir"
if test ${#debugenvs[@]} -ne 0; then
export "${debugenvs[@]}"
fi
if test "$override_args"; then
debugargs=("$@")
fi
case "$tool" in
gdb)
echo "==== Debugging $project ($preset) ===="
# Catches "the runtime was asked to terminate in an usual way".
# If libc++ is dynamically linked, the breakpoint should be pending.
gdb -q \
-ex 'set breakpoint pending on' \
-ex 'break abort' \
-ex 'set breakpoint pending auto' \
--args "$debugcommand" "${debugargs[@]}"
;;
valgrind)
echo "==== Valgrinding $project ($preset) ===="
valgrind "$debugcommand" "${debugargs[@]}"
;;
callgrind)
echo "==== Callgrinding $project ($preset) ===="
valgrind --tool=callgrind "$debugcommand" "${debugargs[@]}"
;;
emrun)
echo "==== Hosting $project ($preset) ===="
if test "$project" = "launcher"; then
emrun --serve_after_close --serve_after_exit "$debugdir/index.html"
else
# TODO: Serve out of CMake dir, so non-installed projects work
emrun --serve_after_close "$debugdir/$project.html"
fi
;;
two)
echo "==== Running $project ($preset) ===="
"$debugcommand" "${debugargs[@]}" &
"$debugcommand" "${debugargs[@]}"
;;
deck)
# TODO: remove requirement that "SteamOS Devkit Client" has been set up
# TODO: allow configuring deck_addr
deck_game=HamSandwich
echo "==== Uploading to $deck_addr:devkit-game/$deck_game ===="
deck_exe=${debugcommand##*/}
rsync -av --chmod=Du=rwx,Dgo=rx,Fu=rwx,Fog=rx -e "ssh -o StrictHostKeyChecking=no -i $HOME/.config/steamos-devkit/devkit_rsa" "$debugcommand" ./ "$deck_addr:/home/deck/devkit-game/$deck_game/"
# shellcheck disable=SC2087
ssh -o StrictHostKeyChecking=no -i ~/.config/steamos-devkit/devkit_rsa "$deck_addr" sh <<-EOD
set -eu
devkit-utils/steam-client-create-shortcut --parms '{"gameid": "$deck_game", "directory": "/home/deck/devkit-game/$deck_game", "argv": ["./$deck_exe"], "settings": {"steam_play": "0"}}'
EOD
# TODO: launch the game automatically
# data = parse ~/.local/share/Steam/userdata/$USERID/config/shortcuts.vdf
# appid = ((data['shortcuts']['N']['appid'] & 0xffffffff) << 32) | 0x02000000
# steam steam://rungameid/$appid
# TODO: tail -F a logfile or pipe to read console output
;;
"")
if test -f "$debugcommand"; then
echo "==== Running $project ($preset) ===="
"$debugcommand" "${debugargs[@]}"
else
echo "$project: not a runnable target."
exit 1
fi
;;
*)
echo "$0: unknown tool: $tool"
exit 1
;;
esac