]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/all/xonotic.subr
error if map file can't be found.
[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                 mapfile="data/xonotic-maps.pk3dir/maps/$1.map"
8                 if [ ! -f "netradiant/install/q3map2.x86" ] ; then
9                         msg "q3map2 needed! Building netradiant..."
10                         cd netradiant
11                         make
12                         cd ../
13                 fi
14                 if [ ! -f "$mapfile" ] ; then
15                         msg "ERROR, $mapfile not found!"
16                         exit 2
17                 else
18                         time misc/tools/xonotic-map-compiler_from_all $mapfile
19                 fi
20                 ;;
21         compile)
22                 cleand0=false
23                 cleandp=false
24                 cleanqcc=false
25                 cleanqc=false
26                 compiled0=false
27                 debug=debug
28                 snowleopardhack=false
29                 if [ -z "$CC" ]; then
30                         export CC="gcc"
31                 fi
32                 export CC="$CC -DSUPPORTIPV6"
33                 while :; do
34                         case "$1" in
35                                 -0)
36                                         compiled0=true
37                                         shift
38                                         ;;
39                                 -c)
40                                         cleand0=true
41                                         cleandp=true
42                                         cleanqcc=true
43                                         cleanqc=true
44                                         shift
45                                         ;;
46                                 -r|-p)
47                                         case "$1" in
48                                                 -p)
49                                                         debug=profile
50                                                         ;;
51                                                 -r)
52                                                         debug=release
53                                                         ;;
54                                         esac
55                                         export CC="$CC -g"
56                                         case "`$CC -dumpversion`" in
57                                                 [5-9]*|[1-9][0-9]*|4.[3-9]*|4.[1-9][0-9]*)
58                                                         # gcc 4.3 or higher
59                                                         # -march=native is broken < 4.3
60                                                         if $CC -mtune=native -march=native misc/tools/conftest.c -o conftest >/dev/null 2>&1; then
61                                                                 export CC="$CC -mtune=native -march=native"
62                                                         fi
63                                                         ;;
64                                         esac
65                                         if [ -n "$WE_HATE_OUR_USERS" ]; then
66                                                 export CC="$CC -fno-common"
67                                         fi
68                                         shift
69                                         ;;
70                                 *)
71                                         break
72                                         ;;
73                         esac
74                 done
75                 if [ -n "$WE_HATE_OUR_USERS" ]; then
76                         TARGETS="sv-$debug cl-$debug"
77                 elif [ x"`uname`" = x"Darwin" ]; then
78                         case "`uname -r`" in
79                                 ?.*)
80                                         TARGETS="sv-$debug cl-$debug sdl-$debug"
81                                         ;;
82                                 *)
83                                         # AGL cannot be compiled on systems with a kernel > 10.x (Snow Leopard)
84                                         snowleopardhack=true
85                                         TARGETS="sv-$debug sdl-$debug"
86                                         ;;
87                         esac
88                         export CC="$CC -fno-reorder-blocks -I$PWD/misc/buildfiles/osx/Xonotic.app/Contents/Frameworks/SDL.framework/Headers -F$PWD/misc/buildfiles/osx/Xonotic.app/Contents/Frameworks"
89                 else
90                         TARGETS="sv-$debug cl-$debug sdl-$debug"
91                 fi
92                 if [ $# -gt 0 ] && [ x"$1" = x"" ]; then
93                         # if we give the command make the arg "", it will surely fail (invalid filename),
94                         # so better handle it as an empty client option
95                         BAD_TARGETS=" "
96                         shift
97                 elif [ -n "$1" ]; then
98                         BAD_TARGETS=
99                         TARGETS_SAVE=$TARGETS
100                         TARGETS=
101                         for X in $1; do
102                                 case "$X" in
103                                         sdl)
104                                                 TARGETS="$TARGETS sdl-$debug"
105                                                 ;;
106                                         agl)
107                                                 TARGETS="$TARGETS cl-$debug"
108                                                 if $snowleopardhack; then
109                                                         export CC="$CC -arch i386"
110                                                 fi
111                                                 ;;
112                                         glx|wgl)
113                                                 TARGETS="$TARGETS cl-$debug"
114                                                 ;;
115                                         dedicated)
116                                                 TARGETS="$TARGETS sv-$debug"
117                                                 ;;
118                                         *)
119                                                 BAD_TARGETS="$BAD_TARGETS $X"
120                                                 ;;
121                                 esac
122                         done
123                         if [ -n "$TARGETS" ]; then # at least a valid client
124                                 shift
125                         else # no valid client, let's assume this option is not meant to be a client then
126                                 TARGETS=$TARGETS_SAVE
127                                 BAD_TARGETS=
128                         fi
129                 fi
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 LIB_JPEG= CFLAGS_LIBJPEG="
137                         fi
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 ! $compiled0; then
177                         # compilation of crypto library failed
178                         # use binaries then, if we can...
179                         mkdir -p .libs
180                         if [ -n "$WE_HATE_OUR_USERS" ]; then
181                                 verbose cp "$d0/misc/buildfiles/win32/libd0_blind_id"-* .libs/
182                                 verbose cp "$d0/misc/buildfiles/win32/libd0_rijndael"-* .libs/
183                                 verbose cp "$d0/misc/buildfiles/win32/libgmp"-* .libs/
184                         else
185                                 case "`uname`" in
186                                         Linux)
187                                                 case `uname -m` in
188                                                         x86_64)
189                                                                 #verbose cp "$d0/misc/builddeps/dp.linux64/lib/libd0_blind_id".* .libs/
190                                                                 #verbose cp "$d0/misc/builddeps/dp.linux64/lib/libd0_rijndael".* .libs/
191                                                                 #verbose cp "$d0/misc/builddeps/dp.linux64/lib/libgmp".* .libs/
192                                                                 MAKEFLAGS="$MAKEFLAGS DP_CRYPTO_STATIC_LIBDIR=../misc/builddeps/dp.linux64/lib/ DP_CRYPTO_RIJNDAEL_STATIC_LIBDIR=../misc/builddeps/dp.linux64/lib/ DP_GMP_STATIC_LIBDIR=../misc/builddeps/dp.linux64/lib/"
193                                                                 ;;
194                                                         *86)
195                                                                 #verbose cp "$d0/misc/builddeps/dp.linux32/lib/libd0_blind_id".* .libs/
196                                                                 #verbose cp "$d0/misc/builddeps/dp.linux32/lib/libd0_rijndael".* .libs/
197                                                                 #verbose cp "$d0/misc/builddeps/dp.linux32/lib/libgmp".* .libs/
198                                                                 MAKEFLAGS="$MAKEFLAGS DP_CRYPTO_STATIC_LIBDIR=../misc/builddeps/dp.linux32/lib/ DP_CRYPTO_RIJNDAEL_STATIC_LIBDIR=../misc/builddeps/dp.linux32/lib/ DP_GMP_STATIC_LIBDIR=../misc/builddeps/dp.linux32/lib/"
199                                                                 ;;
200                                                         *)
201                                                                 compiled0=true
202                                                                 ;;
203                                                 esac
204                                                 ;;
205                                         Darwin)
206                                                 verbose cp "$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS/libd0_blind_id".* .libs/
207                                                 verbose cp "$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS/libd0_rijndael".* .libs/
208                                                 ;;
209                                         *)
210                                                 compiled0=true
211                                                 ;;
212                                 esac
213                         fi
214                 fi
215                 if $compiled0; then
216                         if $cleand0; then
217                                 if [ -f Makefile ]; then
218                                         verbose make $MAKEFLAGS distclean
219                                 fi
220                         fi
221                         if ! [ -f Makefile ]; then
222                                 verbose sh autogen.sh
223                                 verbose ./configure
224                         fi
225                         verbose make $MAKEFLAGS
226                 fi
227
228                 verbose cd "$d0/gmqcc"
229                 if $cleanqcc; then
230                         verbose make $MAKEFLAGS clean
231                 fi
232                 if [ -n "$WE_HATE_OUR_USERS" ]; then
233                         verbose make $MAKEFLAGS gmqcc.exe
234                 else
235                         verbose make $MAKEFLAGS gmqcc
236                 fi
237
238                 verbose cd "$d0/data/xonotic-data.pk3dir"
239                 if $cleanqc; then
240                         verbose make QCC="../../../../gmqcc/gmqcc" "$@" $MAKEFLAGS clean
241                 fi
242                 verbose make QCC="../../../../gmqcc/gmqcc" "$@" $MAKEFLAGS
243                 # 4 levels up: data, xonotic-data, qcsrc, server
244
245                 verbose cd "$d0/darkplaces"
246                 if [ x"$BAD_TARGETS" = x" " ]; then
247                         $ECHO "Warning: invalid empty client, default clients will be used."
248                 fi
249                 if $cleandp; then
250                         verbose make $MAKEFLAGS clean
251                 fi
252                 for T in $TARGETS; do
253                         verbose make $MAKEFLAGS STRIP=: "$@" "$T"
254                 done
255                 for T in $BAD_TARGETS; do
256                         $ECHO "Warning: discarded invalid client $T."
257                 done
258
259                 verbose "$SELF" update-maps
260                 ;;
261         run)
262                 if [ -n "$WE_HATE_OUR_USERS" ]; then
263                         client=
264                         export PATH="$d0/misc/buildfiles/win32:$d0/d0_blind_id/.libs:$PATH"
265                 elif [ x"`uname`" = x"Darwin" ]; then
266                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS:$d0/d0_blind_id/.libs"
267                         export DYLD_FRAMEWORK_PATH="$d0/misc/buildfiles/osx/Xonotic.app/Contents/Frameworks"
268                         client=-sdl
269                 else
270                         export LD_LIBRARY_PATH="$d0/d0_blind_id/.libs"
271                         client=-sdl
272                 fi
273                 case "$1" in
274                         dedicated)
275                                 client=-$1
276                                 shift
277                                 ;;
278                         sdl|glx|agl)
279                                 USE_RLWRAP=no
280                                 client=-$1
281                                 shift
282                                 ;;
283                         wgl)
284                                 USE_RLWRAP=no
285                                 client=
286                                 shift
287                                 ;;
288                 esac
289                 if ! [ -x "darkplaces/darkplaces$client" ]; then
290                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
291                                 client=$client.exe
292                         else
293                                 $ECHO "Client darkplaces/darkplaces$client not found, aborting"
294                                 exit 1
295                         fi
296                 fi
297                 set -- "darkplaces/darkplaces$client" -xonotic "$@"
298
299                 # if pulseaudio is running: USE IT
300                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
301                         if ps -C pulseaudio >/dev/null; then
302                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
303                                         export SDL_AUDIODRIVER=pulse
304                                 fi
305                         fi
306                 fi
307
308                 binary=$1
309
310                 if [ x"$USE_GDB" = x"yes" ]; then
311                         set -- gdb --args "$@"
312                         USE_RLWRAP=no
313                 elif [ x"$USE_GDB" = x"core" ]; then
314                         set -- gdb --batch -x savecore.gdb --args "$@"
315                         USE_RLWRAP=no
316                 elif which catchsegv >/dev/null 2>&1; then
317                         set -- catchsegv "$@"
318                 fi
319                 if [ x"$USE_RLWRAP" != x"no" ] && which rlwrap >/dev/null 2>&1; then
320                         set -- rlwrap -A -g '^quit' -q "\"" -r -S ']' -w 100 "$@"
321                 fi
322                 rm -f xonotic.core
323                 "$@" || true
324                 if [ -f xonotic.core ]; then
325                         if yesno "The program has CRASHED. Do you want to examine the core dump?"; then
326                                 gdb "$binary" xonotic.core
327                         #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
328                         #       tar cvzf xonotic.core.tar.gz xonotic.core darkplaces/*.c darkplaces/*.h
329                         #       # somehow send it
330                         #       rm -f xonotic.core.tar.gz
331                         else
332                                 $ECHO "The core dump can be examined later by"
333                                 $ECHO "  gdb $binary xonotic.core"
334                         fi
335                         exit 1
336                 fi
337                 ;;
338         help)
339                 $ECHO "  $SELF compile [-c] [-r|-p] [-0] [sdl|glx|wgl|agl|dedicated]"
340                 $ECHO "  $SELF update-maps"
341                 $ECHO "  $SELF run [sdl|glx|wgl|agl|dedicated] options..."
342                 handled=false
343                 ;;
344         *)
345                 handled=false
346                 ;;
347 esac