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