]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/all/xonotic.subr
demotc-race-record-extractor.sh: remove useless rc case (gametype name is always...
[xonotic/xonotic.git] / misc / tools / all / xonotic.subr
1 handled=true
2 case "$cmd" in
3         update-maps)
4                 misc/tools/xonotic-map-compiler-autobuild download
5                 ;;
6         compile-map)
7                 if [ $# -eq 0 ] ; then
8                         msg "Usage: ./all compile-map mapname1 mapname2 mapname3"
9                         msg "For example: ./all compile-map dance xoylent"
10                 fi
11                 if ! [ -f "netradiant/build/q3map2" ] ; then
12                         msg "q3map2 needed! Building q3map2..."
13                         cmake -H'netradiant' -B'netradiant/build' -G'Unix Makefiles' -D'CMAKE_BUILD_TYPE=Release' -DBUILD_RADIANT=OFF -DDOWNLOAD_GAMEPACKS=OFF
14                         cmake --build 'netradiant/build' -- q3map2
15                 fi
16                 for mapfile in "$@"; do
17                         mapfile="data/xonotic-maps.pk3dir/maps/$mapfile.map"
18                         if [ ! -f "$mapfile" ] ; then
19                                 msg "ERROR, $mapfile not found!"
20                         else
21                                 verbose measure_time misc/tools/xonotic-map-compiler-optionsfile "$mapfile"
22                         fi
23                 done
24                 ;;
25         compile)
26                 cleand0=false
27                 cleandp=false
28                 cleanqcc=false
29                 cleanqc=false
30                 compiled0=
31                 debug=release  # when changing this default, change the description in the zsh autocompletion script
32                 if [ -z "$CC" ]; then
33                         export CC="gcc"
34                 fi
35                 while :; do
36                         case "$1" in
37                                 -0)
38                                         compiled0=true
39                                         shift
40                                         ;;
41                                 -1)
42                                         compiled0=false
43                                         shift
44                                         ;;
45                                 -c)
46                                         cleand0=true
47                                         cleandp=true
48                                         cleanqcc=true
49                                         cleanqc=true
50                                         shift
51                                         ;;
52                                 -qc)
53                                         cleanqc=true
54                                         shift
55                                         ;;
56                                 -d|-p|-r)
57                                         case "$1" in
58                                                 -d)
59                                                         debug=debug
60                                                         ;;
61                                                 -p)
62                                                         debug=profile
63                                                         ;;
64                                                 -r)
65                                                         debug=release
66                                                         ;;
67                                         esac
68                                         export CC="$CC -g"
69                                         case "`$CC -dumpversion`" in
70                                                 [5-9]*|[1-9][0-9]*|4.[3-9]*|4.[1-9][0-9]*)
71                                                         # gcc 4.3 or higher
72                                                         # -march=native is broken < 4.3
73                                                         if $CC -mtune=native -march=native misc/tools/conftest.c -o conftest >/dev/null 2>&1; then
74                                                                 export CC="$CC -mtune=native -march=native"
75                                                         fi
76                                                         ;;
77                                         esac
78                                         if [ -n "$WE_HATE_OUR_USERS" ]; then
79                                                 export CC="$CC -fno-common"
80                                         fi
81                                         shift
82                                         ;;
83                                 *)
84                                         break
85                                         ;;
86                         esac
87                 done
88
89                 TARGETS="sv-$debug sdl-$debug"
90                 if [ x"`uname`" = x"Darwin" ]; then
91                         export CC="$CC -fno-reorder-blocks"
92                 fi
93
94                 if [ $# -gt 0 ] && [ x"$1" = x"" ]; then
95                         # if we give the command make the arg "", it will surely fail (invalid filename),
96                         # so better handle it as an empty client option
97                         BAD_TARGETS=" "
98                         shift
99                 elif [ -n "$1" ]; then
100                         BAD_TARGETS=
101                         TARGETS_SAVE=$TARGETS
102                         TARGETS=
103                         for X in $1; do
104                                 case "$X" in
105                                         sdl)
106                                                 TARGETS="$TARGETS sdl-$debug"
107                                                 ;;
108                                         dedicated)
109                                                 TARGETS="$TARGETS sv-$debug"
110                                                 ;;
111                                         *)
112                                                 BAD_TARGETS="$BAD_TARGETS $X"
113                                                 ;;
114                                 esac
115                         done
116                         if [ -n "$TARGETS" ]; then # at least a valid client
117                                 shift
118                         else # no valid client, let's assume this option is not meant to be a client then
119                                 TARGETS=$TARGETS_SAVE
120                                 BAD_TARGETS=
121                         fi
122                 fi
123
124                 if [ -z "$MAKE" ]; then
125                         MAKE=make
126                 fi
127
128                 if [ -z "$MAKEFLAGS" ]; then
129                         ncpus=`getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1`
130                         if [ $ncpus -gt 1 ]; then
131                                 MAKEFLAGS=-j$ncpus
132                         fi
133                         if [ -n "$WE_HATE_OUR_USERS" ]; then
134                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw"
135                         fi
136                 elif echo $MAKEFLAGS | head -c1 | grep -qv -; then # MAKEFLAGS starts with a single letter option
137                         MAKEFLAGS=-$(echo $MAKEFLAGS)                  # echo here and above will trim whitespaces
138                 fi
139
140                 # workaround ARM issue in DP's makefile.inc
141                 case `uname -m` in
142                         x86_64|*86)
143                                 ;;
144                         *)
145                                 MAKEFLAGS="$MAKEFLAGS CFLAGS_SSE= CFLAGS_SSE2="
146                                 ;;
147                 esac
148
149                 if ! verbose $CC misc/tools/conftest.c -o conftest; then
150                         msg ""
151                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
152                         msg "~~~~~~~~~~ COMPILER ~~~~~~~~~~"
153                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
154                         msg "~~~~~~~~~~~~~~_...._~~~~~~~~~~"
155                         msg "~~~~~~~~~~~,-'     \\\`-._~~~~~~"
156                         msg "~~~~~~~~~~/     --. ><  \\~~~~~"
157                         msg "~~~~~~~~~/      (*)> -<: \\~~~~"
158                         msg "~~~~~~~~~(     ^~-'  (*) )~~~~"
159                         msg "~~~~~~~~~\\        ^+-_/  |~~~~"
160                         msg "~~~~~~~~~~\\       {vvv}  |~~~~"
161                         msg "~~~~~~~~~~,\\    , {^^^},/~~~~~"
162                         msg "~~~~~~~~,/  \`---.....-'~~W~~~~"
163                         msg "~~~~~~,/   \\_____/_\\_W~~/~~~~~"
164                         msg "~~~~~/          /~~~\\__/~~~~~~"
165                         msg "~~~~/          /~~~~~~~~~~~~~~"
166                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
167                         msg "~~~~~~~ Y U NO COMPILE ~~~~~~~"
168                         msg "~~~~~~~~~~~~ CODE ~~~~~~~~~~~~"
169                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
170                         msg ""
171                         exit 1
172                 fi
173                 rm -f conftest
174
175                 verbose cd "$d0/d0_blind_id"
176                 if [ -z "$compiled0" ]; then
177                         # In doubt, compile.
178                         compiled0=true
179                 fi
180                 if $compiled0; then
181                         if ! [ -f Makefile ]; then
182                                 verbose sh autogen.sh
183                                 verbose ./configure
184                         fi
185                         if $cleand0; then
186                                 verbose $MAKE $MAKEFLAGS distclean
187                                 verbose sh autogen.sh
188                                 verbose ./configure
189                         fi
190                         verbose $MAKE $MAKEFLAGS
191                 fi
192
193                 verbose cd "$d0/gmqcc"
194                 if $cleanqcc; then
195                         verbose $MAKE $MAKEFLAGS clean
196                 fi
197                 if [ -n "$WE_HATE_OUR_USERS" ]; then
198                         verbose $MAKE $MAKEFLAGS gmqcc.exe
199                 else
200                         verbose $MAKE $MAKEFLAGS gmqcc
201                 fi
202
203                 if [ -n "$MSYSTEM" ]; then
204                         DATAMAKE=mingw32-make
205                 else
206                         DATAMAKE=$MAKE
207                 fi
208                 verbose cd "$d0/data/xonotic-data.pk3dir"
209                 if $cleanqc; then
210                         verbose ${DATAMAKE} QCC="../../../../gmqcc/gmqcc" "$@" $MAKEFLAGS clean
211                 fi
212                 verbose ${DATAMAKE} QCC="../../../../gmqcc/gmqcc" "$@" $MAKEFLAGS
213                 # 4 levels up: data, xonotic-data, qcsrc, server
214
215                 verbose cd "$d0/darkplaces"
216                 if [ x"$BAD_TARGETS" = x" " ]; then
217                         $ECHO "Warning: invalid empty client, default clients will be used."
218                 fi
219                 if $cleandp; then
220                         verbose $MAKE $MAKEFLAGS clean
221                 fi
222                 for T in $TARGETS; do
223                         verbose $MAKE $MAKEFLAGS STRIP=: "$@" "$T"
224                 done
225                 for T in $BAD_TARGETS; do
226                         $ECHO "Warning: discarded invalid client $T."
227                 done
228
229                 verbose "$SELF" update-maps
230                 ;;
231         run)
232                 if [ -n "$WE_HATE_OUR_USERS" ]; then
233                         case `uname -m` in
234                                 x86_64)
235                                         export PATH="$d0/misc/buildfiles/win64:$d0/d0_blind_id/.libs:$PATH"
236                                         ;;
237                                 *)
238                                         export PATH="$d0/misc/buildfiles/win32:$d0/d0_blind_id/.libs:$PATH"
239                                         ;;
240                         esac
241                 elif [ x"`uname`" = x"Darwin" ]; then
242                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS:$d0/d0_blind_id/.libs"
243                         export DYLD_FRAMEWORK_PATH="$d0/misc/buildfiles/osx/Xonotic.app/Contents/Frameworks"
244                 else
245                         export LD_LIBRARY_PATH="$d0/d0_blind_id/.libs${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
246                 fi
247
248                 client=-sdl
249                 USE_RLWRAP=no
250                 case "$1" in
251                         dedicated)
252                                 client=-$1
253                                 USE_RLWRAP=
254                                 shift
255                                 ;;
256                         sdl)
257                                 shift
258                                 ;;
259                 esac
260
261                 if ! [ -x "darkplaces/darkplaces$client" ]; then
262                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
263                                 client=$client.exe
264                         else
265                                 $ECHO "Client darkplaces/darkplaces$client not found, aborting"
266                                 exit 1
267                         fi
268                 fi
269                 set -- "darkplaces/darkplaces$client" -xonotic "$@"
270
271                 binary=$1
272
273                 if [ x"$USE_GDB" = x"yes" ]; then
274                         set -- gdb --args "$@"
275                         USE_RLWRAP=no
276                 elif [ x"$USE_GDB" = x"core" ]; then
277                         set -- gdb --batch -x savecore.gdb --args "$@"
278                         USE_RLWRAP=no
279                 elif which catchsegv >/dev/null 2>&1; then
280                         set -- catchsegv "$@"
281                 fi
282                 if [ x"$USE_RLWRAP" != x"no" ] && which rlwrap >/dev/null 2>&1; then
283                         set -- rlwrap -A -g '^quit' -q "\"" -s 10000 -S ']' -w 100 "$@"
284                 fi
285                 rm -f xonotic.core
286                 verbose measure_time "$@" || true
287                 if [ -f xonotic.core ]; then
288                         if yesno "The program has CRASHED. Do you want to examine the core dump?"; then
289                                 gdb "$binary" xonotic.core
290                         #elif yesno "You did not want to examine the core dump. Do you want to provide it - including your DarkPlaces checkout - to the Xonotic developers?"; then
291                         #       tar cvzf xonotic.core.tar.gz xonotic.core darkplaces/*.c darkplaces/*.h
292                         #       # somehow send it
293                         #       rm -f xonotic.core.tar.gz
294                         else
295                                 $ECHO "The core dump can be examined later by"
296                                 $ECHO "  gdb $binary xonotic.core"
297                         fi
298                         exit 1
299                 fi
300                 ;;
301         help)
302                 $ECHO "  $SELF compile [-c] [-qc] [-d|-p|-r] [-0] [-1] [sdl|dedicated]"
303                 $ECHO "  $SELF update-maps"
304                 $ECHO "  $SELF run [sdl|dedicated] options..."
305                 $ECHO "  $SELF compile-map mapname1 mapname2... (e.g. \"./all compile-map dance drain fuse\")"
306                 handled=false
307                 ;;
308         serverbench)
309                 # TODO(rpolzer): Why does :anticheat: output differ? Total game time differs? Why?
310                 trap "rm -rf .serverbench_temp" 0 1 2 3 11 13 15
311                 mkdir -p .serverbench_temp
312                 verbose "$SELF" run dedicated "$@" -noconfig -userdir .serverbench_temp +exec serverbench.cfg |\
313                         tee /dev/stderr |\
314                         grep '^:' |\
315                         grep -v '^:gamestart:' |\
316                         grep -v '^:anticheat:' |\
317                         md5sum
318                 ;;
319         *)
320                 handled=false
321                 ;;
322 esac