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