don't return "bad" exit code
[xonotic/xonotic.git] / all
1 #!/bin/sh
2 # vim: filetype=zsh
3
4 set -e
5
6 # I use this in EVERY shell script ;)
7 LF="
8 "
9
10 d00=`pwd`
11 while ! [ -f ./all ]; do
12         if [ x"`pwd`" = x"/" ]; then
13                 echo "Cannot find myself."
14                 echo "Please run this script with the working directory inside a Xonotic checkout."
15                 exit 1
16         fi
17         cd ..
18 done
19 export d0=`pwd`
20 SELF="$d0/all"
21
22 # If we are on WINDOWS:
23 case "$0" in
24         all|*/all)
25                 case "`uname`" in
26                         MINGW*|Win*)
27                                 # Windows hates users. So this script has to copy itself elsewhere first...
28                                 cp "$SELF" ../all.xonotic.sh
29                                 export WE_HATE_OUR_USERS=1
30                                 exec ../all.xonotic.sh "$@"
31                                 ;;
32                 esac
33                 ;;
34 esac
35
36 msg()
37 {
38         echo >&2 "\e[1m$*\e[m"
39 }
40
41 self=`git hash-object "$SELF"`
42 checkself()
43 {
44         self_new=`git hash-object "$SELF"`
45         if [ x"$self" != x"$self_new" ]; then
46                 msg "./all has changed."
47                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
48                         msg "Rerunning the requested operation to make sure."
49                         export XONOTIC_FORBID_RERUN_ALL=1
50                         exec "$SELF" "$@"
51                 else
52                         msg "Please try $SELF update, and then retry your requested operation."
53                         exit 1
54                 fi
55         fi
56         return 0
57 }
58
59 verbose()
60 {
61         msg "+ $*"
62         "$@"
63 }
64
65 visible_repo_name()
66 {
67         case "$1" in
68                 .)
69                         echo "the root directory"
70                         ;;
71                 *)
72                         echo "\"$1\""
73                         ;;
74         esac
75 }
76
77 check_mergeconflict()
78 {
79         if git ls-files -u | grep ' 1   '; then
80                 echo
81                 echo "MERGE CONFLICT."
82                 echo "change into the \"$1\" project directory, and then:"
83                 echo "- edit the files mentioned above with your favorite editor,"
84                 echo "  and fix the conflicts (marked with <<<<<<< blocks)"
85                 echo "- for binary files, you can select the files using"
86                 echo "  git checkout --ours or git checkout --theirs"
87                 echo "- when done with a file, 'git add' the file"
88                 echo "- when done, 'git commit'"
89                 echo
90                 exit 1
91         fi
92 }
93
94 yesno()
95 {
96         yesno=
97         while [ x"$yesno" != x"y" -a x"$yesno" != x"n" ]; do
98                 eval "$2"
99                 echo "$1"
100                 IFS= read -r yesno
101         done
102         [ x"$yesno" = x"y" ]
103 }
104
105 enter()
106 {
107         $2 cd "$1" || exit 1
108         check_mergeconflict "$1"
109 }
110
111 repos_urls="
112 .                             |                                                   | master      |
113 data/xonotic-data.pk3dir      |                                                   | master      |
114 data/xonotic-music.pk3dir     |                                                   | master      |
115 data/xonotic-nexcompat.pk3dir |                                                   | master      | no
116 darkplaces                    |                                                   | div0-stable | svn
117 netradiant                    |                                                   | master      |
118 div0-gittools                 |                                                   | master      | no
119 data/xonotic-maps.pk3dir      |                                                   | master      |
120 mediasource                   |                                                   | master      | no
121 fteqcc                        | http://github.com/Blub/qclib.git                  | master      |
122 "
123 # todo: in darkplaces, change repobranch to div0-stable
124
125 repos=`echo "$repos_urls" | grep . | cut -d '|' -f 1 | tr -d ' '`
126
127 base=`git config remote.origin.url`
128 case "$base" in
129         */xonotic.git)
130                 base=${base%xonotic.git}
131                 ;;
132         *)
133                 echo "The main repo is not xonotic.git, what have you done?"
134                 exit 1
135                 ;;
136 esac
137
138 repourl()
139 {
140         repo_t=`echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 2 | tr -d ' '`
141         if [ -n "$repo_t" ]; then
142                 case "$repo_t" in
143                         *://*)
144                                 echo "$repo_t"
145                                 ;;
146                         *)
147                                 echo "$base$repo_t"
148                                 ;;
149                 esac
150         else
151                 if [ x"$1" = x"." ]; then
152                         echo "$base""xonotic.git"
153                 else
154                         echo "$base${1##*/}.git"
155                 fi
156         fi
157 }
158
159 repobranch()
160 {
161         repo_t=`echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 3 | tr -d ' '`
162         if [ -n "$repo_t" ]; then
163                 echo "$repo_t"
164         else
165                 echo "master"
166         fi
167 }
168
169 repoflags()
170 {
171         echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 4 | tr -d ' '
172 }
173
174 listrepos()
175 {
176         for d in $repos; do
177                 p="${d%dir}"
178                 f="`repoflags "$d"`"
179                 # if we have the dir, always keep it
180                 if [ -d "$d" ]; then
181                         msg "Repository $d enabled because it already exists"
182                         echo "$d"
183                         continue
184                 fi
185                 # if .yes file exists, always keep it
186                 if [ -f "$d.yes" ]; then
187                         msg "Repository $d enabled by a .yes file"
188                         echo "$d"
189                         continue
190                 fi
191                 # if we have .no file, skip
192                 if [ -f "$d.no" ]; then
193                         msg "Repository $d disabled by a .no file, delete $p.no to enable"
194                         continue
195                 fi
196                 # if we have matching pk3, skip
197                 if [ x"$p" != x"$d" ] && [ -f "$p" ]; then
198                         msg "Repository $d disabled by matching .pk3 file, delete $p or create $d.yes to enable"
199                         continue
200                 fi
201                 # if "no" flag is set, skip
202                 case ",$f," in
203                         *,no,*)
204                                 msg "Repository $d disabled by default, create $d.yes to enable"
205                                 continue
206                                 ;;
207                 esac
208                 # default: enable
209                 msg "Repository $d enabled by default"
210                 echo "$d"
211         done
212 }
213
214 repos=`listrepos`
215
216 if [ "$#" = 0 ]; then
217         set -- help
218 fi
219 cmd=$1
220 shift
221
222 fix_upstream_rebase()
223 {
224         if [ -z "$r_me" ] || [ -z "$r_other" ]; then
225                 return
226         fi
227         r_base=`git merge-base "$r_me" "$r_other"`
228
229         # no merge-base? upstream did filter-branch
230         if [ -n "$r_base" ]; then
231                 # otherwise, check if the two histories are "similar"
232                 r_l_me=`git log --pretty="format:%s" "$r_other".."$r_me" | grep -v "^Merge" | sort -u`
233                 r_l_other=`git log --pretty="format:%s" "$r_me".."$r_other" | grep -v "^Merge" | sort -u`
234
235                 # heuristics: upstream rebase/filter-branch if more than 50% of the commits of one of the sides are in the other too
236                 r_lc_me=`echo "$r_l_me" | wc -l`
237                 r_lc_other=`echo "$r_l_other" | wc -l`
238                 r_lc_together=`{ echo "$r_l_me"; echo "$r_l_other"; } | sort -u | wc -l`
239                 r_lc_same=$(($r_lc_me + $r_lc_other - $r_lc_together))
240
241                 if [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_me )) ] || [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_other )) ]; then
242                         if yesno "Probable upstream rebase detected, automatically fix?" 'git log --oneline --graph --date-order --left-right "$r_other"..."$r_me"'; then
243                                 git reset --hard "$r_me"
244                                 git pull --rebase
245                                 return 1
246                         fi
247                 fi
248         fi
249
250         return 0
251 }
252
253 fix_upstream_rebase_mergeok()
254 {
255         r_me=`git rev-parse --revs-only HEAD^1 2>/dev/null || true`
256         r_other=`git rev-parse --revs-only HEAD^2 2>/dev/null || true`
257         fix_upstream_rebase
258 }
259
260 fix_upstream_rebase_mergefail()
261 {
262         r_me=`git rev-parse --revs-only HEAD 2>/dev/null || true`
263         r_other=`git rev-parse --revs-only MERGE_HEAD 2>/dev/null || true`
264         fix_upstream_rebase
265 }
266
267 fix_git_config()
268 {
269         verbose git config core.autocrlf input
270         if [ -z "`git config push.default`" ]; then
271                 verbose git config push.default current # or is tracking better?
272         fi
273 }
274
275 mkzip()
276 {
277         archive=$1
278         shift
279         ziplist=`mktemp`
280         find "$@" -xtype f \( -executable -or -type l \) -print > "$ziplist"
281         7za a -tzip -mx=9 -x@"$ziplist" "$archive" "$@" || true
282         zip         -9y   -@<"$ziplist" "$archive"      || true
283         rm -f "$ziplist"
284 }
285
286 mkzip0()
287 {
288         zip -0y "$@"
289 }
290
291 case "$cmd" in
292         fix_upstream_rebase)
293                 for d in $repos; do
294                         enter "$d0/$d" verbose
295                         verbose fix_upstream_rebase_mergefail && verbose fix_upstream_rebase_mergeok
296                 done
297                 ;;
298         update|pull)
299                 allow_pull=true
300                 if [ x"$1" = x"-N" ]; then
301                         allow_pull=false
302                 fi
303                 for d in $repos; do
304                         url=`repourl "$d"`
305                         branch=`repobranch "$d"`
306                         if [ -d "$d0/$d" ]; then
307                                 if $allow_pull; then
308                                         enter "$d0/$d" verbose
309                                         fix_git_config
310                                         verbose git config remote.origin.url "$url"
311                                         verbose git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
312                                         r=`git symbolic-ref HEAD`
313                                         r=${r#refs/heads/}
314                                         if git config branch.$r.remote >/dev/null 2>&1; then
315                                                 if ! verbose git pull; then
316                                                         fix_upstream_rebase_mergefail || true
317                                                         check_mergeconflict "$d"
318                                                         echo "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
319                                                         read -r DUMMY
320                                                 else
321                                                         fix_upstream_rebase_mergeok || true
322                                                 fi
323                                         fi
324
325                                         cd "$d00"
326                                         checkself "$cmd" "$@"
327                                         cd "$d0/$d"
328                                         verbose git remote prune origin
329                                         cd "$d0"
330                                 fi
331                         else
332                                 verbose git clone "$url" "$d0/$d"
333                                 enter "$d0/$d" verbose
334                                 fix_git_config
335                                 if [ "$branch" != "master" ]; then
336                                         verbose git checkout --track -b "$branch" origin/"$branch"
337                                 fi
338                                 cd "$d0"
339                         fi
340                 done
341                 ;;
342         update-maps)
343                 misc/tools/xonotic-map-compiler-autobuild download
344                 ;;
345         checkout|switch)
346                 checkoutflags=
347                 if [ x"$1" = x"-f" ]; then
348                         checkoutflags=-f
349                         shift
350                 fi
351                 remote=$1
352                 branch=$2
353                 if [ -z "$branch" ]; then
354                         case "$remote" in
355                                 origin/*)
356                                         branch=${remote#origin/}
357                                         remote=origin
358                                         ;;
359                                 *)
360                                         branch=$remote
361                                         remote=origin
362                                         ;;
363                         esac
364                 fi
365                 exists=false
366                 for d in $repos; do
367                         enter "$d0/$d" verbose
368                         b=$branch
369                         if [ -n "$b" ] && git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
370                                 exists=true
371                                 verbose git checkout $checkoutflags "$b"
372                         elif [ -n "$b" ] && git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
373                                 exists=true
374                                 verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
375                         else
376                                 b=`repobranch "$d"`
377                                 if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
378                                         exists=true
379                                         verbose git checkout $checkoutflags "$b"
380                                 elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
381                                         exists=true
382                                         verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
383                                 else
384                                         echo "WTF? Not even branch $b doesn't exist in $d"
385                                         exit 1
386                                 fi
387                         fi
388                         cd "$d00"
389                         checkself "$cmd" "$@"
390                         cd "$d0"
391                 done
392                 if ! $exists; then
393                         echo "The requested branch was not found in any repository."
394                 fi
395                 exec "$SELF" branch
396                 ;;
397         branch)
398                 remote=$1
399                 branch=$2
400                 srcbranch=$3
401                 if [ -z "$branch" ]; then
402                         branch=$remote
403                         remote=origin
404                 fi
405                 if [ -z "$branch" ]; then
406                         for d in $repos; do
407                                 enter "$d0/$d"
408                                 r=`git symbolic-ref HEAD`
409                                 r=${r#refs/heads/}
410                                 echo "$d is at $r"
411                                 cd "$d0"
412                         done
413                 else
414                         for d in $repos; do
415                                 dv=`visible_repo_name "$d"`
416                                 enter "$d0/$d" verbose
417                                 if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
418                                         echo "Already having this branch in $dv."
419                                 else
420                                         if yesno "Branch in $dv?"; then
421                                                 if [ -n "$srcbranch" ]; then
422                                                         b=$srcbranch
423                                                 else
424                                                         b=origin/"`repobranch "$d"`"
425                                                         verbose git fetch origin || true
426                                                 fi
427                                                 # TODO do this without pushing
428                                                 verbose git checkout -b "$branch" "$b"
429                                                 verbose git config "branch.$branch.remote" "$remote"
430                                                 verbose git config "branch.$branch.merge" "refs/heads/$branch"
431                                         fi
432                                 fi
433                                 cd "$d0"
434                         done
435                         "$SELF" branch
436                 fi
437                 ;;
438         branches)
439                 for d in $repos; do
440                         cd "$d0/$d" # am in a pipe, shouldn't use enter
441                         git branch -r -v -v | cut -c 3- | sed "s/^(no branch)/(no_branch)/" | sed "s,^,$d ,"
442                         cd "$d0"
443                 done | {
444                         branches_list=
445                         # branches_repos_*=
446                         while read -r d BRANCH REV TEXT; do
447                                 if [ x"$BRANCH" = x"`repobranch "$d"`" ]; then
448                                         continue
449                                 fi
450                                 if [ x"$REV" = x"->" ]; then
451                                         continue
452                                 fi
453                                 BRANCH=${BRANCH#remotes/}
454                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
455                                 branches_list="$branches_list $BRANCH" # TEH SORT MAKEZ IT UNIEQ
456                                 eval "r=\$branches_repos_$ID"
457                                 r="$r $d"
458                                 eval "branches_repos_$ID=\$r"
459                         done
460                         echo -n "$branches_list" | xargs -n 1 echo | sort -u | while IFS= read -r BRANCH; do
461                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
462                                 eval "r=\$branches_repos_$ID"
463                                 printf "%-60s %s\n" "$BRANCH" "$r"
464                                 #echo "$BRANCH: $r"
465                         done
466                 }
467                 ;;
468         merge)
469                 for d in $repos; do
470                         dv=`visible_repo_name "$d"`
471                         enter "$d0/$d" verbose
472                         r=`git symbolic-ref HEAD`
473                         r=${r#refs/heads/}
474                         if git log HEAD..origin/"`repobranch "$d"`" | grep .; then
475                                 # we have uncommitted changes
476                                 if yesno "Could merge from \"`repobranch "$d"`\" into \"$r\" in $dv. Do it?"; then
477                                         if ! verbose git merge origin/"`repobranch "$d"`"; then
478                                                 check_mergeconflict "$d"
479                                                 exit 1 # this should ALWAYS be fatal
480                                         fi
481                                 fi
482                         fi
483                         cd "$d0"
484                 done
485                 ;;
486         push|commit)
487                 submit=$1
488                 for d in $repos; do
489                         dv=`visible_repo_name "$d"`
490                         enter "$d0/$d" verbose
491                         r=`git symbolic-ref HEAD`
492                         r=${r#refs/heads/}
493                         diffdata=`git diff --color HEAD`
494                         if [ -n "$diffdata" ]; then
495                                 # we have uncommitted changes
496                                 if yesno "Uncommitted changes in \"$r\" in $dv. Commit?" 'echo "$diffdata" | less -r'; then
497                                         verbose git commit -a
498                                 fi
499                         fi
500                         rem=`git config "branch.$r.remote" || echo origin`
501                         bra=`git config "branch.$r.merge" || echo "$r"`
502                         upstream="$rem/${bra#refs/heads/}"
503                         if ! git rev-parse "$upstream" >/dev/null 2>&1; then
504                                 upstream="origin/`repobranch "$d"`"
505                         fi
506                         logdata=`git log --color "$upstream".."$r"`
507                         if [ -n "$logdata" ]; then
508                                 if yesno "Push \"$r\" in $dv?" 'echo "$logdata" | less -r'; then
509                                         verbose git push "$rem" HEAD
510                                 fi
511                         fi
512                         if [ x"$submit" = x"-s" ]; then
513                                 case "$r" in
514                                         */*)
515                                                 verbose git push "$rem" HEAD:"${bra%%/*}/finished/${bra#*/}"
516                                                 ;;
517                                 esac
518                         fi
519                         cd "$d0"
520                 done
521                 ;;
522         compile)
523                 if [ -n "$WE_HATE_OUR_USERS" ]; then
524                         TARGETS="sv-debug cl-debug"
525                         if [ -z "$CC" ]; then
526                                 export CC=gcc
527                         fi
528                 elif [ x"`uname`" = x"Darwin" ]; then
529                         case "`uname -r`" in
530                                 ?.*)
531                                         TARGETS="sv-debug cl-debug sdl-debug"
532                                         ;;
533                                 *)
534                                         # AGL cannot be compiled on systems with a kernel > 10.x (Snow Leopard)
535                                         TARGETS="sv-debug sdl-debug"
536                                         ;;
537                         esac
538                         export CC="gcc -I$PWD/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks/SDL.framework/Headers -F$PWD/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks"
539                 else
540                         TARGETS="sv-debug cl-debug sdl-debug"
541                 fi
542                 case "$1" in
543                         -c)
544                                 cleandp=true
545                                 cleanqcc=true
546                                 cleanqc=true
547                                 shift
548                                 ;;
549                         *)
550                                 cleandp=false
551                                 cleanqcc=false
552                                 cleanqc=false
553                                 ;;
554                 esac
555                 if [ $# -gt 0 ] && [ x"$1" = x"" ]; then
556                         # if we give the command make the arg "", it will surely fail (invalid filename),
557                         # so better handle it as an empty client option
558                         BAD_TARGETS=" "
559                         shift
560                 elif [ -n "$1" ]; then
561                         BAD_TARGETS=
562                         TARGETS_SAVE=$TARGETS
563                         TARGETS=
564                         for X in $1; do
565                                 case "$X" in
566                                         sdl)
567                                                 TARGETS="$TARGETS sdl-debug"
568                                                 ;;
569                                         glx|agl|wgl)
570                                                 TARGETS="$TARGETS cl-debug"
571                                                 ;;
572                                         dedicated)
573                                                 TARGETS="$TARGETS sv-debug"
574                                                 ;;
575                                         *)
576                                                 BAD_TARGETS="$BAD_TARGETS $X"
577                                                 ;;
578                                 esac
579                         done
580                         if [ -n "$TARGETS" ]; then # at least a valid client
581                                 shift
582                         else # no valid client, let's assume this option is not meant to be a client then
583                                 TARGETS=$TARGETS_SAVE
584                                 BAD_TARGETS=
585                         fi
586                 fi
587                 if [ -z "$MAKEFLAGS" ]; then
588                         if [ -f /proc/cpuinfo ]; then
589                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
590                                 if [ $ncpus -gt 1 ]; then
591                                         MAKEFLAGS=-j$ncpus
592                                 fi
593                         fi
594                         if [ -n "$WE_HATE_OUR_USERS" ]; then
595                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw LIB_JPEG= CFLAGS_LIBJPEG="
596                         fi
597                 fi
598
599                 enter "$d0/fteqcc" verbose
600                 if $cleanqcc; then
601                         verbose make $MAKEFLAGS clean
602                 fi
603                 verbose make $MAKEFLAGS
604
605                 enter "$d0/data/xonotic-data.pk3dir" verbose
606                 if $cleanqc; then
607                         verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS clean
608                 fi
609                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS
610
611                 enter "$d0/darkplaces" verbose
612                 if [ x"$BAD_TARGETS" = x" " ]; then
613                         echo "Warning: invalid empty client, default clients will be used."
614                 fi
615                 if $cleandp; then
616                         verbose make $MAKEFLAGS clean
617                 fi
618                 for T in $TARGETS; do
619                         verbose make $MAKEFLAGS "$@" "$T"
620                 done
621                 for T in $BAD_TARGETS; do
622                         echo "Warning: discarded invalid client $T."
623                 done
624
625                 verbose "$SELF" update-maps
626                 ;;
627         run)
628                 if [ -n "$WE_HATE_OUR_USERS" ]; then
629                         client=
630                         export PATH="$d0/misc/buildfiles/win32:$PATH"
631                 elif [ x"`uname`" = x"Darwin" ]; then
632                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/MacOS"
633                         export DYLD_FRAMEWORK_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks"
634                         client=-sdl
635                 else
636                         client=-sdl
637                 fi
638                 case "$1" in
639                         sdl|glx|agl|dedicated)
640                                 client=-$1
641                                 shift
642                                 ;;
643                         wgl)
644                                 client=
645                                 shift
646                                 ;;
647                 esac
648                 if ! [ -x "darkplaces/darkplaces$client" ]; then
649                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
650                                 client=$client.exe
651                         else
652                                 echo "Client darkplaces/darkplaces$client not found, aborting"
653                                 exit 1
654                         fi
655                 fi
656                 set -- "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic -mygames "$@"
657                 # change this to:
658                 #set -- "darkplaces/darkplaces$client" -xonotic -mygames "$@"
659
660                 # if pulseaudio is running: USE IT
661                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
662                         if ps -C pulseaudio >/dev/null; then
663                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
664                                         export SDL_AUDIODRIVER=pulse
665                                 fi
666                         fi
667                 fi
668
669                 binary=$1
670
671                 if [ -n "$USE_GDB" ]; then
672                         set -- gdb --args "$@"
673                 elif which gdb >/dev/null 2>&1; then
674                         set -- gdb --batch -x savecore.gdb --args "$@"
675                 elif which catchsegv >/dev/null 2>&1; then
676                         set -- catchsegv "$@"
677                 fi
678                 rm -f xonotic.core
679                 "$@" || true
680                 if [ -f xonotic.core ]; then
681                         if yesno "The program has CRASHED. Do you want to examine the core dump?"; then
682                                 gdb "$binary" xonotic.core
683                         #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
684                         #       tar cvzf xonotic.core.tar.gz xonotic.core darkplaces/*.c darkplaces/*.h
685                         #       # somehow send it
686                         #       rm -f xonotic.core.tar.gz
687                         else
688                                 echo "The core dump can be examined later by"
689                                 echo "  gdb $binary xonotic.core"
690                         fi
691                 fi
692                 ;;
693         each|foreach)
694                 keep_going=false
695                 if [ x"$1" = x"-k" ]; then
696                         keep_going=true
697                         shift
698                 fi
699                 for d in $repos; do
700                         if verbose cd "$d0/$d"; then
701                                 if $keep_going; then
702                                         verbose "$@" || true
703                                 else
704                                         verbose "$@"
705                                 fi
706                                 cd "$d0"
707                         fi
708                 done
709                 ;;
710         save-patches)
711                 outfile=$1
712                 patchdir=`mktemp -d -t save-patches.XXXXXX`
713                 for d in $repos; do
714                         enter "$d0/$d" verbose
715                         git branch -v -v | cut -c 3- | {
716                                 i=0
717                                 while read -r BRANCH REV UPSTREAM TEXT; do
718                                         case "$UPSTREAM" in
719                                                 \[*)
720                                                         UPSTREAM=${UPSTREAM#\[}
721                                                         UPSTREAM=${UPSTREAM%\]}
722                                                         UPSTREAM=${UPSTREAM%:*}
723                                                         TRACK=true
724                                                         ;;
725                                                 *)
726                                                         UPSTREAM=origin/"`repobranch "$d"`"
727                                                         TRACK=false
728                                                         ;;
729                                         esac
730                                         if [ x"$REV" = x"->" ]; then
731                                                 continue
732                                         fi
733                                         if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
734                                                 echo "$d" > "$patchdir/$i/info.txt"
735                                                 echo "$BRANCH" >> "$patchdir/$i/info.txt"
736                                                 echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
737                                                 echo "$TRACK" >> "$patchdir/$i/info.txt"
738                                                 i=$(($i+1))
739                                         else
740                                                 rm -rf "$patchdir/$i"
741                                         fi
742                                 done
743                         }
744                 done
745                 ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
746                 rm -rf "$patchdir"
747                 ;;
748         restore-patches)
749                 infile=$1
750                 patchdir=`mktemp -d -t restore-patches.XXXXXX`
751                 ( cd "$patchdir" && tar xvzf - ) < "$infile"
752                 # detach the head
753                 for P in "$patchdir"/*/info.txt; do
754                         D=${P%/info.txt}
755                         exec 3<"$P"
756                         read -r d <&3
757                         read -r BRANCH <&3
758                         read -r UPSTREAM <&3
759                         read -r TRACK <&3
760                         verbose git checkout HEAD^0
761                         verbose git branch -D "$BRANCH"
762                         if [ x"$TRACK" = x"true" ]; then
763                                 verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
764                         else
765                                 verbose git branch -b "$BRANCH" "$UPSTREAM"
766                         fi
767                         verbose git am "$D"
768                 done
769                 rm -rf "$patchdir"
770                 ;;
771         admin-merge)
772                 branch=$1
773                 t=`mktemp`
774                 report=""
775                 reportecho()
776                 {
777                         report=$report"$*$LF"
778                         echo "$*"
779                 }
780                 reportecho4()
781                 {
782                         report=$report"    $*$LF"
783                         echo "    $*"
784                 }
785                 reportdo4()
786                 {
787                         o=`"$@" | sed 's/^/    /' || true`
788                         reportecho "$o"
789                 }
790                 for d in $repos; do
791                         enter "$d0/$d" verbose
792                         base="`repobranch "$d"`"
793                         reportecho "In $d:"
794                         for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
795                                 case "${ref#refs/remotes/origin/}" in
796                                         "$base")
797                                                 continue
798                                                 ;;
799                                         HEAD|master)
800                                                 continue
801                                                 ;;
802                                         */*)
803                                                 ;;
804                                         *)
805                                                 continue
806                                                 ;;
807                                 esac
808                                 if [ -n "$branch" ]; then
809                                         if [ x"$branch" != x"${ref#refs/remotes/origin/}" ]; then
810                                                 continue
811                                         fi
812                                 fi
813                                 case "$base" in
814                                         master)
815                                                 realbase=$base
816                                                 ;;
817                                         *)
818                                                 l0=`git rev-list "$base".."$ref" | wc -l`
819                                                 l1=`git rev-list master.."$ref" | wc -l`
820                                                 if [ $l0 -gt $l1 ]; then
821                                                         realbase=master
822                                                 else
823                                                         realbase=$base
824                                                 fi
825                                                 ;;
826                                 esac
827                                 reportecho "  Branch $ref:"
828                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
829                                 logdata=`git log --color "$realbase".."$ref"`
830                                 if [ -z "$logdata" ]; then
831                                         reportecho4 "--> not merging, no changes vs master"
832                                         if yesno "Branch \"$ref\" probably should get deleted. Do it?" ''; then
833                                                 git push origin :"${ref#refs/remotes/origin/}"
834                                                 reportecho4 "--> branch deleted"
835                                         fi
836                                 else
837                                         diffdata=`git diff --color --find-copies-harder --ignore-space-change "$realbase"..."$ref"`
838                                         if [ -z "$diffdata" ]; then
839                                                 reportecho4 "--> not merging, no changes vs master, branch contains redundant history"
840                                                 if yesno "Branch \"$ref\" probably should get deleted. Do it?" '{ echo "$logdata"; } | less -r'; then
841                                                         git push origin :"${ref#refs/remotes/origin/}"
842                                                         reportecho4 "--> branch deleted"
843                                                 fi
844                                         elif [ -z "$branch" ] && [ -n "$note" ]; then
845                                                 reportdo4 echo "$note"
846                                                 reportecho4 "--> not merging, already had this one rejected before"
847                                         elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ echo "$logdata"; echo "$diffdata"; } | less -r'; then
848                                                 git checkout "$realbase"
849                                                 org=`git rev-parse HEAD`
850                                                 if ! git merge --no-ff "$ref" 2>&1 | tee "$t" && ! { git ls-files -u | grep ' 1 ' >/dev/null; }; then
851                                                         git reset --hard "$org"
852                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Merge failed:$LF`cat "$t"`" "$ref"
853                                                         reportdo4 cat "$t"
854                                                         reportecho4 "--> merge failed"
855                                                 elif ! "$SELF" compile 2>&1 | tee "$t"; then
856                                                         git reset --hard "$org"
857                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Compile failed:$LF`cat "$t"`" "$ref"
858                                                         reportdo4 cat "$t"
859                                                         reportecho4 "--> compile failed"
860                                                 elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
861                                                         git reset --hard "$org"
862                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
863                                                         note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
864                                                         if [ x"$note" = x"del" ]; then
865                                                                 git push origin :"${ref#refs/remotes/origin/}"
866                                                                 reportecho4 "--> test failed, branch deleted"
867                                                         elif [ -n "$note" ]; then
868                                                                 reportdo4 echo "$note"
869                                                                 reportecho4 "--> test failed"
870                                                         else
871                                                                 reportecho4 "--> test failed, postponed"
872                                                         fi
873                                                 else
874                                                         echo "MERGING"
875                                                         case ",`repoflags "$d"`," in
876                                                                 *,svn,*)
877                                                                         # we do quite a mess here... luckily we know $org
878                                                                         git fetch # svn needs to be current
879                                                                         git rebase -i --onto origin/master "$org"
880                                                                         git svn dcommit --add-author-from
881                                                                         git reset --hard "$org"
882                                                                         ;;
883                                                                 *)
884                                                                         git push origin HEAD
885                                                                         ;;
886                                                         esac
887                                                         reportecho4 "--> MERGED"
888                                                         if yesno "Delete original branch \"$ref\"?"; then
889                                                                 git push origin :"${ref#refs/remotes/origin/}"
890                                                                 reportecho4 "--> branch deleted"
891                                                         fi
892                                                 fi
893                                         else
894                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
895                                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
896                                                 if [ x"$note" = x"del" ]; then
897                                                         git push origin :"${ref#refs/remotes/origin/}"
898                                                         reportecho4 "--> branch deleted"
899                                                 elif [ -n "$note" ]; then
900                                                         reportdo4 echo "$note"
901                                                         reportecho4 "--> rejected"
902                                                 else
903                                                         reportecho4 "--> postponed"
904                                                 fi
905                                         fi
906                                 fi
907                                 reportecho ""
908                         done
909                         reportecho ""
910                 done
911                 rm -f "$t"
912                 echo "$report" | ssh nexuiz@rm.endoftheinternet.org cat '>>' public_html/xonotic-merge-notes.txt
913                 ;;
914         clean)
915                 force=false
916                 gotoupstream=false
917                 fetchupstream=false
918                 gotomaster=false
919                 rmuntracked=false
920                 killbranches=false
921                 # usage:
922                 #   ./all clean [-m] [-f | -fu | -fU] [-r] [-D]
923                 #   ./all clean --reclone
924                 found=false
925                 while :; do
926                         if [ x"$1" = x"--reclone" ]; then
927                                 force=true
928                                 fetchupstream=true
929                                 gotoupstream=true
930                                 gotomaster=true
931                                 rmuntracked=true
932                                 killbranches=true
933                         elif [ x"$1" = x"-f" ]; then
934                                 force=true
935                         elif [ x"$1" = x"-u" ]; then
936                                 gotoupstream=true
937                         elif [ x"$1" = x"-U" ]; then
938                                 gotoupstream=true
939                                 fetchupstream=true
940                         elif [ x"$1" = x"-fu" ]; then
941                                 force=true
942                                 gotoupstream=true
943                         elif [ x"$1" = x"-fU" ]; then
944                                 force=true
945                                 gotoupstream=true
946                                 fetchupstream=true
947                         elif [ x"$1" = x"-m" ]; then
948                                 gotomaster=true
949                         elif [ x"$1" = x"-r" ]; then
950                                 rmuntracked=true
951                         elif [ x"$1" = x"-D" ]; then
952                                 killbranches=true
953                         else
954                                 break
955                         fi
956                         found=true
957                         shift
958                 done
959                 if ! $found; then
960                         rmuntracked=true
961                 fi
962                 for d in $repos; do
963                         verbose cd "$d0/$d"
964                         if $gotoupstream; then
965                                 if ! $force; then
966                                         msg "Must also use -f (delete local changes) when using -u"
967                                         exit 1
968                                 fi
969                                 if $gotomaster; then
970                                         if $fetchupstream; then
971                                                 verbose git fetch origin
972                                                 verbose git remote prune origin
973                                         fi
974                                         verbose git checkout -f "`repobranch "$d"`"
975                                         verbose git reset --hard origin/"`repobranch "$d"`"
976                                 else
977                                         r=`git symbolic-ref HEAD`
978                                         r=${r#refs/heads/}
979                                         rem=`git config "branch.$r.remote" || echo origin`
980                                         bra=`git config "branch.$r.merge" || echo "$r"`
981                                         upstream="$rem/${bra#refs/heads/}"
982                                         if $fetchupstream; then
983                                                 verbose git fetch "$rem"
984                                                 verbose git remote prune "$rem"
985                                         fi
986                                         if ! git rev-parse "$upstream" >/dev/null 2>&1; then
987                                                 upstream="origin/`repobranch "$d"`"
988                                         fi
989                                         verbose git reset --hard "$upstream"
990                                 fi
991                         elif $gotomaster; then
992                                 if $force; then
993                                         verbose git checkout -f "`repobranch "$d"`"
994                                         verbose git reset --hard
995                                 else
996                                         verbose git checkout "`repobranch "$d"`"
997                                 fi
998                         elif $force; then
999                                 verbose git reset --hard
1000                         fi
1001                         if $rmuntracked; then
1002                                 case "$d" in
1003                                         .)
1004                                                 verbose git clean -df
1005                                                 ;;
1006                                         *)
1007                                                 verbose git clean -xdf
1008                                                 ;;
1009                                 esac
1010                         fi
1011                         if $killbranches; then
1012                                 git for-each-ref --format='%(refname)' refs/heads/ | while IFS= read -r B; do
1013                                         if [ x"$B" != x"`git symbolic-ref HEAD`" ]; then
1014                                                 verbose git branch -D "${B#refs/heads/}"
1015                                         fi
1016                                 done
1017                         fi
1018                 done
1019                 ;;
1020
1021         # release building goes here
1022         release-prepare)
1023                 #"$SELF" each git clean -fxd
1024                 case "$RELEASETYPE" in
1025                         beta)
1026                                 msg "Building a BETA"
1027                                 ;;
1028                         release)
1029                                 msg "Building a RELEASE"
1030                                 ;;
1031                         *)
1032                                 msg "Must either set RELEASETYPE=beta or RELEASETYPE=release"
1033                                 exit 1
1034                                 ;;
1035                 esac
1036                 verbose rm -rf Xonotic Xonotic*.zip
1037                 verbose mkdir -p Xonotic
1038                 if [ -n "$RELEASEDATE" ]; then
1039                         verbose echo "$RELEASEDATE" > Xonotic/stamp.txt
1040                 else
1041                         verbose date +%Y%m%d > Xonotic/stamp.txt
1042                 fi
1043                 verbose git archive --format=tar HEAD -- Docs misc server xonotic-linux-glx.sh xonotic-linux-sdl.sh misc/buildfiles | {
1044                         verbose cd Xonotic
1045                         verbose mkdir data fteqcc source source/darkplaces source/fteqcc
1046                         verbose tar xvf -
1047                         verbose rm -rf misc/builddeps
1048                         verbose mv misc/buildfiles/win32/* . || true
1049                         verbose mv misc/buildfiles/win64 bin64 || true
1050                         verbose mv misc/buildfiles/osx/* . || true
1051                         verbose rm -rf misc/buildfiles
1052                 }
1053                 {
1054                         verbose cd darkplaces
1055                         verbose git archive --format=tar HEAD
1056                 } | {
1057                         verbose cd Xonotic/source/darkplaces
1058                         verbose tar xvf -
1059                 }
1060                 {
1061                         verbose cd fteqcc
1062                         verbose git archive --format=tar HEAD
1063                 } | {
1064                         verbose cd Xonotic/source/fteqcc
1065                         verbose tar xvf -
1066                 }
1067                 {
1068                         verbose cd data/xonotic-data.pk3dir
1069                         verbose git archive --format=tar HEAD -- qcsrc Makefile
1070                 } | {
1071                         verbose cd Xonotic/source
1072                         verbose tar xvf -
1073                 }
1074                 ;;
1075         release-compile-run)
1076                 host=$1
1077                 buildpath=$2
1078                 maketargets=$3
1079                 makeflags=$4
1080                 srcdir=$5
1081                 depsdir=$6
1082                 targetfiles=$7
1083                 set -x
1084                 if [ -n "$targetfiles" ]; then
1085                         case " $HOSTS_THAT_ARE_DISABLED " in
1086                                 *\ $host\ *)
1087                                         exit
1088                                         ;;
1089                         esac
1090                         case " $HOSTS_THAT_ARE_MYSELF " in
1091                                 *\ $host\ *)
1092                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$buildpath/"
1093                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$buildpath.deps/"
1094                                         verbose ln -snf "$buildpath.deps" "$buildpath/.deps"
1095                                         verbose eval make -C "$buildpath" clean $maketargets $makeflags
1096                                         for f in $targetfiles; do
1097                                                 verbose mv "$buildpath/${f%:*}" "${f##*:}" || true
1098                                         done
1099                                         ;;
1100                                 *)
1101                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$host:$buildpath/"
1102                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$host:$buildpath.deps/"
1103                                         verbose ssh "$host" "ln -snf $buildpath.deps $buildpath/.deps && cd $buildpath && nice -`nice` make clean $maketargets $makeflags"
1104                                         for f in $targetfiles; do
1105                                                 verbose rsync -zvaSHP "$host:$buildpath/${f%:*}" "${f##*:}" || true
1106                                         done
1107                                         ;;
1108                         esac
1109                         # now rebrand the binaries...
1110                         for f in $targetfiles; do
1111                                 #verbose "$d0/misc/tools/rebrand-darkplaces-engine.sh" "${XONOTIC_BRAND:-$d0/misc/tools/xonotic.brand}" "${f##*:}" || true
1112                                 case "$f" in
1113                                         xonotic*.exe)
1114                                                 verbose "$d0/misc/tools/change-icon-of-exe.sh" "$d0/misc/logos/icons_ico/xonotic.ico" "$f"
1115                                                 (
1116                                                         d=`mktemp -d -t rebrand.XXXXXX`
1117                                                         cd "$d"
1118                                                         echo "-mygames" > darkplaces.opt
1119                                                         zip -9r darkplaces.zip darkplaces.opt
1120                                                         cat darkplaces.zip
1121                                                         cd "$d0"
1122                                                         rm -rf "$d"
1123                                                 ) >> "$f"
1124                                                 ;;
1125                                 esac
1126                         done
1127                 fi
1128                 ;;
1129         release-compile)
1130                 suffix=$1
1131                 makeflags=$2
1132                 fteqcc_maketargets=$3
1133                 fteqcc_files=$4
1134                 darkplaces_maketargets=$5
1135                 darkplaces_files=$6
1136                 host=xonotic-build-$suffix
1137                 verbose "$SELF" release-compile-run "$host" /tmp/fteqcc.build."$suffix" "$fteqcc_maketargets" "$makeflags" "Xonotic/source/fteqcc" "$d0/misc/builddeps/dp.$suffix" "$fteqcc_files"
1138                 verbose "$SELF" release-compile-run "$host" /tmp/Darkplaces.build."$suffix" "$darkplaces_maketargets" "$makeflags" "Xonotic/source/darkplaces" "$d0/misc/builddeps/dp.$suffix" "$darkplaces_files"
1139                 ;;
1140         release-engine-win32)
1141                 verbose "$SELF" release-compile win32 \
1142                         'STRIP=: DP_MAKE_TARGET=mingw CC="i586-mingw32msvc-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib" WINDRES="i586-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN32RELEASE=1 D3D=0' \
1143                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc.exe' \
1144                         '' ''
1145                 verbose "$SELF" release-compile win32 \
1146                         'STRIP=: DP_MAKE_TARGET=mingw CC="i586-mingw32msvc-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib" WINDRES="i586-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN32RELEASE=1 D3D=0' \
1147                         '' '' \
1148                         release 'darkplaces.exe:Xonotic/xonotic.exe darkplaces-sdl.exe:Xonotic/xonotic-sdl.exe darkplaces-dedicated.exe:Xonotic/xonotic-dedicated.exe'
1149                 ;;
1150         release-engine-win64)
1151                 verbose "$SELF" release-compile win64 \
1152                         'STRIP=: DP_MAKE_TARGET=mingw CC="amd64-mingw32msvc-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib" WINDRES="amd64-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN64RELEASE=1 D3D=0' \
1153                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc-x64.exe' \
1154                         'sv-release sdl-release' 'darkplaces-sdl.exe:Xonotic/xonotic-x64-sdl.exe darkplaces-dedicated.exe:Xonotic/xonotic-x64-dedicated.exe'
1155                 verbose "$SELF" release-compile win64 \
1156                         'STRIP=: DP_MAKE_TARGET=mingw CC="x86_64-w64-mingw32-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib" WINDRES="x86_64-w64-mingw32-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN64RELEASE=1 D3D=0' \
1157                         '' '' \
1158                         cl-release 'darkplaces.exe:Xonotic/xonotic-x64.exe'
1159                 ;;
1160         release-engine-osx)
1161                 # gcc on OSX is buggy, needs -fno-reorder-blocks for a release build to succeed
1162                 verbose "$SELF" release-compile osx \
1163                         'STRIP=: CC="gcc -g -arch i386 -arch ppc -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.4 -I.deps/include -L.deps/lib -fno-reorder-blocks"' \
1164                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.osx' \
1165                         'sv-release sdl-release' 'darkplaces-sdl:Xonotic/Xonotic-SDL.app/Contents/MacOS/xonotic-osx-sdl-bin darkplaces-dedicated:Xonotic/xonotic-osx-dedicated'
1166                 verbose "$SELF" release-compile osx \
1167                         'STRIP=: CC="gcc -g -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.4 -I.deps/include -L.deps/lib -fno-reorder-blocks"' \
1168                         '' '' \
1169                         'cl-release' 'darkplaces-agl:Xonotic/Xonotic.app/Contents/MacOS/xonotic-osx-agl-bin'
1170                 ;;
1171         release-engine-linux32)
1172                 verbose "$SELF" release-compile linux32 \
1173                         'STRIP=: CC="gcc -m32 -g -I.deps/include -L.deps/lib" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a' \
1174                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux32' \
1175                         release 'darkplaces-glx:Xonotic/xonotic-linux32-glx darkplaces-sdl:Xonotic/xonotic-linux32-sdl darkplaces-dedicated:Xonotic/xonotic-linux32-dedicated'
1176                 ;;
1177         release-engine-linux64)
1178                 verbose "$SELF" release-compile linux64 \
1179                         'STRIP=: CC="gcc -m64 -g -I.deps/include -L.deps/lib" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a' \
1180                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux64' \
1181                         release 'darkplaces-glx:Xonotic/xonotic-linux64-glx darkplaces-sdl:Xonotic/xonotic-linux64-sdl darkplaces-dedicated:Xonotic/xonotic-linux64-dedicated'
1182                 ;;
1183         release-engine)
1184                 verbose "$SELF" release-engine-linux32 &
1185                 verbose "$SELF" release-engine-linux64 &
1186                 verbose "$SELF" release-engine-win32 &
1187                 verbose "$SELF" release-engine-win64 &
1188                 verbose "$SELF" release-engine-osx &
1189                 wait %1
1190                 wait %2
1191                 wait %3
1192                 wait %4
1193                 wait %5
1194                 wait
1195                 ;;
1196         release-maps)
1197                 verbose "$SELF" update-maps
1198                 ;;
1199         release-qc)
1200                 case "$RELEASETYPE" in
1201                         beta)
1202                                 verbose make -C Xonotic/source FTEQCC="$d0/Xonotic/fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 clean all
1203                                 ;;
1204                         release)
1205                                 verbose make -C Xonotic/source FTEQCC="$d0/Xonotic/fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 FTEQCCFLAGS_WATERMARK= clean all
1206                                 ;;
1207                 esac
1208                 verbose rm -f Xonotic/source/*/fteqcc.log
1209                 ;;
1210         release-buildpk3-transform-raw)
1211                 dir=$1
1212                 ;;
1213         release-buildpk3-transform-normal)
1214                 dir=$1
1215                 verbose cd "$dir"
1216                 # texture: convert to jpeg and dds
1217                 verbose export do_jpeg=true
1218                 verbose export jpeg_qual_rgb=95
1219                 verbose export jpeg_qual_a=99
1220                 verbose export do_dds=true
1221                 verbose export dds_flags=
1222                 verbose export do_ogg=false
1223                 verbose export del_src=true
1224                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1225                 ;;
1226         release-buildpk3-transform-low)
1227                 dir=$1
1228                 verbose cd "$dir"
1229                 # texture: convert to jpeg and dds
1230                 # music: reduce bitrate
1231                 verbose export do_jpeg=true
1232                 verbose export jpeg_qual_rgb=80
1233                 verbose export jpeg_qual_a=95
1234                 verbose export do_dds=false
1235                 verbose export do_ogg=true
1236                 verbose export ogg_qual=1
1237                 verbose export del_src=true
1238                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1239                 ;;
1240         release-buildpk3-transform-lowdds)
1241                 dir=$1
1242                 verbose cd "$dir"
1243                 # texture: convert to jpeg and dds
1244                 # music: reduce bitrate
1245                 verbose export do_jpeg=false
1246                 verbose export do_jpeg_if_not_dds=true
1247                 verbose export jpeg_qual_rgb=80
1248                 verbose export jpeg_qual_a=95
1249                 verbose export do_dds=true
1250                 verbose export dds_flags=
1251                 verbose export do_ogg=true
1252                 verbose export ogg_qual=1
1253                 verbose export del_src=true
1254                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1255                 ;;
1256         release-buildpk3)
1257                 src=$1
1258                 dst=$2
1259                 transform=$3
1260                 case "$dst" in
1261                         /*)
1262                                 ;;
1263                         */)
1264                                 dst="$PWD/$dst"
1265                                 ;;
1266                 esac
1267                 verbose rm -rf Xonotic/temp
1268                 verbose mkdir -p Xonotic/temp
1269                 {
1270                         verbose cd "$src"
1271                         verbose git archive --format=tar HEAD
1272                 } | {
1273                         verbose cd Xonotic/temp
1274                         verbose tar xvf -
1275                 }
1276                 verbose cd Xonotic/temp
1277                 if [ x"$src" = x"data/xonotic-data.pk3dir" ]; then
1278                         verbose cp ../source/progs.dat .
1279                         verbose cp ../source/csprogs.dat .
1280                         verbose cp ../source/menu.dat .
1281                         verbose rm -rf qcsrc
1282                         gv=`grep "^gameversion " "defaultXonotic.cfg" | awk '{ print $2 }'`
1283                         major=$(($gv / 10000))
1284                         minor=$(($gv / 100 - $major * 100))
1285                         patch=$(($gv - $major * 10000 - $minor * 100))
1286                         versionstr="$major.$minor.$patch"
1287                         case "$RELEASETYPE" in
1288                                 beta)
1289                                         versionstr="$versionstr""beta"
1290                                         ;;
1291                         esac
1292                         verbose sed -i "
1293                                 s/^set g_xonoticversion [^ ]* /set g_xonoticversion $versionstr /;
1294                                 s/^gameversion_min [0-9]*/gameversion_min $(( ($gv / 100) * 100 - 100 ))/;
1295                                 s/^gameversion_max [0-9]*/gameversion_max $(( ($gv / 100) * 100 + 199 ))/;
1296                         " defaultXonotic.cfg
1297                         (
1298                                 verbose cd gfx/menu/luminos
1299                                 verbose cp "$d0"/mediasource/gfx/menu/luminos_versionbuilder/background_l2.svg .
1300                                 verbose "$d0"/mediasource/gfx/menu/luminos_versionbuilder/versionbuilder "$versionstr"
1301                                 verbose rm background_l2.svg
1302                         )
1303                 fi
1304                 if [ x"$src" = x"data/xonotic-maps.pk3dir" ]; then
1305                         for X in ../../data/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
1306                                 if [ -f "$X" ]; then
1307                                         verbose unzip "$X"
1308                                         verbose rm -f maps/*.log maps/*.irc maps/*.lin
1309                                 fi
1310                         done
1311                 fi
1312                 verbose export git_src_repo="$d0/$src" # skip hash-object
1313                 verbose "$SELF" release-buildpk3-transform-$transform "Xonotic/temp"
1314                 verbose mkzip "../../$dst" *
1315                 verbose cd ../..
1316                 verbose rm -rf Xonotic/temp
1317                 ;;
1318         release-buildpk3s)
1319                 stamp=`cat Xonotic/stamp.txt`
1320                 src=$1
1321                 shift
1322                 dst=${src%.pk3dir}
1323                 case "$dst" in
1324                         data/xonotic-*)
1325                                 dst="data/xonotic-$stamp-${dst#data/xonotic-}"
1326                                 ;;
1327                         *)
1328                                 dst="$dst-$stamp"
1329                                 ;;
1330                 esac
1331                 while [ "$#" -gt 1 ]; do
1332                         verbose "$SELF" release-buildpk3 "$src" "Xonotic/$dst$2.pk3" "$1"
1333                         shift
1334                         shift
1335                 done
1336                 ;;
1337         release-pack)
1338                 verbose "$SELF" release-buildpk3s data/font-nimbussansl.pk3dir             raw ''
1339                 verbose "$SELF" release-buildpk3s data/xonotic-data.pk3dir       normal '' raw '-raw' low '-low' lowdds '-lowdds'
1340                 verbose "$SELF" release-buildpk3s data/xonotic-maps.pk3dir       normal '' raw '-raw' low '-low' lowdds '-lowdds'
1341                 verbose "$SELF" release-buildpk3s data/xonotic-music.pk3dir                raw ''     low '-low'
1342                 verbose "$SELF" release-buildpk3s data/xonotic-nexcompat.pk3dir                       low ''
1343                 ;;
1344         release-pack-needsx11)
1345                 case "$DISPLAY" in
1346                         '')
1347                                 verbose startx "$SELF" release-pack -- /usr/bin/Xvfb :7
1348                                 ;;
1349                         *)
1350                                 verbose "$SELF" release-pack
1351                                 ;;
1352                 esac
1353                 ;;
1354         release-zip)
1355                 stamp=`cat Xonotic/stamp.txt`
1356                 # exe and dll files do not need +x, so this makes them eligible for 7zip compression too
1357                 chmod a-x Xonotic/*.exe Xonotic/*.dll || true
1358                 # need to use infozip for these (+x bits)
1359                 verbose mkzip Xonotic-$stamp-engine.zip \
1360                         Xonotic/*.dll \
1361                         Xonotic/bin64/*.dll \
1362                         Xonotic/*.app \
1363                         Xonotic/xonotic-* \
1364                         Xonotic/xonotic.exe \
1365                         Xonotic/source/darkplaces/
1366                 verbose cp Xonotic-$stamp-engine.zip Xonotic-$stamp-common.zip
1367                 verbose mkzip Xonotic-$stamp-common.zip \
1368                         Xonotic/source/fteqcc/ \
1369                         Xonotic/source/qcsrc/ \
1370                         Xonotic/Docs \
1371                         Xonotic/misc \
1372                         Xonotic/fteqcc \
1373                         Xonotic/server \
1374                         Xonotic/data/font-nimbussansl-$stamp.pk3
1375                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp.zip
1376                 verbose mkzip0 Xonotic-$stamp.zip \
1377                         Xonotic/data/xonotic-$stamp-data.pk3 \
1378                         Xonotic/data/xonotic-$stamp-maps.pk3 \
1379                         Xonotic/data/xonotic-$stamp-music.pk3 \
1380                         Xonotic/data/xonotic-$stamp-nexcompat.pk3
1381                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-low.zip
1382                 verbose mkzip0 Xonotic-$stamp-low.zip \
1383                         Xonotic/data/xonotic-$stamp-data-low.pk3 \
1384                         Xonotic/data/xonotic-$stamp-maps-low.pk3 \
1385                         Xonotic/data/xonotic-$stamp-music-low.pk3
1386                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-lowdds.zip
1387                 verbose mkzip0 Xonotic-$stamp-lowdds.zip \
1388                         Xonotic/data/xonotic-$stamp-data-lowdds.pk3 \
1389                         Xonotic/data/xonotic-$stamp-maps-lowdds.pk3 \
1390                         Xonotic/data/xonotic-$stamp-music-low.pk3
1391                 verbose mv Xonotic-$stamp-common.zip Xonotic-$stamp-high.zip
1392                 verbose mkzip0 Xonotic-$stamp-high.zip \
1393                         Xonotic/data/xonotic-$stamp-data-raw.pk3 \
1394                         Xonotic/data/xonotic-$stamp-maps-raw.pk3 \
1395                         Xonotic/data/xonotic-$stamp-music.pk3 \
1396                         Xonotic/data/xonotic-$stamp-nexcompat.pk3
1397                 ;;
1398         release)
1399                 verbose "$SELF" release-prepare
1400                 verbose "$SELF" release-maps
1401                 verbose "$SELF" release-engine
1402                 verbose "$SELF" release-qc
1403                 verbose "$SELF" release-pack-needsx11
1404                 verbose "$SELF" release-zip
1405                 ;;
1406
1407         *)
1408                 echo "Usage:"
1409                 echo "  $SELF admin-merge [<branch>]"
1410                 echo "  $SELF branch <branch>"
1411                 echo "  $SELF branch <remote> <branch> [<srcbranch>]"
1412                 echo "  $SELF branches"
1413                 echo "  $SELF checkout|switch <branch>"
1414                 echo "  $SELF checkout|switch <remote>/<branch>"
1415                 echo "  $SELF clean [-m] [-f | -fu | -fU] [-r] [-D]"
1416                 echo "  $SELF clean --reclone"
1417                 echo "  $SELF compile [-c]"
1418                 echo "  $SELF each|foreach [-k] command..."
1419                 echo "  $SELF fix_upstream_rebase"
1420                 echo "  $SELF merge"
1421                 echo "  $SELF push|commit [-s]"
1422                 echo "  $SELF release"
1423                 echo "  $SELF restore-patches"
1424                 echo "  $SELF run [sdl|glx|wgl|agl|dedicated] options..."
1425                 echo "  $SELF save-patches"
1426                 echo "  $SELF update-maps"
1427                 echo "  $SELF update|pull [-N]"
1428                 ;;
1429 esac