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