]> git.xonotic.org Git - xonotic/xonotic.git/blob - all
12d312afbc8ffca5b09203bc66687b9f1da4335a
[xonotic/xonotic.git] / all
1 #!/bin/sh
2 # vim: filetype=zsh
3
4 set -e
5
6 # I use this in EVERY shell script ;)
7 LF="
8 "
9
10 d00=`pwd`
11 while ! [ -f ./all ]; do
12         if [ x"`pwd`" = x"/" ]; then
13                 echo "Cannot find myself."
14                 echo "Please run this script with the working directory inside a Xonotic checkout."
15                 exit 1
16         fi
17         cd ..
18 done
19 export d0=`pwd`
20 SELF="$d0/all"
21
22 # If we are on WINDOWS:
23 case "$0" in
24         all|*/all)
25                 case "`uname`" in
26                         MINGW*|Win*)
27                                 # Windows hates users. So this script has to copy itself elsewhere first...
28                                 cp "$SELF" ../all.xonotic.sh
29                                 export WE_HATE_OUR_USERS=1
30                                 exec ../all.xonotic.sh "$@"
31                                 ;;
32                 esac
33                 ;;
34 esac
35
36 msg()
37 {
38         echo >&2 "\e[1m$*\e[m"
39 }
40
41 self=`git hash-object "$SELF"`
42 checkself()
43 {
44         self_new=`git hash-object "$SELF"`
45         if [ x"$self" != x"$self_new" ]; then
46                 msg "./all has changed."
47                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
48                         msg "Rerunning the requested operation to make sure."
49                         export XONOTIC_FORBID_RERUN_ALL=1
50                         exec "$SELF" "$@"
51                 else
52                         msg "Please try $SELF update, and then retry your requested operation."
53                         exit 1
54                 fi
55         fi
56         return 0
57 }
58
59 verbose()
60 {
61         msg "+ $*"
62         "$@"
63 }
64
65 visible_repo_name()
66 {
67         case "$1" in
68                 .)
69                         echo "the root directory"
70                         ;;
71                 *)
72                         echo "\"$1\""
73                         ;;
74         esac
75 }
76
77 check_mergeconflict()
78 {
79         if git ls-files -u | grep ' 1   '; then
80                 echo
81                 echo "MERGE CONFLICT."
82                 echo "change into the \"$1\" project directory, and then:"
83                 echo "- edit the files mentioned above with your favorite editor,"
84                 echo "  and fix the conflicts (marked with <<<<<<< blocks)"
85                 echo "- for binary files, you can select the files using"
86                 echo "  git checkout --ours or git checkout --theirs"
87                 echo "- when done with a file, 'git add' the file"
88                 echo "- when done, 'git commit'"
89                 echo
90                 exit 1
91         fi
92 }
93
94 yesno()
95 {
96         yesno=
97         while [ x"$yesno" != x"y" -a x"$yesno" != x"n" ]; do
98                 eval "$2"
99                 echo "$1"
100                 IFS= read -r yesno
101         done
102         [ x"$yesno" = x"y" ]
103 }
104
105 enter()
106 {
107         $2 cd "$1" || exit 1
108         check_mergeconflict "$1"
109 }
110
111 repos_urls="
112 .                             |                                                   | master      |
113 data/xonotic-data.pk3dir      |                                                   | master      |
114 data/xonotic-music.pk3dir     |                                                   | master      |
115 data/xonotic-nexcompat.pk3dir |                                                   | master      | no
116 darkplaces                    |                                                   | div0-stable | svn
117 netradiant                    |                                                   | master      |
118 div0-gittools                 |                                                   | master      | no
119 d0_blind_id                   | http://github.com/divVerent/d0_blind_id.git       | master      |
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
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 [ -z "$CC" ]; then
525                         export CC="gcc -DSUPPORT_IPV6"
526                 fi
527                 if [ -n "$WE_HATE_OUR_USERS" ]; then
528                         TARGETS="sv-debug cl-debug"
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="$CC -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" -xonotic -mygames "$@"
671
672                 # if pulseaudio is running: USE IT
673                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
674                         if ps -C pulseaudio >/dev/null; then
675                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
676                                         export SDL_AUDIODRIVER=pulse
677                                 fi
678                         fi
679                 fi
680
681                 binary=$1
682
683                 if [ -n "$USE_GDB" ]; then
684                         set -- gdb --args "$@"
685                 elif which gdb >/dev/null 2>&1; then
686                         set -- gdb --batch -x savecore.gdb --args "$@"
687                 elif which catchsegv >/dev/null 2>&1; then
688                         set -- catchsegv "$@"
689                 fi
690                 rm -f xonotic.core
691                 "$@" || true
692                 if [ -f xonotic.core ]; then
693                         if yesno "The program has CRASHED. Do you want to examine the core dump?"; then
694                                 gdb "$binary" xonotic.core
695                         #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
696                         #       tar cvzf xonotic.core.tar.gz xonotic.core darkplaces/*.c darkplaces/*.h
697                         #       # somehow send it
698                         #       rm -f xonotic.core.tar.gz
699                         else
700                                 echo "The core dump can be examined later by"
701                                 echo "  gdb $binary xonotic.core"
702                         fi
703                 fi
704                 ;;
705         each|foreach)
706                 keep_going=false
707                 if [ x"$1" = x"-k" ]; then
708                         keep_going=true
709                         shift
710                 fi
711                 for d in $repos; do
712                         if verbose cd "$d0/$d"; then
713                                 if $keep_going; then
714                                         verbose "$@" || true
715                                 else
716                                         verbose "$@"
717                                 fi
718                                 cd "$d0"
719                         fi
720                 done
721                 ;;
722         save-patches)
723                 outfile=$1
724                 patchdir=`mktemp -d -t save-patches.XXXXXX`
725                 for d in $repos; do
726                         enter "$d0/$d" verbose
727                         git branch -v -v | cut -c 3- | {
728                                 i=0
729                                 while read -r BRANCH REV UPSTREAM TEXT; do
730                                         case "$UPSTREAM" in
731                                                 \[*)
732                                                         UPSTREAM=${UPSTREAM#\[}
733                                                         UPSTREAM=${UPSTREAM%\]}
734                                                         UPSTREAM=${UPSTREAM%:*}
735                                                         TRACK=true
736                                                         ;;
737                                                 *)
738                                                         UPSTREAM=origin/"`repobranch "$d"`"
739                                                         TRACK=false
740                                                         ;;
741                                         esac
742                                         if [ x"$REV" = x"->" ]; then
743                                                 continue
744                                         fi
745                                         if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
746                                                 echo "$d" > "$patchdir/$i/info.txt"
747                                                 echo "$BRANCH" >> "$patchdir/$i/info.txt"
748                                                 echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
749                                                 echo "$TRACK" >> "$patchdir/$i/info.txt"
750                                                 i=$(($i+1))
751                                         else
752                                                 rm -rf "$patchdir/$i"
753                                         fi
754                                 done
755                         }
756                 done
757                 ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
758                 rm -rf "$patchdir"
759                 ;;
760         restore-patches)
761                 infile=$1
762                 patchdir=`mktemp -d -t restore-patches.XXXXXX`
763                 ( cd "$patchdir" && tar xvzf - ) < "$infile"
764                 # detach the head
765                 for P in "$patchdir"/*/info.txt; do
766                         D=${P%/info.txt}
767                         exec 3<"$P"
768                         read -r d <&3
769                         read -r BRANCH <&3
770                         read -r UPSTREAM <&3
771                         read -r TRACK <&3
772                         verbose git checkout HEAD^0
773                         verbose git branch -D "$BRANCH"
774                         if [ x"$TRACK" = x"true" ]; then
775                                 verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
776                         else
777                                 verbose git branch -b "$BRANCH" "$UPSTREAM"
778                         fi
779                         verbose git am "$D"
780                 done
781                 rm -rf "$patchdir"
782                 ;;
783         admin-merge)
784                 branch=$1
785                 t=`mktemp`
786                 report=""
787                 reportecho()
788                 {
789                         report=$report"$*$LF"
790                         echo "$*"
791                 }
792                 reportecho4()
793                 {
794                         report=$report"    $*$LF"
795                         echo "    $*"
796                 }
797                 reportdo4()
798                 {
799                         o=`"$@" | sed 's/^/    /' || true`
800                         reportecho "$o"
801                 }
802                 for d in $repos; do
803                         enter "$d0/$d" verbose
804                         base="`repobranch "$d"`"
805                         reportecho "In $d:"
806                         for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
807                                 case "${ref#refs/remotes/origin/}" in
808                                         "$base")
809                                                 continue
810                                                 ;;
811                                         HEAD|master)
812                                                 continue
813                                                 ;;
814                                         */*)
815                                                 ;;
816                                         *)
817                                                 continue
818                                                 ;;
819                                 esac
820                                 if [ -n "$branch" ]; then
821                                         if [ x"$branch" != x"${ref#refs/remotes/origin/}" ]; then
822                                                 continue
823                                         fi
824                                 fi
825                                 case "$base" in
826                                         master)
827                                                 realbase=$base
828                                                 ;;
829                                         *)
830                                                 l0=`git rev-list "$base".."$ref" | wc -l`
831                                                 l1=`git rev-list master.."$ref" | wc -l`
832                                                 if [ $l0 -gt $l1 ]; then
833                                                         realbase=master
834                                                 else
835                                                         realbase=$base
836                                                 fi
837                                                 ;;
838                                 esac
839                                 reportecho "  Branch $ref:"
840                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
841                                 logdata=`git log --color "$realbase".."$ref"`
842                                 if [ -z "$logdata" ]; then
843                                         reportecho4 "--> not merging, no changes vs master"
844                                         if yesno "Branch \"$ref\" probably should get deleted. Do it?" ''; then
845                                                 git push origin :"${ref#refs/remotes/origin/}"
846                                                 reportecho4 "--> branch deleted"
847                                         fi
848                                 else
849                                         diffdata=`git diff --color --find-copies-harder --ignore-space-change "$realbase"..."$ref"`
850                                         if [ -z "$diffdata" ]; then
851                                                 reportecho4 "--> not merging, no changes vs master, branch contains redundant history"
852                                                 if yesno "Branch \"$ref\" probably should get deleted. Do it?" '{ echo "$logdata"; } | less -r'; then
853                                                         git push origin :"${ref#refs/remotes/origin/}"
854                                                         reportecho4 "--> branch deleted"
855                                                 fi
856                                         elif [ -z "$branch" ] && [ -n "$note" ]; then
857                                                 reportdo4 echo "$note"
858                                                 reportecho4 "--> not merging, already had this one rejected before"
859                                         elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ echo "$logdata"; echo "$diffdata"; } | less -r'; then
860                                                 git checkout "$realbase"
861                                                 org=`git rev-parse HEAD`
862                                                 if ! git merge --no-ff "$ref" 2>&1 | tee "$t" && ! { git ls-files -u | grep ' 1 ' >/dev/null; }; then
863                                                         git reset --hard "$org"
864                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Merge failed:$LF`cat "$t"`" "$ref"
865                                                         reportdo4 cat "$t"
866                                                         reportecho4 "--> merge failed"
867                                                 elif ! "$SELF" compile 2>&1 | tee "$t"; then
868                                                         git reset --hard "$org"
869                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Compile failed:$LF`cat "$t"`" "$ref"
870                                                         reportdo4 cat "$t"
871                                                         reportecho4 "--> compile failed"
872                                                 elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
873                                                         git reset --hard "$org"
874                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
875                                                         note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
876                                                         if [ x"$note" = x"del" ]; then
877                                                                 git push origin :"${ref#refs/remotes/origin/}"
878                                                                 reportecho4 "--> test failed, branch deleted"
879                                                         elif [ -n "$note" ]; then
880                                                                 reportdo4 echo "$note"
881                                                                 reportecho4 "--> test failed"
882                                                         else
883                                                                 reportecho4 "--> test failed, postponed"
884                                                         fi
885                                                 else
886                                                         echo "MERGING"
887                                                         case ",`repoflags "$d"`," in
888                                                                 *,svn,*)
889                                                                         # we do quite a mess here... luckily we know $org
890                                                                         git fetch # svn needs to be current
891                                                                         git rebase -i --onto origin/master "$org"
892                                                                         git svn dcommit --add-author-from
893                                                                         git reset --hard "$org"
894                                                                         ;;
895                                                                 *)
896                                                                         git push origin HEAD
897                                                                         ;;
898                                                         esac
899                                                         reportecho4 "--> MERGED"
900                                                         if yesno "Delete original branch \"$ref\"?"; then
901                                                                 git push origin :"${ref#refs/remotes/origin/}"
902                                                                 reportecho4 "--> branch deleted"
903                                                         fi
904                                                 fi
905                                         else
906                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
907                                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
908                                                 if [ x"$note" = x"del" ]; then
909                                                         git push origin :"${ref#refs/remotes/origin/}"
910                                                         reportecho4 "--> branch deleted"
911                                                 elif [ -n "$note" ]; then
912                                                         reportdo4 echo "$note"
913                                                         reportecho4 "--> rejected"
914                                                 else
915                                                         reportecho4 "--> postponed"
916                                                 fi
917                                         fi
918                                 fi
919                                 reportecho ""
920                         done
921                         reportecho ""
922                 done
923                 rm -f "$t"
924                 echo "$report" | ssh nexuiz@rm.endoftheinternet.org cat '>>' public_html/xonotic-merge-notes.txt
925                 ;;
926         clean)
927                 force=false
928                 gotoupstream=false
929                 fetchupstream=false
930                 gotomaster=false
931                 rmuntracked=false
932                 killbranches=false
933                 # usage:
934                 #   ./all clean [-m] [-f | -fu | -fU] [-r] [-D]
935                 #   ./all clean --reclone
936                 found=false
937                 while :; do
938                         if [ x"$1" = x"--reclone" ]; then
939                                 force=true
940                                 fetchupstream=true
941                                 gotoupstream=true
942                                 gotomaster=true
943                                 rmuntracked=true
944                                 killbranches=true
945                         elif [ x"$1" = x"-f" ]; then
946                                 force=true
947                         elif [ x"$1" = x"-u" ]; then
948                                 gotoupstream=true
949                         elif [ x"$1" = x"-U" ]; then
950                                 gotoupstream=true
951                                 fetchupstream=true
952                         elif [ x"$1" = x"-fu" ]; then
953                                 force=true
954                                 gotoupstream=true
955                         elif [ x"$1" = x"-fU" ]; then
956                                 force=true
957                                 gotoupstream=true
958                                 fetchupstream=true
959                         elif [ x"$1" = x"-m" ]; then
960                                 gotomaster=true
961                         elif [ x"$1" = x"-r" ]; then
962                                 rmuntracked=true
963                         elif [ x"$1" = x"-D" ]; then
964                                 killbranches=true
965                         else
966                                 break
967                         fi
968                         found=true
969                         shift
970                 done
971                 if ! $found; then
972                         rmuntracked=true
973                 fi
974                 for d in $repos; do
975                         verbose cd "$d0/$d"
976                         if $gotoupstream; then
977                                 if ! $force; then
978                                         msg "Must also use -f (delete local changes) when using -u"
979                                         exit 1
980                                 fi
981                                 if $gotomaster; then
982                                         if $fetchupstream; then
983                                                 verbose git fetch origin
984                                                 verbose git remote prune origin
985                                         fi
986                                         verbose git checkout -f "`repobranch "$d"`"
987                                         verbose git reset --hard origin/"`repobranch "$d"`"
988                                 else
989                                         r=`git symbolic-ref HEAD`
990                                         r=${r#refs/heads/}
991                                         rem=`git config "branch.$r.remote" || echo origin`
992                                         bra=`git config "branch.$r.merge" || echo "$r"`
993                                         upstream="$rem/${bra#refs/heads/}"
994                                         if $fetchupstream; then
995                                                 verbose git fetch "$rem"
996                                                 verbose git remote prune "$rem"
997                                         fi
998                                         if ! git rev-parse "$upstream" >/dev/null 2>&1; then
999                                                 upstream="origin/`repobranch "$d"`"
1000                                         fi
1001                                         verbose git reset --hard "$upstream"
1002                                 fi
1003                         elif $gotomaster; then
1004                                 if $force; then
1005                                         verbose git checkout -f "`repobranch "$d"`"
1006                                         verbose git reset --hard
1007                                 else
1008                                         verbose git checkout "`repobranch "$d"`"
1009                                 fi
1010                         elif $force; then
1011                                 verbose git reset --hard
1012                         fi
1013                         if $rmuntracked; then
1014                                 case "$d" in
1015                                         .)
1016                                                 verbose git clean -df
1017                                                 ;;
1018                                         *)
1019                                                 verbose git clean -xdf
1020                                                 ;;
1021                                 esac
1022                         fi
1023                         if $killbranches; then
1024                                 git for-each-ref --format='%(refname)' refs/heads/ | while IFS= read -r B; do
1025                                         if [ x"$B" != x"`git symbolic-ref HEAD`" ]; then
1026                                                 verbose git branch -D "${B#refs/heads/}"
1027                                         fi
1028                                 done
1029                         fi
1030                 done
1031                 ;;
1032
1033         # release building goes here
1034         release-prepare)
1035                 #"$SELF" each git clean -fxd
1036                 case "$RELEASETYPE" in
1037                         beta)
1038                                 msg "Building a BETA"
1039                                 ;;
1040                         release)
1041                                 msg "Building a RELEASE"
1042                                 ;;
1043                         *)
1044                                 msg "Must either set RELEASETYPE=beta or RELEASETYPE=release"
1045                                 exit 1
1046                                 ;;
1047                 esac
1048                 verbose rm -rf Xonotic Xonotic*.zip
1049                 verbose mkdir -p Xonotic
1050                 if [ -n "$RELEASEDATE" ]; then
1051                         verbose echo "$RELEASEDATE" > Xonotic/stamp.txt
1052                 else
1053                         verbose date +%Y%m%d > Xonotic/stamp.txt
1054                 fi
1055                 verbose git archive --format=tar HEAD -- Docs misc server xonotic-linux-glx.sh xonotic-linux-sdl.sh misc/buildfiles key_0.d0pk | {
1056                         verbose cd Xonotic
1057                         verbose mkdir data fteqcc source source/darkplaces source/fteqcc
1058                         verbose tar xvf -
1059                         verbose rm -rf misc/builddeps
1060                         verbose mv misc/buildfiles/win32/* . || true
1061                         verbose mv misc/buildfiles/win64 bin64 || true
1062                         verbose mv misc/buildfiles/osx/* . || true
1063                         verbose rm -rf misc/buildfiles
1064                         verbose rm -rf misc/pki
1065                 }
1066                 {
1067                         verbose cd darkplaces
1068                         verbose git archive --format=tar HEAD
1069                 } | {
1070                         verbose cd Xonotic/source/darkplaces
1071                         verbose tar xvf -
1072                 }
1073                 {
1074                         verbose cd fteqcc
1075                         verbose git archive --format=tar HEAD
1076                 } | {
1077                         verbose cd Xonotic/source/fteqcc
1078                         verbose tar xvf -
1079                 }
1080                 {
1081                         verbose cd data/xonotic-data.pk3dir
1082                         verbose git archive --format=tar HEAD -- qcsrc Makefile
1083                 } | {
1084                         verbose cd Xonotic/source
1085                         verbose tar xvf -
1086                 }
1087                 rm -f Xonotic/key_15.d0pk
1088                 ;;
1089         release-compile-run)
1090                 host=$1
1091                 buildpath=$2
1092                 maketargets=$3
1093                 makeflags=$4
1094                 srcdir=$5
1095                 depsdir=$6
1096                 targetfiles=$7
1097                 set -x
1098                 if [ -n "$targetfiles" ]; then
1099                         case " $HOSTS_THAT_ARE_DISABLED " in
1100                                 *\ $host\ *)
1101                                         exit
1102                                         ;;
1103                         esac
1104                         case " $HOSTS_THAT_ARE_MYSELF " in
1105                                 *\ $host\ *)
1106                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$buildpath/"
1107                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$buildpath.deps/"
1108                                         verbose ln -snf "$buildpath.deps" "$buildpath/.deps"
1109                                         verbose eval make -C "$buildpath" clean $maketargets $makeflags
1110                                         for f in $targetfiles; do
1111                                                 verbose mv "$buildpath/${f%:*}" "${f##*:}" || true
1112                                         done
1113                                         ;;
1114                                 *)
1115                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$host:$buildpath/"
1116                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$host:$buildpath.deps/"
1117                                         verbose ssh "$host" "ln -snf $buildpath.deps $buildpath/.deps && cd $buildpath && nice -`nice` make clean $maketargets $makeflags"
1118                                         for f in $targetfiles; do
1119                                                 verbose rsync -zvaSHP "$host:$buildpath/${f%:*}" "${f##*:}" || true
1120                                         done
1121                                         ;;
1122                         esac
1123                         # now rebrand the binaries...
1124                         for f in $targetfiles; do
1125                                 #verbose "$d0/misc/tools/rebrand-darkplaces-engine.sh" "${XONOTIC_BRAND:-$d0/misc/tools/xonotic.brand}" "${f##*:}" || true
1126                                 case "$f" in
1127                                         xonotic*.exe)
1128                                                 verbose "$d0/misc/tools/change-icon-of-exe.sh" "$d0/misc/logos/icons_ico/xonotic.ico" "$f"
1129                                                 (
1130                                                         d=`mktemp -d -t rebrand.XXXXXX`
1131                                                         cd "$d"
1132                                                         echo "-mygames" > darkplaces.opt
1133                                                         zip -9r darkplaces.zip darkplaces.opt
1134                                                         cat darkplaces.zip
1135                                                         cd "$d0"
1136                                                         rm -rf "$d"
1137                                                 ) >> "$f"
1138                                                 ;;
1139                                 esac
1140                         done
1141                 fi
1142                 ;;
1143         release-compile)
1144                 suffix=$1
1145                 makeflags=$2
1146                 fteqcc_maketargets=$3
1147                 fteqcc_files=$4
1148                 darkplaces_maketargets=$5
1149                 darkplaces_files=$6
1150                 host=xonotic-build-$suffix
1151                 verbose "$SELF" release-compile-run "$host" /tmp/fteqcc.build."$suffix" "$fteqcc_maketargets" "$makeflags" "Xonotic/source/fteqcc" "$d0/misc/builddeps/dp.$suffix" "$fteqcc_files"
1152                 verbose "$SELF" release-compile-run "$host" /tmp/Darkplaces.build."$suffix" "$darkplaces_maketargets" "$makeflags" "Xonotic/source/darkplaces" "$d0/misc/builddeps/dp.$suffix" "$darkplaces_files"
1153                 ;;
1154         release-engine-win32)
1155                 verbose "$SELF" release-compile win32 \
1156                         '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' \
1157                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc.exe' \
1158                         '' ''
1159                 verbose "$SELF" release-compile win32 \
1160                         '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' \
1161                         '' '' \
1162                         release 'darkplaces.exe:Xonotic/xonotic.exe darkplaces-sdl.exe:Xonotic/xonotic-sdl.exe darkplaces-dedicated.exe:Xonotic/xonotic-dedicated.exe'
1163                 ;;
1164         release-engine-win64)
1165                 verbose "$SELF" release-compile win64 \
1166                         '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' \
1167                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc-x64.exe' \
1168                         'sv-release sdl-release' 'darkplaces-sdl.exe:Xonotic/xonotic-x64-sdl.exe darkplaces-dedicated.exe:Xonotic/xonotic-x64-dedicated.exe'
1169                 verbose "$SELF" release-compile win64 \
1170                         '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' \
1171                         '' '' \
1172                         cl-release 'darkplaces.exe:Xonotic/xonotic-x64.exe'
1173                 ;;
1174         release-engine-osx)
1175                 # gcc on OSX is buggy, needs -fno-reorder-blocks for a release build to succeed
1176                 verbose "$SELF" release-compile osx \
1177                         '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"' \
1178                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.osx' \
1179                         'sv-release sdl-release' 'darkplaces-sdl:Xonotic/Xonotic-SDL.app/Contents/MacOS/xonotic-osx-sdl-bin darkplaces-dedicated:Xonotic/xonotic-osx-dedicated'
1180                 verbose "$SELF" release-compile osx \
1181                         '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"' \
1182                         '' '' \
1183                         'cl-release' 'darkplaces-agl:Xonotic/Xonotic.app/Contents/MacOS/xonotic-osx-agl-bin'
1184                 ;;
1185         release-engine-linux32)
1186                 verbose "$SELF" release-compile linux32 \
1187                         'STRIP=: CC="gcc -m32 -g -I.deps/include -L.deps/lib -DSUPPORTIPV6" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a DP_CRYPTO_STATIC_LIBDIR=.deps/lib' \
1188                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux32' \
1189                         release 'darkplaces-glx:Xonotic/xonotic-linux32-glx darkplaces-sdl:Xonotic/xonotic-linux32-sdl darkplaces-dedicated:Xonotic/xonotic-linux32-dedicated'
1190                 ;;
1191         release-engine-linux64)
1192                 verbose "$SELF" release-compile linux64 \
1193                         'STRIP=: CC="gcc -m64 -g -I.deps/include -L.deps/lib -DSUPPORTIPV6" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a DP_CRYPTO_STATIC_LIBDIR=.deps/lib' \
1194                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux64' \
1195                         release 'darkplaces-glx:Xonotic/xonotic-linux64-glx darkplaces-sdl:Xonotic/xonotic-linux64-sdl darkplaces-dedicated:Xonotic/xonotic-linux64-dedicated'
1196                 ;;
1197         release-engine)
1198                 verbose "$SELF" release-engine-linux32 &
1199                 verbose "$SELF" release-engine-linux64 &
1200                 verbose "$SELF" release-engine-win32 &
1201                 verbose "$SELF" release-engine-win64 &
1202                 verbose "$SELF" release-engine-osx &
1203                 wait %1
1204                 wait %2
1205                 wait %3
1206                 wait %4
1207                 wait %5
1208                 wait
1209                 ;;
1210         release-maps)
1211                 verbose "$SELF" update-maps
1212                 ;;
1213         release-qc)
1214                 case "$RELEASETYPE" in
1215                         beta)
1216                                 verbose make -C Xonotic/source FTEQCC="$d0/Xonotic/fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 clean all
1217                                 ;;
1218                         release)
1219                                 verbose make -C Xonotic/source FTEQCC="$d0/Xonotic/fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 FTEQCCFLAGS_WATERMARK= clean all
1220                                 ;;
1221                 esac
1222                 verbose rm -f Xonotic/source/*/fteqcc.log
1223                 ;;
1224         release-buildpk3-transform-raw)
1225                 dir=$1
1226                 ;;
1227         release-buildpk3-transform-normal)
1228                 dir=$1
1229                 verbose cd "$dir"
1230                 # texture: convert to jpeg and dds
1231                 verbose export do_jpeg=true
1232                 verbose export jpeg_qual_rgb=95
1233                 verbose export jpeg_qual_a=99
1234                 verbose export do_dds=true
1235                 verbose export dds_flags=
1236                 verbose export do_ogg=false
1237                 verbose export del_src=true
1238                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1239                 ;;
1240         release-buildpk3-transform-low)
1241                 dir=$1
1242                 verbose cd "$dir"
1243                 # texture: convert to jpeg and dds
1244                 # music: reduce bitrate
1245                 verbose export do_jpeg=true
1246                 verbose export jpeg_qual_rgb=80
1247                 verbose export jpeg_qual_a=95
1248                 verbose export do_dds=false
1249                 verbose export do_ogg=true
1250                 verbose export ogg_qual=1
1251                 verbose export del_src=true
1252                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1253                 ;;
1254         release-buildpk3-transform-lowdds)
1255                 dir=$1
1256                 verbose cd "$dir"
1257                 # texture: convert to jpeg and dds
1258                 # music: reduce bitrate
1259                 verbose export do_jpeg=false
1260                 verbose export do_jpeg_if_not_dds=true
1261                 verbose export jpeg_qual_rgb=80
1262                 verbose export jpeg_qual_a=95
1263                 verbose export do_dds=true
1264                 verbose export dds_flags=
1265                 verbose export do_ogg=true
1266                 verbose export ogg_qual=1
1267                 verbose export del_src=true
1268                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1269                 ;;
1270         release-buildpk3)
1271                 src=$1
1272                 dst=$2
1273                 transform=$3
1274                 case "$dst" in
1275                         /*)
1276                                 ;;
1277                         */)
1278                                 dst="$PWD/$dst"
1279                                 ;;
1280                 esac
1281                 verbose rm -rf Xonotic/temp
1282                 verbose mkdir -p Xonotic/temp
1283                 {
1284                         verbose cd "$src"
1285                         verbose git archive --format=tar HEAD
1286                 } | {
1287                         verbose cd Xonotic/temp
1288                         verbose tar xvf -
1289                 }
1290                 verbose cd Xonotic/temp
1291                 if [ x"$src" = x"data/xonotic-data.pk3dir" ]; then
1292                         verbose cp ../source/progs.dat .
1293                         verbose cp ../source/csprogs.dat .
1294                         verbose cp ../source/menu.dat .
1295                         verbose rm -rf qcsrc
1296                         gv=`grep "^gameversion " "defaultXonotic.cfg" | awk '{ print $2 }'`
1297                         major=$(($gv / 10000))
1298                         minor=$(($gv / 100 - $major * 100))
1299                         patch=$(($gv - $major * 10000 - $minor * 100))
1300                         versionstr="$major.$minor.$patch"
1301                         case "$RELEASETYPE" in
1302                                 beta)
1303                                         versionstr="$versionstr""beta"
1304                                         ;;
1305                         esac
1306                         verbose sed -i "
1307                                 s/^set g_xonoticversion [^ ]* /set g_xonoticversion $versionstr /;
1308                                 s/^gameversion_min [0-9]*/gameversion_min $(( ($gv / 100) * 100 - 100 ))/;
1309                                 s/^gameversion_max [0-9]*/gameversion_max $(( ($gv / 100) * 100 + 199 ))/;
1310                         " defaultXonotic.cfg
1311                         (
1312                                 verbose cd gfx/menu/luminos
1313                                 verbose cp "$d0"/mediasource/gfx/menu/luminos_versionbuilder/background_l2.svg .
1314                                 verbose "$d0"/mediasource/gfx/menu/luminos_versionbuilder/versionbuilder "$versionstr"
1315                                 verbose rm background_l2.svg
1316                         )
1317                 fi
1318                 if [ x"$src" = x"data/xonotic-maps.pk3dir" ]; then
1319                         for X in ../../data/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
1320                                 if [ -f "$X" ]; then
1321                                         verbose unzip "$X"
1322                                         verbose rm -f maps/*.log maps/*.irc maps/*.lin
1323                                 fi
1324                         done
1325                 fi
1326                 verbose export git_src_repo="$d0/$src" # skip hash-object
1327                 verbose "$SELF" release-buildpk3-transform-$transform "Xonotic/temp"
1328                 verbose mkzip "../../$dst" *
1329                 verbose cd ../..
1330                 verbose rm -rf Xonotic/temp
1331                 ;;
1332         release-buildpk3s)
1333                 stamp=`cat Xonotic/stamp.txt`
1334                 src=$1
1335                 shift
1336                 dst=${src%.pk3dir}
1337                 case "$dst" in
1338                         data/xonotic-*)
1339                                 dst="data/xonotic-$stamp-${dst#data/xonotic-}"
1340                                 ;;
1341                         *)
1342                                 dst="$dst-$stamp"
1343                                 ;;
1344                 esac
1345                 while [ "$#" -gt 1 ]; do
1346                         verbose "$SELF" release-buildpk3 "$src" "Xonotic/$dst$2.pk3" "$1"
1347                         shift
1348                         shift
1349                 done
1350                 ;;
1351         release-pack)
1352                 verbose "$SELF" release-buildpk3s data/font-nimbussansl.pk3dir             raw ''
1353                 verbose "$SELF" release-buildpk3s data/xonotic-data.pk3dir       normal '' raw '-raw' low '-low' lowdds '-lowdds'
1354                 verbose "$SELF" release-buildpk3s data/xonotic-maps.pk3dir       normal '' raw '-raw' low '-low' lowdds '-lowdds'
1355                 verbose "$SELF" release-buildpk3s data/xonotic-music.pk3dir                raw ''     low '-low'
1356                 verbose "$SELF" release-buildpk3s data/xonotic-nexcompat.pk3dir                       low ''
1357                 ;;
1358         release-pack-needsx11)
1359                 case "$DISPLAY" in
1360                         '')
1361                                 verbose startx "$SELF" release-pack -- /usr/bin/Xvfb :7
1362                                 ;;
1363                         *)
1364                                 verbose "$SELF" release-pack
1365                                 ;;
1366                 esac
1367                 ;;
1368         release-zip)
1369                 stamp=`cat Xonotic/stamp.txt`
1370                 # exe and dll files do not need +x, so this makes them eligible for 7zip compression too
1371                 chmod a-x Xonotic/*.exe Xonotic/*.dll || true
1372                 # let's pass crypto import laws of some nasty countries
1373                 crypto_libs=`find Xonotic -name \*d0_rijndael\*`
1374                 if [ -n "$crypto_libs" ]; then
1375                         verbose mkzip Xonotic-$stamp-crypto.zip \
1376                                 $crypto_libs
1377                         rm -f $crypto_libs
1378                 fi
1379                 # build the archives
1380                 verbose mkzip Xonotic-$stamp-engine.zip \
1381                         Xonotic/*.dll \
1382                         Xonotic/bin64/*.dll \
1383                         Xonotic/*.app \
1384                         Xonotic/xonotic-* \
1385                         Xonotic/xonotic.exe \
1386                         Xonotic/source/darkplaces/
1387                 verbose cp Xonotic-$stamp-engine.zip Xonotic-$stamp-common.zip
1388                 verbose mkzip Xonotic-$stamp-common.zip \
1389                         Xonotic/source/fteqcc/ \
1390                         Xonotic/source/qcsrc/ \
1391                         Xonotic/Docs \
1392                         Xonotic/misc \
1393                         Xonotic/fteqcc \
1394                         Xonotic/server \
1395                         Xonotic/key_0.d0pk \
1396                         Xonotic/data/font-nimbussansl-$stamp.pk3
1397                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp.zip
1398                 verbose mkzip0 Xonotic-$stamp.zip \
1399                         Xonotic/data/xonotic-$stamp-data.pk3 \
1400                         Xonotic/data/xonotic-$stamp-maps.pk3 \
1401                         Xonotic/data/xonotic-$stamp-music.pk3 \
1402                         Xonotic/data/xonotic-$stamp-nexcompat.pk3
1403                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-low.zip
1404                 verbose mkzip0 Xonotic-$stamp-low.zip \
1405                         Xonotic/data/xonotic-$stamp-data-low.pk3 \
1406                         Xonotic/data/xonotic-$stamp-maps-low.pk3 \
1407                         Xonotic/data/xonotic-$stamp-music-low.pk3
1408                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-lowdds.zip
1409                 verbose mkzip0 Xonotic-$stamp-lowdds.zip \
1410                         Xonotic/data/xonotic-$stamp-data-lowdds.pk3 \
1411                         Xonotic/data/xonotic-$stamp-maps-lowdds.pk3 \
1412                         Xonotic/data/xonotic-$stamp-music-low.pk3
1413                 verbose mv Xonotic-$stamp-common.zip Xonotic-$stamp-high.zip
1414                 verbose mkzip0 Xonotic-$stamp-high.zip \
1415                         Xonotic/data/xonotic-$stamp-data-raw.pk3 \
1416                         Xonotic/data/xonotic-$stamp-maps-raw.pk3 \
1417                         Xonotic/data/xonotic-$stamp-music.pk3 \
1418                         Xonotic/data/xonotic-$stamp-nexcompat.pk3
1419                 ;;
1420         release)
1421                 verbose "$SELF" release-prepare
1422                 verbose "$SELF" release-maps
1423                 verbose "$SELF" release-engine
1424                 verbose "$SELF" release-qc
1425                 verbose "$SELF" release-pack-needsx11
1426                 verbose "$SELF" release-zip
1427                 ;;
1428
1429         *)
1430                 echo "Usage:"
1431                 echo "  $SELF admin-merge [<branch>]"
1432                 echo "  $SELF branch <branch>"
1433                 echo "  $SELF branch <remote> <branch> [<srcbranch>]"
1434                 echo "  $SELF branches"
1435                 echo "  $SELF checkout|switch <branch>"
1436                 echo "  $SELF checkout|switch <remote>/<branch>"
1437                 echo "  $SELF clean [-m] [-f | -fu | -fU] [-r] [-D]"
1438                 echo "  $SELF clean --reclone"
1439                 echo "  $SELF compile [-c]"
1440                 echo "  $SELF each|foreach [-k] command..."
1441                 echo "  $SELF fix_upstream_rebase"
1442                 echo "  $SELF merge"
1443                 echo "  $SELF push|commit [-s]"
1444                 echo "  $SELF release"
1445                 echo "  $SELF restore-patches"
1446                 echo "  $SELF run [sdl|glx|wgl|agl|dedicated] options..."
1447                 echo "  $SELF save-patches"
1448                 echo "  $SELF update-maps"
1449                 echo "  $SELF update|pull [-N]"
1450                 ;;
1451 esac