828f67d71bff0ac650b7bc5d981d1dc470d9b0fa
[ira/wip.git] / source / script / mkversion.sh
1 #!/bin/sh
2
3 VERSION_FILE=$1
4 OUTPUT_FILE=$2
5
6 if test -z "$VERSION_FILE";then
7         VERSION_FILE="VERSION"
8 fi
9
10 if test -z "$OUTPUT_FILE";then
11         OUTPUT_FILE="version.h"
12 fi
13
14 SOURCE_DIR=$3
15
16 SAMBA_VERSION_MAJOR=`sed -n 's/^SAMBA_VERSION_MAJOR=//p' $SOURCE_DIR$VERSION_FILE`
17 SAMBA_VERSION_MINOR=`sed -n 's/^SAMBA_VERSION_MINOR=//p' $SOURCE_DIR$VERSION_FILE`
18 SAMBA_VERSION_RELEASE=`sed -n 's/^SAMBA_VERSION_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
19
20 SAMBA_VERSION_REVISION=`sed -n 's/^SAMBA_VERSION_REVISION=//p' $SOURCE_DIR$VERSION_FILE`
21
22 SAMBA_VERSION_TP_RELEASE=`sed -n 's/^SAMBA_VERSION_TP_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
23 SAMBA_VERSION_ALPHA_RELEASE=`sed -n 's/^SAMBA_VERSION_ALPHA_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
24 SAMBA_VERSION_PRE_RELEASE=`sed -n 's/^SAMBA_VERSION_PRE_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
25 SAMBA_VERSION_RC_RELEASE=`sed -n 's/^SAMBA_VERSION_RC_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
26
27 SAMBA_VERSION_IS_SVN_SNAPSHOT=`sed -n 's/^SAMBA_VERSION_IS_SVN_SNAPSHOT=//p' $SOURCE_DIR$VERSION_FILE`
28
29 SAMBA_VERSION_RELEASE_NICKNAME=`sed -n 's/^SAMBA_VERSION_RELEASE_NICKNAME=//p' $SOURCE_DIR$VERSION_FILE`
30
31 SAMBA_VERSION_VENDOR_SUFFIX=`sed -n 's/^SAMBA_VERSION_VENDOR_SUFFIX=//p' $SOURCE_DIR$VERSION_FILE`
32 SAMBA_VERSION_VENDOR_PATCH=`sed -n 's/^SAMBA_VERSION_VENDOR_PATCH=//p' $SOURCE_DIR$VERSION_FILE`
33
34 echo "/* Autogenerated by script/mkversion.sh */" > $OUTPUT_FILE
35
36 echo "#define SAMBA_VERSION_MAJOR ${SAMBA_VERSION_MAJOR}" >> $OUTPUT_FILE
37 echo "#define SAMBA_VERSION_MINOR ${SAMBA_VERSION_MINOR}" >> $OUTPUT_FILE
38 echo "#define SAMBA_VERSION_RELEASE ${SAMBA_VERSION_RELEASE}" >> $OUTPUT_FILE
39
40
41 ##
42 ## start with "3.0.22"
43 ##
44 SAMBA_VERSION_STRING="${SAMBA_VERSION_MAJOR}.${SAMBA_VERSION_MINOR}.${SAMBA_VERSION_RELEASE}"
45
46
47 ##
48 ## maybe add "3.0.22a" or "4.0.0tp11" or "4.0.0alpha1" or "3.0.22pre1" or "3.0.22rc1"
49 ## We do not do pre or rc version on patch/letter releases
50 ##
51 if test -n "${SAMBA_VERSION_REVISION}";then
52     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}${SAMBA_VERSION_REVISION}"
53     echo "#define SAMBA_VERSION_REVISION \"${SAMBA_VERSION_REVISION}\"" >> $OUTPUT_FILE
54 elif test -n "${SAMBA_VERSION_TP_RELEASE}";then
55     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}tp${SAMBA_VERSION_TP_RELEASE}"
56     echo "#define SAMBA_VERSION_TP_RELEASE ${SAMBA_VERSION_TP_RELEASE}" >> $OUTPUT_FILE
57 elif test -n "${SAMBA_VERSION_ALPHA_RELEASE}";then
58     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}alpha${SAMBA_VERSION_ALPHA_RELEASE}"
59     echo "#define SAMBA_VERSION_ALPHA_RELEASE ${SAMBA_VERSION_ALPHA_RELEASE}" >> $OUTPUT_FILE
60 elif test -n "${SAMBA_VERSION_PRE_RELEASE}";then
61     ## maybe add "3.0.22pre2"
62     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}pre${SAMBA_VERSION_PRE_RELEASE}"
63     echo "#define SAMBA_VERSION_PRE_RELEASE ${SAMBA_VERSION_PRE_RELEASE}" >> $OUTPUT_FILE
64 elif test -n "${SAMBA_VERSION_RC_RELEASE}";then
65     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}rc${SAMBA_VERSION_RC_RELEASE}"
66     echo "#define SAMBA_VERSION_RC_RELEASE ${SAMBA_VERSION_RC_RELEASE}" >> $OUTPUT_FILE
67 fi
68
69 ##
70 ## SVN revision number? 
71 ##
72 if test x"${SAMBA_VERSION_IS_SVN_SNAPSHOT}" = x"yes";then
73     _SAVE_LANG=${LANG}
74     LANG=""
75     HAVEVER="no"
76
77     if test x"${HAVEVER}" != x"yes";then
78         HAVESVN=no
79         SVN_INFO=`svn info ${SOURCE_DIR} 2>/dev/null`
80         TMP_REVISION=`echo -e "${SVN_INFO}" | grep 'Last Changed Rev.*:' |sed -e 's/Last Changed Rev.*: \([0-9]*\).*/\1/'`
81         if test -n "$TMP_REVISION"; then
82             HAVESVN=yes
83             HAVEVER=yes
84         fi
85     fi
86
87     if test x"${HAVEVER}" != x"yes";then
88         HAVESVK=no
89         SVK_INFO=`svk info ${SOURCE_DIR} 2>/dev/null`
90         TMP_REVISION=`echo -e "${SVK_INFO}" | grep 'Last Changed Rev.*:' |sed -e 's/Last Changed Rev.*: \([0-9]*\).*/\1/'`
91         if test -n "$TMP_REVISION"; then
92             HAVESVK=yes
93             HAVEVER=yes
94         fi
95         TMP_MIRRORED_REVISION=`echo -e "${SVK_INFO}" | grep 'Mirrored From:.*samba\.org.*' |sed -e 's/Mirrored From: .* Rev\..* \([0-9]*\).*/\1/'`
96     fi
97
98     if test x"${HAVEVER}" != x"yes" -a -d "${SOURCE_DIR}../.bzr";then
99         HAVEBZR=no
100         BZR_INFO=`bzr version-info --check-clean ${SOURCE_DIR} 2>/dev/null`
101         TMP_REVISION=`echo -e "${BZR_INFO}" | grep 'revno:' |sed -e 's/revno: \([0-9]*\).*/\1/'`
102         if test -n "$TMP_REVISION"; then
103             HAVEBZR=yes
104             HAVEVER=yes
105         fi
106         TMP_MIRRORED_REVISION=`echo -e "${BZR_INFO}" | grep 'revision-id: svn-v1:.*@0c0555d6-39d7-0310-84fc-f1cc0bd64818' |sed -e 's/revision-id: svn-v1:\([0-9]*\)@0c0555d6-39d7-0310-84fc-f1cc0bd64818.*/\1/'`
107         TMP_BRANCH_NICK=`echo -e "${BZR_INFO}" | grep 'branch-nick:' |sed -e 's/branch-nick: \(.*\)$/\1/'`
108         TMP_CLEAN_TREE=`echo -e "${BZR_INFO}" | grep 'clean:' |sed -e 's/clean: \([a-zA-Z]*\).*/\1/'`
109     fi
110
111     if test x"${HAVEVER}" != x"yes" -a -d "${SOURCE_DIR}../.git";then
112         HAVEGIT=no
113         GIT_INFO=`git show --abbrev-commit HEAD 2>/dev/null`
114         TMP_REVISION=`echo -e "${GIT_INFO}" | sed 1q | grep 'commit ' | sed -e 's/commit \([0-9a-f]*\).*/\1/'`
115         if test -n "$TMP_REVISION";then
116             HAVEGIT=yes
117             HAVEVER=yes
118         fi
119         TMP_MIRRORED_REVISION=`echo -e "${GIT_INFO}" | grep 'git-svn-id' |sed -e 's#^[ ^t]*git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/\(SAMBA_[34]_[0-9]\(_[0-9]\+\)\?@[0-9]*\).*#\1#'`
120     fi
121         
122
123     if test x"${HAVESVN}" = x"yes";then
124         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-SVN-build-${TMP_REVISION}"
125         echo "#define SAMBA_VERSION_SVN_REVISION ${TMP_REVISION}" >> $OUTPUT_FILE
126     elif test x"${HAVESVK}" = x"yes";then
127         if test -n "$TMP_MIRRORED_REVISION"; then
128             TMP_SVK_REVISION_STR="${TMP_REVISION}-${USER}@${HOSTNAME}-[SVN-${TMP_MIRRORED_REVISION}]"
129         else
130             TMP_SVK_REVISION_STR="${TMP_REVISION}-${USER}@${HOSTNAME}"
131         fi
132         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-SVK-build-${TMP_SVK_REVISION_STR}"
133     elif test x"${HAVEBZR}" = x"yes";then
134         TMP_BZR_REVISION_STR="${TMP_REVISION}"
135
136         if test -n "$TMP_BRANCH_NICK"; then
137             TMP_BZR_REVISION_STR="${TMP_BZR_REVISION_STR}${TMP_MOD_STR}@${TMP_BRANCH_NICK}"
138         fi
139
140         if test -n "$TMP_MIRRORED_REVISION"; then
141             TMP_BZR_REVISION_STR="${TMP_BZR_REVISION_STR}-[SVN-${TMP_MIRRORED_REVISION}]"
142         fi
143
144         if test  x"$TMP_CLEAN_TREE" != x"True"; then
145             TMP_BZR_REVISION_STR="${TMP_BZR_REVISION_STR}-[modified]"
146         fi
147
148         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-BZR-${TMP_BZR_REVISION_STR}"
149     elif test x"${HAVEGIT}" = x"yes";then
150         TMP_GIT_REVISION_STR="${TMP_REVISION}"
151
152         if test -n "$TMP_MIRRORED_REVISION"; then
153             TMP_GIT_REVISION_STR="${TMP_GIT_REVISION_STR}-[SVN-${TMP_MIRRORED_REVISION}]"
154         fi
155
156         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-GIT-${TMP_GIT_REVISION_STR}"
157     else
158         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-SVN-build-UNKNOWN"
159     fi
160     LANG=${_SAVE_LANG}
161 fi
162
163 echo "#define SAMBA_VERSION_OFFICIAL_STRING \"${SAMBA_VERSION_STRING}\"" >> $OUTPUT_FILE
164
165 ##
166 ## Add the vendor string if present
167 ##
168 if test -n "${SAMBA_VERSION_VENDOR_SUFFIX}";then
169     echo "#define SAMBA_VERSION_VENDOR_SUFFIX ${SAMBA_VERSION_VENDOR_SUFFIX}" >> $OUTPUT_FILE
170     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-${SAMBA_VERSION_VENDOR_SUFFIX}"
171     if test -n "${SAMBA_VERSION_VENDOR_PATCH}";then
172         echo "#define SAMBA_VERSION_VENDOR_PATCH ${SAMBA_VERSION_VENDOR_PATCH}" >> $OUTPUT_FILE
173         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-${SAMBA_VERSION_VENDOR_PATCH}"
174     fi
175 fi
176
177 echo "/* Version for mkrelease.sh: " >> $OUTPUT_FILE
178 echo "SAMBA_VERSION_STRING=$SAMBA_VERSION_STRING" >> $OUTPUT_FILE
179 echo "*/" >> $OUTPUT_FILE
180
181 ##
182 ## Add a release nickname
183 ##
184 if test -n "${SAMBA_VERSION_RELEASE_NICKNAME}";then
185     echo "#define SAMBA_VERSION_RELEASE_NICKNAME ${SAMBA_VERSION_RELEASE_NICKNAME}" >> $OUTPUT_FILE
186     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING} (${SAMBA_VERSION_RELEASE_NICKNAME})"
187 fi
188
189 echo "#define SAMBA_VERSION_STRING \"${SAMBA_VERSION_STRING}\"" >> $OUTPUT_FILE
190
191 echo "$0: '$OUTPUT_FILE' created for Samba(\"${SAMBA_VERSION_STRING}\")"
192
193 exit 0