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