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