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