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