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