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