]> git.xonotic.org Git - xonotic/xonotic.git/blob - all
b052023cd46c7b7bcba0feaaf6673d911806f176
[xonotic/xonotic.git] / all
1 #!/bin/sh
2
3 set -e
4
5 msg()
6 {
7         echo "\e[1m$*\e[m"
8 }
9
10 self=`cksum "$0"`
11 checkself()
12 {
13         self_new=`cksum "$0"`
14         if [ x"$self" != x"$self_new" ]; then
15                 msg "./all has changed."
16                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
17                         msg "Rerunning the requested operation to make sure."
18                         export XONOTIC_FORBID_RERUN_ALL=1
19                         exec "$0" "$@"
20                 else
21                         msg "Please try $0 update, and then retry your requested operation."
22                         exit 1
23                 fi
24         fi
25         return 0
26 }
27
28 verbose()
29 {
30         msg "+ $*"
31         "$@"
32 }
33
34 repos_urls="
35         .
36         data/xonotic-data.pk3dir
37         data/xonotic-maps.pk3dir
38         data/xonotic-music.pk3dir
39         data/xonotic-nexcompat.pk3dir
40         darkplaces
41         fteqcc@git://github.com/Blub/qclib.git
42         div0-gittools@git://git.icculus.org/divverent/div0-gittools.git
43         netradiant
44 "
45
46 repos=`for X in $repos_urls; do echo "${X%%@*}"; done`
47
48 if [ "$#" = 0 ]; then
49         set -- help
50 fi
51 cmd=$1
52 shift
53
54 d0=`pwd`
55 case "$cmd" in
56         update|pull)
57                 base=`git config remote.origin.url`
58                 base=${base%xonotic.git}
59                 for dcomplete in $repos_urls; do
60                         case "$dcomplete" in
61                                 *@*)
62                                         d=${dcomplete%%@*}
63                                         url=${dcomplete#*@}
64                                         switch=false
65                                         ;;
66                                 *)
67                                         d=${dcomplete%%@*}
68                                         url=$base${d##*/}.git
69                                         switch=true
70                                         ;;
71                         esac
72                         if [ -d "$d0/$d" ]; then
73                                 verbose cd "$d0/$d"
74                                 case "$d" in
75                                         .)
76                                                 ;;
77                                         *)
78                                                 if $switch; then
79                                                         verbose git config remote.origin.url "$url"
80                                                 fi
81                                                 ;;
82                                 esac
83                                 verbose git pull
84                                 cd "$d0"
85                                 checkself "$0" "$@"
86                                 cd "$d0/$d"
87                                 verbose git remote prune origin
88                                 cd "$d0"
89                         else
90                                 verbose git clone "$url" "$d0/$d"
91                         fi
92                 done
93                 ;;
94         checkout|switch)
95                 remote=$1
96                 branch=$2
97                 if [ -z "$branch" ]; then
98                         branch=$remote
99                         remote=origin
100                 fi
101                 exists=false
102                 for d in $repos; do
103                         verbose cd "$d0/$d"
104                         if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
105                                 exists=true
106                                 verbose git checkout "$branch"
107                         elif git rev-parse "refs/remotes/$remote/$branch" >/dev/null 2>&1; then
108                                 exists=true
109                                 verbose git checkout --track -b "$branch" "$remote/$branch"
110                         else
111                                 verbose git checkout master
112                         fi
113                         cd "$d0"
114                         checkself "$0" "$@"
115                 done
116                 if ! $exists; then
117                         echo "The requested branch was not found in any repository."
118                 fi
119                 "$0" branch
120                 ;;
121         branch)
122                 remote=$1
123                 branch=$2
124                 if [ -z "$branch" ]; then
125                         branch=$remote
126                         remote=origin
127                 fi
128                 if [ -z "$branch" ]; then
129                         for d in $repos; do
130                                 cd "$d0/$d"
131                                 r=`git symbolic-ref HEAD`
132                                 r=${r#refs/heads/}
133                                 echo "$d is at $r"
134                                 cd "$d0"
135                         done
136                 else
137                         for d in $repos; do
138                                 cd "$d0/$d"
139                                 a=
140                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
141                                         echo "Branch in $d?"
142                                         read -r a
143                                 done
144                                 if [ x"$a" = x"y" ]; then
145                                         verbose git push "$remote" HEAD:"$branch"
146                                         verbose git checkout --track -b "$branch" "$remote/$branch"
147                                 fi
148                                 cd "$d0"
149                         done
150                         "$0" branch
151                 fi
152                 ;;
153         branches)
154                 for d in $repos; do
155                         cd "$d0/$d"
156                         echo "In $d:"
157                         git branch -a | sed 's/^/  /; /->/d'
158                         cd "$d0"
159                 done
160                 ;;
161         push)
162                 for d in $repos; do
163                         cd "$d0/$d"
164                         r=`git symbolic-ref HEAD`
165                         r=${r#refs/heads/}
166                         a=
167                         if git log "origin/$r".."$r" | grep .; then
168                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
169                                         echo "Push $r in $d?"
170                                         read -r a
171                                 done
172                                 if [ x"$a" = x"y" ]; then
173                                         verbose git push `git config "branch.$r.remote" || echo origin` HEAD
174                                 fi
175                         fi
176                         cd "$d0"
177                 done
178                 ;;
179         compile)
180                 if [ -z "$MAKEFLAGS" ]; then
181                         if [ -f /proc/cpuinfo ]; then
182                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
183                                 if [ $ncpus -gt 1 ]; then
184                                         MAKEFLAGS=-j$ncpus
185                                 fi
186                         fi
187                 fi
188                 verbose cd "$d0/fteqcc"
189                 verbose make $MAKEFLAGS
190                 verbose cd "$d0/data/xonotic-data.pk3dir"
191                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" $MAKEFLAGS
192                 verbose cd "$d0/darkplaces"
193                 verbose make $MAKEFLAGS sv-debug
194                 verbose make $MAKEFLAGS cl-debug
195                 verbose make $MAKEFLAGS sdl-debug
196                 ;;
197         run)
198                 client=-sdl
199                 case "$1" in
200                         sdl|glx|agl|dedicated)
201                                 client=-$1
202                                 shift
203                                 ;;
204                         wgl)
205                                 client=
206                                 shift
207                                 ;;
208                 esac
209                 if ! [ -x "darkplaces/darkplaces$client" ]; then
210                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
211                                 client=$client.exe
212                         else
213                                 echo "Client darkplaces/darkplaces$client not found, aborting"
214                                 exit 1
215                         fi
216                 fi
217                 #verbose "darkplaces/darkplaces$client" -xonotic "$@"
218                 verbose "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
219                 ;;
220         each|foreach)
221                 for d in $repos; do
222                         verbose cd "$d0/$d"
223                         verbose "$@"
224                         cd "$d0"
225                 done
226                 ;;
227         *)
228                 echo "Usage:"
229                 echo "  $0 pull"
230                 echo "  $0 push"
231                 echo "  $0 branches"
232                 echo "  $0 branch <remote> <branchname>"
233                 echo "  $0 checkout"
234                 echo "  $0 compile"
235                 echo "  $0 run <client> <options>"
236                 echo "  $0 each <command>"
237                 ;;
238 esac