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