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