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