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