]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/all/xonotic.subr
Improve serverbench command WRT #273 (fix)
[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/install/q3map2" ] ; then
12                         msg "q3map2 needed! Building netradiant..."
13                         make -C netradiant BUILD=native install/q3map2
14                 fi
15                 for mapfile in "$@"; do
16                         mapfile="data/xonotic-maps.pk3dir/maps/$mapfile.map"
17                         if [ ! -f "$mapfile" ] ; then
18                                 msg "ERROR, $mapfile not found!"
19                         else
20                                 verbose measure_time misc/tools/xonotic-map-compiler-optionsfile "$mapfile"
21                         fi
22                 done
23                 ;;
24         compile)
25                 cleand0=false
26                 cleandp=false
27                 cleanqcc=false
28                 cleanqc=false
29                 compiled0=
30                 debug=release  # when changing this default, change the description in the zsh autocompletion script
31                 if [ -z "$CC" ]; then
32                         export CC="gcc"
33                 fi
34                 export CC="$CC -DSUPPORTIPV6"
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                 if [ x"`uname`" = x"Darwin" ]; then
90                         TARGETS="sv-$debug sdl-$debug"
91                         export CC="$CC -fno-reorder-blocks"
92                 elif [ -n "$WE_HATE_OUR_USERS" ]; then
93                         TARGETS="sv-$debug sdl-$debug"
94                 else
95                         TARGETS="sv-$debug cl-$debug sdl-$debug"
96                 fi
97
98                 if [ $# -gt 0 ] && [ x"$1" = x"" ]; then
99                         # if we give the command make the arg "", it will surely fail (invalid filename),
100                         # so better handle it as an empty client option
101                         BAD_TARGETS=" "
102                         shift
103                 elif [ -n "$1" ]; then
104                         BAD_TARGETS=
105                         TARGETS_SAVE=$TARGETS
106                         TARGETS=
107                         for X in $1; do
108                                 case "$X" in
109                                         sdl)
110                                                 TARGETS="$TARGETS sdl-$debug"
111                                                 ;;
112                                         glx)
113                                                 TARGETS="$TARGETS cl-$debug"
114                                                 ;;
115                                         dedicated)
116                                                 TARGETS="$TARGETS sv-$debug"
117                                                 ;;
118                                         *)
119                                                 BAD_TARGETS="$BAD_TARGETS $X"
120                                                 ;;
121                                 esac
122                         done
123                         if [ -n "$TARGETS" ]; then # at least a valid client
124                                 shift
125                         else # no valid client, let's assume this option is not meant to be a client then
126                                 TARGETS=$TARGETS_SAVE
127                                 BAD_TARGETS=
128                         fi
129                 fi
130
131                 if [ -z "$MAKE" ]; then
132                         MAKE=make
133                 fi
134
135                 if [ -z "$MAKEFLAGS" ]; then
136                         ncpus=`getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1`
137                         if [ $ncpus -gt 1 ]; then
138                                 MAKEFLAGS=-j$ncpus
139                         fi
140                         if [ -n "$WE_HATE_OUR_USERS" ]; then
141                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw"
142                         fi
143                 fi
144
145                 if [ -n "$WE_HATE_OUR_USERS" ]; then
146                         # win32: use SDL2
147                         case `uname -m` in
148                                 x86_64)
149                                         MAKEFLAGS="$MAKEFLAGS SDL_CONFIG=$d0/misc/builddeps/win64/sdl/bin/sdl2-config"
150                                         ;;
151                                 *)
152                                         MAKEFLAGS="$MAKEFLAGS SDL_CONFIG=$d0/misc/builddeps/win32/sdl/bin/sdl2-config"
153                                         ;;
154                         esac
155
156                         # win32: don't rely on jpeg includes
157                         MAKEFLAGS="$MAKEFLAGS LIB_JPEG= CFLAGS_LIBJPEG="
158                 fi
159
160                 if [ x"`uname`" = x"Darwin" ]; then
161                         # osx: use SDL2
162                         f=$d0/misc/buildfiles/osx/Xonotic.app/Contents/Frameworks
163                         MAKEFLAGS="$MAKEFLAGS SDLCONFIG_MACOSXCFLAGS=-I$f/SDL2.framework/Headers SDLCONFIG_MACOSXLIBS=-F$f SDLCONFIG_MACOSXLIBS+=-framework SDLCONFIG_MACOSXLIBS+=SDL2 SDLCONFIG_MACOSXLIBS+=-framework SDLCONFIG_MACOSXLIBS+=Cocoa SDLCONFIG_MACOSXLIBS+=-I$f/SDL2.framework/Headers SDLCONFIG_MACOSXSTATICLIBS=-F$f SDLCONFIG_MACOSXSTATICLIBS+=-framework SDLCONFIG_MACOSXSTATICLIBS+=SDL2 SDLCONFIG_MACOSXSTATICLIBS+=-framework SDLCONFIG_MACOSXSTATICLIBS+=Cocoa SDLCONFIG_MACOSXSTATICLIBS+=-I$f/SDL2.framework/Headers"
164                 fi
165
166                 # workaround ARM issue in DP's makefile.inc
167                 case `uname -m` in
168                         x86_64|*86)
169                                 ;;
170                         *)
171                                 MAKEFLAGS="$MAKEFLAGS CFLAGS_SSE= CFLAGS_SSE2="
172                                 ;;
173                 esac
174
175                 if ! verbose $CC misc/tools/conftest.c -o conftest; then
176                         msg ""
177                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
178                         msg "~~~~~~~~~~ COMPILER ~~~~~~~~~~"
179                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
180                         msg "~~~~~~~~~~~~~~_...._~~~~~~~~~~"
181                         msg "~~~~~~~~~~~,-'     \\\`-._~~~~~~"
182                         msg "~~~~~~~~~~/     --. ><  \\~~~~~"
183                         msg "~~~~~~~~~/      (*)> -<: \\~~~~"
184                         msg "~~~~~~~~~(     ^~-'  (*) )~~~~"
185                         msg "~~~~~~~~~\\        ^+-_/  |~~~~"
186                         msg "~~~~~~~~~~\\       {vvv}  |~~~~"
187                         msg "~~~~~~~~~~,\\    , {^^^},/~~~~~"
188                         msg "~~~~~~~~,/  \`---.....-'~~W~~~~"
189                         msg "~~~~~~,/   \\_____/_\\_W~~/~~~~~"
190                         msg "~~~~~/          /~~~\\__/~~~~~~"
191                         msg "~~~~/          /~~~~~~~~~~~~~~"
192                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
193                         msg "~~~~~~~ Y U NO COMPILE ~~~~~~~"
194                         msg "~~~~~~~~~~~~ CODE ~~~~~~~~~~~~"
195                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
196                         msg ""
197                         exit 1
198                 fi
199                 rm -f conftest
200
201                 verbose cd "$d0/d0_blind_id"
202                 if [ -z "$compiled0" ]; then
203                         # In doubt, compile.
204                         compiled0=true
205
206                         # compilation of crypto library failed
207                         # use binaries then, if we can...
208                         mkdir -p .libs
209                         if [ -n "$WE_HATE_OUR_USERS" ]; then
210                                 case `uname -m` in
211                                         x86_64)
212                                                 verbose cp "$d0/misc/buildfiles/win64/libd0_blind_id"-* .libs/
213                                                 verbose cp "$d0/misc/buildfiles/win64/libd0_rijndael"-* .libs/
214                                                 verbose cp "$d0/misc/buildfiles/win64/libgmp"-* .libs/
215                                                 compiled0=false
216                                                 ;;
217                                         *)
218                                                 verbose cp "$d0/misc/buildfiles/win32/libd0_blind_id"-* .libs/
219                                                 verbose cp "$d0/misc/buildfiles/win32/libd0_rijndael"-* .libs/
220                                                 verbose cp "$d0/misc/buildfiles/win32/libgmp"-* .libs/
221                                                 compiled0=false
222                                                 ;;
223                                 esac
224                         else
225                                 case "`uname`" in
226                                         Linux)
227                                                 case `uname -m` in
228                                                         *86)
229                                                                 # No cp commands, we want to use static linking instead.
230                                                                 export CC="$CC -I../../../../misc/builddeps/linux32/d0_blind_id/include"
231                                                                 export CC="$CC -L../../../../misc/builddeps/linux32/d0_blind_id/lib"
232                                                                 export CC="$CC -Wl,-rpath,../../../../misc/builddeps/linux32/d0_blind_id/lib"
233                                                                 export CC="$CC -I../../../../misc/builddeps/linux32/gmp/include"
234                                                                 export CC="$CC -L../../../../misc/builddeps/linux32/gmp/lib"
235                                                                 export CC="$CC -Wl,-rpath,../../../../misc/builddeps/linux32/gmp/lib"
236                                                                 MAKEFLAGS="$MAKEFLAGS DP_LINK_CRYPTO=shared DP_LINK_CRYPTO_RIJNDAEL=shared LIB_CRYPTO=../../../../misc/builddeps/linux32/d0_blind_id/lib/libd0_blind_id.a LIB_CRYPTO+=../../../../misc/builddeps/linux32/gmp/lib/libgmp.a LIB_CRYPTO_RIJNDAEL=../../../../misc/builddeps/linux32/d0_blind_id/lib/libd0_rijndael.a"
237                                                                 compiled0=false
238                                                                 ;;
239                                                         *)
240                                                                 msg "Always need to compile libd0_blind_id on Linux `uname -m`."
241                                                                 ;;
242                                                 esac
243                                                 ;;
244                                         Darwin)
245                                                 verbose cp "$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS/libd0_blind_id".* .libs/
246                                                 verbose cp "$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS/libd0_rijndael".* .libs/
247                                                 compiled0=false
248                                                 ;;
249                                         *)
250                                                 msg "Always need to compile libd0_blind_id on `uname`."
251                                                 ;;
252                                 esac
253                         fi
254                 fi
255                 if $compiled0; then
256                         if $cleand0; then
257                                 if [ -f Makefile ]; then
258                                         verbose $MAKE $MAKEFLAGS distclean
259                                 fi
260                         fi
261                         if ! [ -f Makefile ]; then
262                                 verbose sh autogen.sh
263                                 verbose ./configure
264                         fi
265                         verbose $MAKE $MAKEFLAGS
266                 fi
267
268                 verbose cd "$d0/gmqcc"
269                 if $cleanqcc; then
270                         verbose $MAKE $MAKEFLAGS clean
271                 fi
272                 if [ -n "$WE_HATE_OUR_USERS" ]; then
273                         verbose $MAKE $MAKEFLAGS gmqcc.exe
274                 else
275                         verbose $MAKE $MAKEFLAGS gmqcc
276                 fi
277
278                 if [ -n "$MSYSTEM" ]; then
279                         DATAMAKE=mingw32-make
280                 else
281                         DATAMAKE=$MAKE
282                 fi
283                 verbose cd "$d0/data/xonotic-data.pk3dir"
284                 if $cleanqc; then
285                         verbose ${DATAMAKE} QCC="../../../../gmqcc/gmqcc" "$@" $MAKEFLAGS clean
286                 fi
287                 verbose ${DATAMAKE} QCC="../../../../gmqcc/gmqcc" "$@" $MAKEFLAGS
288                 # 4 levels up: data, xonotic-data, qcsrc, server
289
290                 verbose cd "$d0/darkplaces"
291                 if [ x"$BAD_TARGETS" = x" " ]; then
292                         $ECHO "Warning: invalid empty client, default clients will be used."
293                 fi
294                 if $cleandp; then
295                         verbose $MAKE $MAKEFLAGS clean
296                 fi
297                 for T in $TARGETS; do
298                         verbose $MAKE $MAKEFLAGS STRIP=: "$@" "$T"
299                 done
300                 for T in $BAD_TARGETS; do
301                         $ECHO "Warning: discarded invalid client $T."
302                 done
303
304                 verbose "$SELF" update-maps
305                 ;;
306         run)
307                 if [ -n "$WE_HATE_OUR_USERS" ]; then
308                         case `uname -m` in
309                                 x86_64)
310                                         export PATH="$d0/misc/buildfiles/win64:$d0/d0_blind_id/.libs:$PATH"
311                                         ;;
312                                 *)
313                                         export PATH="$d0/misc/buildfiles/win32:$d0/d0_blind_id/.libs:$PATH"
314                                         ;;
315                         esac
316                 elif [ x"`uname`" = x"Darwin" ]; then
317                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS:$d0/d0_blind_id/.libs"
318                         export DYLD_FRAMEWORK_PATH="$d0/misc/buildfiles/osx/Xonotic.app/Contents/Frameworks"
319                 else
320                         export LD_LIBRARY_PATH="$d0/d0_blind_id/.libs${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
321                 fi
322
323                 client=-sdl
324                 USE_RLWRAP=no
325                 case "$1" in
326                         dedicated)
327                                 client=-$1
328                                 USE_RLWRAP=
329                                 shift
330                                 ;;
331                         sdl)
332                                 shift
333                                 ;;
334                         glx)
335                                 client=-$1
336                                 shift
337                                 ;;
338                 esac
339
340                 if ! [ -x "darkplaces/darkplaces$client" ]; then
341                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
342                                 client=$client.exe
343                         else
344                                 $ECHO "Client darkplaces/darkplaces$client not found, aborting"
345                                 exit 1
346                         fi
347                 fi
348                 set -- "darkplaces/darkplaces$client" -xonotic "$@"
349
350                 # if pulseaudio is running: USE IT
351                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
352                         if ps -C pulseaudio >/dev/null; then
353                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
354                                         export SDL_AUDIODRIVER=pulse
355                                 fi
356                         fi
357                 fi
358
359                 binary=$1
360
361                 if [ x"$USE_GDB" = x"yes" ]; then
362                         set -- gdb --args "$@"
363                         USE_RLWRAP=no
364                 elif [ x"$USE_GDB" = x"core" ]; then
365                         set -- gdb --batch -x savecore.gdb --args "$@"
366                         USE_RLWRAP=no
367                 elif which catchsegv >/dev/null 2>&1; then
368                         set -- catchsegv "$@"
369                 fi
370                 if [ x"$USE_RLWRAP" != x"no" ] && which rlwrap >/dev/null 2>&1; then
371                         set -- rlwrap -A -g '^quit' -q "\"" -s 10000 -S ']' -w 100 "$@"
372                 fi
373                 rm -f xonotic.core
374                 verbose measure_time "$@" || true
375                 if [ -f xonotic.core ]; then
376                         if yesno "The program has CRASHED. Do you want to examine the core dump?"; then
377                                 gdb "$binary" xonotic.core
378                         #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
379                         #       tar cvzf xonotic.core.tar.gz xonotic.core darkplaces/*.c darkplaces/*.h
380                         #       # somehow send it
381                         #       rm -f xonotic.core.tar.gz
382                         else
383                                 $ECHO "The core dump can be examined later by"
384                                 $ECHO "  gdb $binary xonotic.core"
385                         fi
386                         exit 1
387                 fi
388                 ;;
389         help)
390                 $ECHO "  $SELF compile [-c] [-qc] [-d|-p|-r] [-0] [-1] [sdl|glx|dedicated]"
391                 $ECHO "  $SELF update-maps"
392                 $ECHO "  $SELF run [sdl|glx|dedicated] options..."
393                 $ECHO "  $SELF compile-map mapname1 mapname2... (e.g. \"./all compile-map dance drain fuse\")"
394                 handled=false
395                 ;;
396         serverbench)
397                 # TODO(rpolzer): Why does :anticheat: output differ? Total game time differs? Why?
398                 mkdir -p SERVERBENCH_TEMP
399                 verbose "$SELF" run dedicated -noconfig -userdir SERVERBENCH_TEMP +exec serverbench.cfg |\
400                         tee /dev/stderr |\
401                         grep '^:' |\
402                         grep -v '^:gamestart:' |\
403                         grep -v '^:anticheat:' |\
404                         md5sum
405                 rm -rf SERVERBENCH_TEMP
406                 ;;
407         *)
408                 handled=false
409                 ;;
410 esac