]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/all/xonotic.subr
Remove buildfiles: second copy of SDL for Mac specific to dev/git builds, and related...
[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                 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                 TARGETS="sv-$debug sdl-$debug"
90                 if [ x"`uname`" = x"Darwin" ]; then
91                         export CC="$CC -fno-reorder-blocks"
92                 fi
93
94                 if [ $# -gt 0 ] && [ x"$1" = x"" ]; then
95                         # if we give the command make the arg "", it will surely fail (invalid filename),
96                         # so better handle it as an empty client option
97                         BAD_TARGETS=" "
98                         shift
99                 elif [ -n "$1" ]; then
100                         BAD_TARGETS=
101                         TARGETS_SAVE=$TARGETS
102                         TARGETS=
103                         for X in $1; do
104                                 case "$X" in
105                                         sdl)
106                                                 TARGETS="$TARGETS sdl-$debug"
107                                                 ;;
108                                         dedicated)
109                                                 TARGETS="$TARGETS sv-$debug"
110                                                 ;;
111                                         *)
112                                                 BAD_TARGETS="$BAD_TARGETS $X"
113                                                 ;;
114                                 esac
115                         done
116                         if [ -n "$TARGETS" ]; then # at least a valid client
117                                 shift
118                         else # no valid client, let's assume this option is not meant to be a client then
119                                 TARGETS=$TARGETS_SAVE
120                                 BAD_TARGETS=
121                         fi
122                 fi
123
124                 if [ -z "$MAKE" ]; then
125                         MAKE=make
126                 fi
127
128                 if [ -z "$MAKEFLAGS" ]; then
129                         ncpus=`getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1`
130                         if [ $ncpus -gt 1 ]; then
131                                 MAKEFLAGS=-j$ncpus
132                         fi
133                         if [ -n "$WE_HATE_OUR_USERS" ]; then
134                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw"
135                         fi
136                 elif echo $MAKEFLAGS | head -c1 | grep -qv -; then # MAKEFLAGS starts with a single letter option
137                         MAKEFLAGS=-$(echo $MAKEFLAGS)                  # echo here and above will trim whitespaces
138                 fi
139
140                 # workaround ARM issue in DP's makefile.inc
141                 case `uname -m` in
142                         x86_64|*86)
143                                 ;;
144                         *)
145                                 MAKEFLAGS="$MAKEFLAGS CFLAGS_SSE= CFLAGS_SSE2="
146                                 ;;
147                 esac
148
149                 if ! verbose $CC misc/tools/conftest.c -o conftest; then
150                         msg ""
151                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
152                         msg "~~~~~~~~~~ COMPILER ~~~~~~~~~~"
153                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
154                         msg "~~~~~~~~~~~~~~_...._~~~~~~~~~~"
155                         msg "~~~~~~~~~~~,-'     \\\`-._~~~~~~"
156                         msg "~~~~~~~~~~/     --. ><  \\~~~~~"
157                         msg "~~~~~~~~~/      (*)> -<: \\~~~~"
158                         msg "~~~~~~~~~(     ^~-'  (*) )~~~~"
159                         msg "~~~~~~~~~\\        ^+-_/  |~~~~"
160                         msg "~~~~~~~~~~\\       {vvv}  |~~~~"
161                         msg "~~~~~~~~~~,\\    , {^^^},/~~~~~"
162                         msg "~~~~~~~~,/  \`---.....-'~~W~~~~"
163                         msg "~~~~~~,/   \\_____/_\\_W~~/~~~~~"
164                         msg "~~~~~/          /~~~\\__/~~~~~~"
165                         msg "~~~~/          /~~~~~~~~~~~~~~"
166                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
167                         msg "~~~~~~~ Y U NO COMPILE ~~~~~~~"
168                         msg "~~~~~~~~~~~~ CODE ~~~~~~~~~~~~"
169                         msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
170                         msg ""
171                         exit 1
172                 fi
173                 rm -f conftest
174
175                 verbose cd "$d0/d0_blind_id"
176                 if [ -z "$compiled0" ]; then
177                         # In doubt, compile.
178                         compiled0=true
179                 fi
180                 if $compiled0; then
181                         verbose sh autogen.sh
182                         verbose ./configure
183                         if $cleand0; then
184                                 verbose $MAKE $MAKEFLAGS distclean
185                         fi
186                         verbose $MAKE $MAKEFLAGS
187                 fi
188
189                 verbose cd "$d0/gmqcc"
190                 if $cleanqcc; then
191                         verbose $MAKE $MAKEFLAGS clean
192                 fi
193                 if [ -n "$WE_HATE_OUR_USERS" ]; then
194                         verbose $MAKE $MAKEFLAGS gmqcc.exe
195                 else
196                         verbose $MAKE $MAKEFLAGS gmqcc
197                 fi
198
199                 if [ -n "$MSYSTEM" ]; then
200                         DATAMAKE=mingw32-make
201                 else
202                         DATAMAKE=$MAKE
203                 fi
204                 verbose cd "$d0/data/xonotic-data.pk3dir"
205                 if $cleanqc; then
206                         verbose ${DATAMAKE} QCC="../../../../gmqcc/gmqcc" "$@" $MAKEFLAGS clean
207                 fi
208                 verbose ${DATAMAKE} QCC="../../../../gmqcc/gmqcc" "$@" $MAKEFLAGS
209                 # 4 levels up: data, xonotic-data, qcsrc, server
210
211                 verbose cd "$d0/darkplaces"
212                 if [ x"$BAD_TARGETS" = x" " ]; then
213                         $ECHO "Warning: invalid empty client, default clients will be used."
214                 fi
215                 if $cleandp; then
216                         verbose $MAKE $MAKEFLAGS clean
217                 fi
218                 for T in $TARGETS; do
219                         verbose $MAKE $MAKEFLAGS STRIP=: "$@" "$T"
220                 done
221                 for T in $BAD_TARGETS; do
222                         $ECHO "Warning: discarded invalid client $T."
223                 done
224
225                 verbose "$SELF" update-maps
226                 ;;
227         run)
228                 if [ -n "$WE_HATE_OUR_USERS" ]; then
229                         case `uname -m` in
230                                 x86_64)
231                                         export PATH="$d0/misc/buildfiles/win64:$d0/d0_blind_id/.libs:$PATH"
232                                         ;;
233                                 *)
234                                         export PATH="$d0/misc/buildfiles/win32:$d0/d0_blind_id/.libs:$PATH"
235                                         ;;
236                         esac
237                 elif [ x"`uname`" = x"Darwin" ]; then
238                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS:$d0/d0_blind_id/.libs"
239                         export DYLD_FRAMEWORK_PATH="$d0/misc/buildfiles/osx/Xonotic.app/Contents/Frameworks"
240                 else
241                         export LD_LIBRARY_PATH="$d0/d0_blind_id/.libs${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
242                 fi
243
244                 client=-sdl
245                 USE_RLWRAP=no
246                 case "$1" in
247                         dedicated)
248                                 client=-$1
249                                 USE_RLWRAP=
250                                 shift
251                                 ;;
252                         sdl)
253                                 shift
254                                 ;;
255                 esac
256
257                 if ! [ -x "darkplaces/darkplaces$client" ]; then
258                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
259                                 client=$client.exe
260                         else
261                                 $ECHO "Client darkplaces/darkplaces$client not found, aborting"
262                                 exit 1
263                         fi
264                 fi
265                 set -- "darkplaces/darkplaces$client" -xonotic "$@"
266
267                 binary=$1
268
269                 if [ x"$USE_GDB" = x"yes" ]; then
270                         set -- gdb --args "$@"
271                         USE_RLWRAP=no
272                 elif [ x"$USE_GDB" = x"core" ]; then
273                         set -- gdb --batch -x savecore.gdb --args "$@"
274                         USE_RLWRAP=no
275                 elif which catchsegv >/dev/null 2>&1; then
276                         set -- catchsegv "$@"
277                 fi
278                 if [ x"$USE_RLWRAP" != x"no" ] && which rlwrap >/dev/null 2>&1; then
279                         set -- rlwrap -A -g '^quit' -q "\"" -s 10000 -S ']' -w 100 "$@"
280                 fi
281                 rm -f xonotic.core
282                 verbose measure_time "$@" || true
283                 if [ -f xonotic.core ]; then
284                         if yesno "The program has CRASHED. Do you want to examine the core dump?"; then
285                                 gdb "$binary" xonotic.core
286                         #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
287                         #       tar cvzf xonotic.core.tar.gz xonotic.core darkplaces/*.c darkplaces/*.h
288                         #       # somehow send it
289                         #       rm -f xonotic.core.tar.gz
290                         else
291                                 $ECHO "The core dump can be examined later by"
292                                 $ECHO "  gdb $binary xonotic.core"
293                         fi
294                         exit 1
295                 fi
296                 ;;
297         help)
298                 $ECHO "  $SELF compile [-c] [-qc] [-d|-p|-r] [-0] [-1] [sdl|dedicated]"
299                 $ECHO "  $SELF update-maps"
300                 $ECHO "  $SELF run [sdl|dedicated] options..."
301                 $ECHO "  $SELF compile-map mapname1 mapname2... (e.g. \"./all compile-map dance drain fuse\")"
302                 handled=false
303                 ;;
304         serverbench)
305                 # TODO(rpolzer): Why does :anticheat: output differ? Total game time differs? Why?
306                 trap "rm -rf .serverbench_temp" 0 1 2 3 11 13 15
307                 mkdir -p .serverbench_temp
308                 verbose "$SELF" run dedicated "$@" -noconfig -userdir .serverbench_temp +exec serverbench.cfg |\
309                         tee /dev/stderr |\
310                         grep '^:' |\
311                         grep -v '^:gamestart:' |\
312                         grep -v '^:anticheat:' |\
313                         md5sum
314                 ;;
315         *)
316                 handled=false
317                 ;;
318 esac