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