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