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