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