Merge "rtp_engine.h: Remove extraneous semicolons."
[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     # If the first log commit messages indicates that this is checked into
98     # subversion, we'll just use the SVN- form of the revision.
99     MODIFIED=""
100     SVN_REV=`${GIT} log --pretty=full -1 | ${GREP} -F "git-svn-id:" | sed -e "s/.*\@\([^\s]*\)\s.*/\1/g"`
101     if [ -z "$SVN_REV" ]; then
102         VERSION=`${GIT} describe --long --always --tags --dirty=M 2> /dev/null`
103         if [ $? -ne 0 ]; then
104             if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then
105                 MODIFIED="M"
106             fi
107             # Some older versions of git do not support all the above
108             # options.
109             VERSION=`${GIT} rev-parse --short --verify HEAD`${MODIFIED}
110         fi
111         echo GIT-${MAINLINE_BRANCH}-${VERSION}
112     else
113         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'`
114         BRANCH=0
115         TEAM=0
116         TAG=0
117         FEATURE=0
118
119         if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then
120             MODIFIED="M"
121         fi
122
123         for PART in $PARTS ; do
124             if [ ${TAG} != 0 ] ; then
125                 if [ "${PART}" = "autotag_for_be" ] ; then
126                     continue
127                 fi
128                 if [ "${PART}" = "autotag_for_sx00i" ] ; then
129                     continue
130                 fi
131                 RESULT="${PART}"
132                 break
133             fi
134
135             if [ ${BRANCH} != 0 ] ; then
136                 RESULT="${RESULT}-${PART}"
137                 if [ ${FEATURE} != 0 ] ; then
138                     RESULT="${RESULT}-${FEATURE_NAME}"
139                 fi
140                 break
141             fi
142
143             if [ ${TEAM} != 0 ] ; then
144                 if [ -z "${RESULT}" ] ; then
145                     RESULT="${PART}"
146                 else
147                     RESULT="${RESULT}-${PART}"
148                 fi
149                 continue
150             fi
151
152             if [ "${PART}" = "certified" ] ; then
153                 FEATURE=1
154                 FEATURE_NAME="cert"
155                 continue
156             fi
157
158             if [ "${PART}" = "branches" ] ; then
159                 BRANCH=1
160                 RESULT="branch"
161                 continue
162             fi
163
164             if [ "${PART}" = "tags" ] ; then
165                 TAG=1
166                 continue
167             fi
168
169             if [ "${PART}" = "team" ] ; then
170                 TEAM=1
171                 continue
172             fi
173
174             if [ "${PART}" = "trunk" ]; then
175                 echo SVN-trunk-r${SVN_REV}${MODIFIED}
176                 exit 0
177             fi
178         done
179
180         if [ ${TAG} != 0 ] ; then
181             echo ${RESULT}
182         else
183             echo SVN-${RESULT##-}-r${SVN_REV}${MODIFIED}
184         fi
185     fi
186 else
187     echo "UNKNOWN__and_probably_unsupported"
188 fi