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