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