Binaural synthesis (confbridge): Adds utils/conf_bridge_binaural_hrir_importer
[asterisk/asterisk.git] / build_tools / make_version
1 #!/bin/sh
2
3 AWK=${AWK:-awk}
4 GIT=${GIT:-git}
5 GREP=${GREP:-grep}
6 MAINLINE_BRANCH=master
7
8 if [ -f ${1}/.version ]; then
9     cat ${1}/.version
10 elif [ -d ${1}/.svn ]; then
11     PARTS=`LANG=C svn info ${1} | ${GREP} URL | ${AWK} '{print $2;}' | sed -e 's:^.*/svn/asterisk/::' | sed -e 's:/: :g'`
12     BRANCH=0
13     TEAM=0
14     TAG=0
15     FEATURE=0
16
17     REV=`svnversion -c ${1} | cut -d: -f2`
18
19     INTEGRATED=`LANG=C svn pg automerge-propname ${1}`
20     if [ -z "${INTEGRATED}" ] ; then
21         INTEGRATED=svnmerge-integrated
22     fi
23
24     BASE=`LANG=C svn pg ${INTEGRATED} ${1} | cut -d: -f1`
25
26     if [ "${PARTS}" = "trunk" ] ; then
27         echo SVN-trunk-r${REV}
28         exit 0
29     fi
30
31     for PART in $PARTS ; do
32         if [ ${TAG} != 0 ] ; then
33             if [ "${PART}" = "autotag_for_be" ] ; then
34                 continue
35             fi
36             if [ "${PART}" = "autotag_for_sx00i" ] ; then
37                 continue
38             fi
39             RESULT="${PART}"
40             break
41         fi
42
43         if [ ${BRANCH} != 0 ] ; then
44             RESULT="${RESULT}-${PART}"
45             if [ ${FEATURE} != 0 ] ; then
46                 RESULT="${RESULT}-${FEATURE_NAME}"
47             fi
48             break
49         fi
50
51         if [ ${TEAM} != 0 ] ; then
52             if [ -z "${RESULT}" ] ; then
53                 RESULT="${PART}"
54             else
55                 RESULT="${RESULT}-${PART}"
56             fi
57             continue
58         fi
59
60         if [ "${PART}" = "certified" ] ; then
61             FEATURE=1
62             FEATURE_NAME="cert"
63             continue
64         fi
65
66         if [ "${PART}" = "branches" ] ; then
67             BRANCH=1
68             RESULT="branch"
69             continue
70         fi
71
72         if [ "${PART}" = "tags" ] ; then
73             TAG=1
74             continue
75         fi
76
77         if [ "${PART}" = "team" ] ; then
78             TEAM=1
79             continue
80         fi
81     done
82
83     if [ ${TAG} != 0 ] ; then
84         echo ${RESULT}
85     else
86         echo SVN-${RESULT}-r${REV}${BASE:+-${BASE}}
87     fi
88 elif [ -d ${1}/.git ]; then
89     if [ -z ${GIT} ]; then
90         GIT="git"
91     fi
92         
93     if ! command -v ${GIT} >/dev/null 2>&1; then
94         echo "UNKNOWN__and_probably_unsupported"
95         exit 1
96     fi
97         cd ${1} 
98     
99     # If the first log commit messages indicates that this is checked into
100     # subversion, we'll just use the SVN- form of the revision.
101     MODIFIED=""
102     SVN_REV=`${GIT} log --pretty=full -1 | ${GREP} -F "git-svn-id:" | sed -e "s/.*\@\([^\s]*\)\s.*/\1/g"`
103     if [ -z "$SVN_REV" ]; then
104         VERSION=`${GIT} describe --long --always --tags --dirty=M 2> /dev/null`
105         if [ $? -ne 0 ]; then
106             if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then
107                 MODIFIED="M"
108             fi
109             # Some older versions of git do not support all the above
110             # options.
111             VERSION=`${GIT} rev-parse --short --verify HEAD`${MODIFIED}
112         fi
113         echo GIT-${MAINLINE_BRANCH}-${VERSION}
114     else
115         PARTS=`LANG=C ${GIT} log --pretty=full | ${GREP} -F "git-svn-id:" | head -1 | ${AWK} '{print $2;}' | sed -e s:^.*/svn/$2/:: | sed -e 's:/: :g' | sed -e 's/@.*$//g'`
116         BRANCH=0
117         TEAM=0
118         TAG=0
119         FEATURE=0
120
121         if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then
122             MODIFIED="M"
123         fi
124
125         for PART in $PARTS ; do
126             if [ ${TAG} != 0 ] ; then
127                 if [ "${PART}" = "autotag_for_be" ] ; then
128                     continue
129                 fi
130                 if [ "${PART}" = "autotag_for_sx00i" ] ; then
131                     continue
132                 fi
133                 RESULT="${PART}"
134                 break
135             fi
136
137             if [ ${BRANCH} != 0 ] ; then
138                 RESULT="${RESULT}-${PART}"
139                 if [ ${FEATURE} != 0 ] ; then
140                     RESULT="${RESULT}-${FEATURE_NAME}"
141                 fi
142                 break
143             fi
144
145             if [ ${TEAM} != 0 ] ; then
146                 if [ -z "${RESULT}" ] ; then
147                     RESULT="${PART}"
148                 else
149                     RESULT="${RESULT}-${PART}"
150                 fi
151                 continue
152             fi
153
154             if [ "${PART}" = "certified" ] ; then
155                 FEATURE=1
156                 FEATURE_NAME="cert"
157                 continue
158             fi
159
160             if [ "${PART}" = "branches" ] ; then
161                 BRANCH=1
162                 RESULT="branch"
163                 continue
164             fi
165
166             if [ "${PART}" = "tags" ] ; then
167                 TAG=1
168                 continue
169             fi
170
171             if [ "${PART}" = "team" ] ; then
172                 TEAM=1
173                 continue
174             fi
175
176             if [ "${PART}" = "trunk" ]; then
177                 echo SVN-trunk-r${SVN_REV}${MODIFIED}
178                 exit 0
179             fi
180         done
181
182         if [ ${TAG} != 0 ] ; then
183             echo ${RESULT}
184         else
185             echo SVN-${RESULT##-}-r${SVN_REV}${MODIFIED}
186         fi
187     fi
188 else
189     echo "UNKNOWN__and_probably_unsupported"
190 fi