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