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