]> de.git.xonotic.org Git - xonotic/xonotic.git/blob - all
Detect calling "all" via e.g. ../../all and chdir where it SHOULD be
[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 case "$0" in
55         */*)
56                 cd "${0%/*}"
57                 ;;
58 esac
59
60 d0=`pwd`
61 case "$cmd" in
62         update|pull)
63                 base=`git config remote.origin.url`
64                 base=${base%xonotic.git}
65                 for dcomplete in $repos_urls; do
66                         case "$dcomplete" in
67                                 *@*)
68                                         d=${dcomplete%%@*}
69                                         url=${dcomplete#*@}
70                                         switch=false
71                                         ;;
72                                 *)
73                                         d=${dcomplete%%@*}
74                                         url=$base${d##*/}.git
75                                         switch=true
76                                         ;;
77                         esac
78                         if [ -d "$d0/$d" ]; then
79                                 verbose cd "$d0/$d"
80                                 case "$d" in
81                                         .)
82                                                 ;;
83                                         *)
84                                                 if $switch; then
85                                                         verbose git config remote.origin.url "$url"
86                                                 fi
87                                                 ;;
88                                 esac
89                                 verbose git pull
90                                 cd "$d0"
91                                 checkself "$0" "$@"
92                                 cd "$d0/$d"
93                                 verbose git remote prune origin
94                                 cd "$d0"
95                         else
96                                 verbose git clone "$url" "$d0/$d"
97                         fi
98                 done
99                 ;;
100         checkout|switch)
101                 remote=$1
102                 branch=$2
103                 if [ -z "$branch" ]; then
104                         branch=$remote
105                         remote=origin
106                 fi
107                 exists=false
108                 for d in $repos; do
109                         verbose cd "$d0/$d"
110                         if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
111                                 exists=true
112                                 verbose git checkout "$branch"
113                         elif git rev-parse "refs/remotes/$remote/$branch" >/dev/null 2>&1; then
114                                 exists=true
115                                 verbose git checkout --track -b "$branch" "$remote/$branch"
116                         else
117                                 verbose git checkout master
118                         fi
119                         cd "$d0"
120                         checkself "$0" "$@"
121                 done
122                 if ! $exists; then
123                         echo "The requested branch was not found in any repository."
124                 fi
125                 "$0" branch
126                 ;;
127         branch)
128                 remote=$1
129                 branch=$2
130                 if [ -z "$branch" ]; then
131                         branch=$remote
132                         remote=origin
133                 fi
134                 if [ -z "$branch" ]; then
135                         for d in $repos; do
136                                 cd "$d0/$d"
137                                 r=`git symbolic-ref HEAD`
138                                 r=${r#refs/heads/}
139                                 echo "$d is at $r"
140                                 cd "$d0"
141                         done
142                 else
143                         for d in $repos; do
144                                 cd "$d0/$d"
145                                 a=
146                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
147                                         echo "Branch in \"$d\"?"
148                                         read -r a
149                                 done
150                                 if [ x"$a" = x"y" ]; then
151                                         verbose git push "$remote" HEAD:"$branch"
152                                         verbose git checkout --track -b "$branch" "$remote/$branch"
153                                 fi
154                                 cd "$d0"
155                         done
156                         "$0" branch
157                 fi
158                 ;;
159         branches)
160                 for d in $repos; do
161                         cd "$d0/$d"
162                         echo "In $d:"
163                         git branch -a | sed 's/^/  /; /->/d'
164                         cd "$d0"
165                 done
166                 ;;
167         push)
168                 for d in $repos; do
169                         cd "$d0/$d"
170                         r=`git symbolic-ref HEAD`
171                         r=${r#refs/heads/}
172                         if git diff HEAD | grep .; then
173                                 # we have uncommitted changes
174                                 a=
175                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
176                                         echo "Uncommitted changes in \"$r\" in \"$d\". Commit?"
177                                         read -r a
178                                 done
179                                 if [ x"$a" = x"y" ]; then
180                                         verbose git commit -a
181                                 fi
182                         fi
183                         if git log "origin/$r".."$r" | grep .; then
184                                 a=
185                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
186                                         echo "Push \"$r\" in \"$d\"?"
187                                         read -r a
188                                 done
189                                 if [ x"$a" = x"y" ]; then
190                                         verbose git push `git config "branch.$r.remote" || echo origin` HEAD
191                                 fi
192                         fi
193                         cd "$d0"
194                 done
195                 ;;
196         compile)
197                 if [ -z "$MAKEFLAGS" ]; then
198                         if [ -f /proc/cpuinfo ]; then
199                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
200                                 if [ $ncpus -gt 1 ]; then
201                                         MAKEFLAGS=-j$ncpus
202                                 fi
203                         fi
204                 fi
205                 verbose cd "$d0/fteqcc"
206                 verbose make $MAKEFLAGS
207                 verbose cd "$d0/data/xonotic-data.pk3dir"
208                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" $MAKEFLAGS
209                 verbose cd "$d0/darkplaces"
210                 verbose make $MAKEFLAGS sv-debug
211                 verbose make $MAKEFLAGS cl-debug
212                 verbose make $MAKEFLAGS sdl-debug
213                 ;;
214         run)
215                 client=-sdl
216                 case "$1" in
217                         sdl|glx|agl|dedicated)
218                                 client=-$1
219                                 shift
220                                 ;;
221                         wgl)
222                                 client=
223                                 shift
224                                 ;;
225                 esac
226                 if ! [ -x "darkplaces/darkplaces$client" ]; then
227                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
228                                 client=$client.exe
229                         else
230                                 echo "Client darkplaces/darkplaces$client not found, aborting"
231                                 exit 1
232                         fi
233                 fi
234                 #verbose "darkplaces/darkplaces$client" -xonotic "$@"
235                 verbose "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
236                 ;;
237         each|foreach)
238                 for d in $repos; do
239                         verbose cd "$d0/$d"
240                         verbose "$@"
241                         cd "$d0"
242                 done
243                 ;;
244         *)
245                 echo "Usage:"
246                 echo "  $0 pull"
247                 echo "  $0 push"
248                 echo "  $0 branches"
249                 echo "  $0 branch <remote> <branchname>"
250                 echo "  $0 checkout"
251                 echo "  $0 compile"
252                 echo "  $0 run <client> <options>"
253                 echo "  $0 each <command>"
254                 ;;
255 esac