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