Merge branch 'asciiwolf/xonotic-makefile-fix'
[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 case "$0" in
23         /*/all)
24                 export d0="${0%/all}"
25                 ;;
26         */all)
27                 export d0="$d00/${0%/all}"
28                 ;;
29         */all.xonotic.sh)
30                 ;;
31         *)
32                 $ECHO "Cannot find myself."
33                 $ECHO "Please run this script with the working directory inside a Xonotic checkout."
34                 ;;
35 esac
36 cd "$d0"
37 d0=`pwd`
38 SELF="$d0/all"
39
40 # If we are on WINDOWS:
41 case "$0" in
42         all|*/all)
43                 case "`uname`" in
44                         MINGW*|Win*)
45                                 # Windows hates users. So this script has to copy itself elsewhere first...
46                                 cp "$SELF" ../all.xonotic.sh
47                                 export WE_HATE_OUR_USERS=1
48                                 exec ../all.xonotic.sh "$@"
49                                 ;;
50                 esac
51                 ;;
52 esac
53
54 msg()
55 {
56         $ECHO >&2 "$ESC""[1m$*$ESC""[m"
57 }
58
59 self=`git hash-object "$SELF"`
60 checkself()
61 {
62         self_new=`git hash-object "$SELF"`
63         if [ x"$self" != x"$self_new" ]; then
64                 msg "./all has changed."
65                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
66                         msg "Rerunning the requested operation to make sure."
67                         export XONOTIC_FORBID_RERUN_ALL=1
68                         exec "$SELF" "$@"
69                 else
70                         msg "Please try $SELF update, and then retry your requested operation."
71                         exit 1
72                 fi
73         fi
74         return 0
75 }
76
77 verbose()
78 {
79         msg "+ $*"
80         "$@"
81 }
82
83 yesno()
84 {
85         yesno=
86         while [ x"$yesno" != x"y" -a x"$yesno" != x"n" ]; do
87                 eval "$2"
88                 $ECHO "$1"
89                 if ! IFS= read -r yesno; then
90                         yesno=n
91                         break
92                 fi
93         done
94         [ x"$yesno" = x"y" ]
95 }
96
97 enter()
98 {
99         $2 cd "$1" || exit 1
100         check_mergeconflict "$1" # defined in git.subr
101 }
102
103 if [ "$#" = 0 ]; then
104         set -- help
105 fi
106 cmd=$1
107 shift
108
109 # project config
110 . "$d0/misc/tools/all/config.subr"
111
112 # shared commands
113 handled=false
114 . "$d0/misc/tools/all/git.subr" "$@"
115
116 # optional modules
117 $handled || . "$d0/misc/tools/all/release.subr" "$@"
118 $handled || . "$d0/misc/tools/all/xonotic.subr" "$@"
119
120 if ! $handled; then
121         if [ x"$cmd" != x"help" ]; then
122                 $ECHO "Run $SELF help for help."
123                 exit 1
124         fi
125 fi