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