bf829410ac6333e3db51df2eacc228c58afa6d5e
[jelmer/samba4-debian.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_PRE_RELEASE=`sed -n 's/^SAMBA_VERSION_PRE_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
24 SAMBA_VERSION_RC_RELEASE=`sed -n 's/^SAMBA_VERSION_RC_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
25
26 SAMBA_VERSION_IS_SVN_SNAPSHOT=`sed -n 's/^SAMBA_VERSION_IS_SVN_SNAPSHOT=//p' $SOURCE_DIR$VERSION_FILE`
27
28 SAMBA_VERSION_RELEASE_NICKNAME=`sed -n 's/^SAMBA_VERSION_RELEASE_NICKNAME=//p' $SOURCE_DIR$VERSION_FILE`
29
30 SAMBA_VERSION_VENDOR_SUFFIX=`sed -n 's/^SAMBA_VERSION_VENDOR_SUFFIX=//p' $SOURCE_DIR$VERSION_FILE`
31 SAMBA_VERSION_VENDOR_PATCH=`sed -n 's/^SAMBA_VERSION_VENDOR_PATCH=//p' $SOURCE_DIR$VERSION_FILE`
32
33 echo "/* Autogenerated by script/mkversion.sh */" > $OUTPUT_FILE
34
35 echo "#define SAMBA_VERSION_MAJOR ${SAMBA_VERSION_MAJOR}" >> $OUTPUT_FILE
36 echo "#define SAMBA_VERSION_MINOR ${SAMBA_VERSION_MINOR}" >> $OUTPUT_FILE
37 echo "#define SAMBA_VERSION_RELEASE ${SAMBA_VERSION_RELEASE}" >> $OUTPUT_FILE
38
39
40 ##
41 ## start with "3.0.22"
42 ##
43 SAMBA_VERSION_STRING="${SAMBA_VERSION_MAJOR}.${SAMBA_VERSION_MINOR}.${SAMBA_VERSION_RELEASE}"
44
45
46 ##
47 ## maybe add "3.0.22a" or "4.0.0tp11" or "3.0.22pre1" or "3.0.22rc1"
48 ## We do not do pre or rc version on patch/letter releases
49 ##
50 if test -n "${SAMBA_VERSION_REVISION}";then
51     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}${SAMBA_VERSION_REVISION}"
52     echo "#define SAMBA_VERSION_REVISION \"${SAMBA_VERSION_REVISION}\"" >> $OUTPUT_FILE
53 elif test -n "${SAMBA_VERSION_TP_RELEASE}";then
54     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}tp${SAMBA_VERSION_TP_RELEASE}"
55     echo "#define SAMBA_VERSION_TP_RELEASE ${SAMBA_VERSION_TP_RELEASE}" >> $OUTPUT_FILE
56 elif test -n "${SAMBA_VERSION_PRE_RELEASE}";then
57     ## maybe add "3.0.22pre2"
58     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}pre${SAMBA_VERSION_PRE_RELEASE}"
59     echo "#define SAMBA_VERSION_PRE_RELEASE ${SAMBA_VERSION_PRE_RELEASE}" >> $OUTPUT_FILE
60 elif test -n "${SAMBA_VERSION_RC_RELEASE}";then
61     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}rc${SAMBA_VERSION_RC_RELEASE}"
62     echo "#define SAMBA_VERSION_RC_RELEASE ${SAMBA_VERSION_RC_RELEASE}" >> $OUTPUT_FILE
63 fi
64
65 ##
66 ## SVN revision number? 
67 ##
68 if test x"${SAMBA_VERSION_IS_SVN_SNAPSHOT}" = x"yes";then
69     _SAVE_LANG=${LANG}
70     LANG=""
71     HAVEVER="no"
72
73     if test x"${HAVEVER}" != x"yes";then
74         HAVESVN=no
75         SVN_INFO=`svn info ${SOURCE_DIR} 2>/dev/null`
76         TMP_REVISION=`echo -e "${SVN_INFO}" | grep 'Last Changed Rev.*:' |sed -e 's/Last Changed Rev.*: \([0-9]*\).*/\1/'`
77         if test -n "$TMP_REVISION"; then
78             HAVESVN=yes
79             HAVEVER=yes
80         fi
81     fi
82
83     if test x"${HAVEVER}" != x"yes";then
84         HAVESVK=no
85         SVK_INFO=`svk info ${SOURCE_DIR} 2>/dev/null`
86         TMP_REVISION=`echo -e "${SVK_INFO}" | grep 'Last Changed Rev.*:' |sed -e 's/Last Changed Rev.*: \([0-9]*\).*/\1/'`
87         if test -n "$TMP_REVISION"; then
88             HAVESVK=yes
89             HAVEVER=yes
90         fi
91         TMP_MIRRORED_REVISION=`echo -e "${SVK_INFO}" | grep 'Mirrored From:.*samba\.org.*' |sed -e 's/Mirrored From: .* Rev\..* \([0-9]*\).*/\1/'`
92     fi
93
94     if test x"${HAVEVER}" != x"yes";then
95         HAVEBZR=no
96         BZR_INFO=`bzr version-info --check-clean ${SOURCE_DIR} 2>/dev/null`
97         TMP_REVISION=`echo -e "${BZR_INFO}" | grep 'revno:' |sed -e 's/revno: \([0-9]*\).*/\1/'`
98         if test -n "$TMP_REVISION"; then
99             HAVEBZR=yes
100             HAVEVER=yes
101         fi
102         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/'`
103         TMP_BRANCH_NICK=`echo -e "${BZR_INFO}" | grep 'branch-nick:' |sed -e 's/branch-nick: \(.*\)$/\1/'`
104         TMP_CLEAN_TREE=`echo -e "${BZR_INFO}" | grep 'clean:' |sed -e 's/clean: \([a-zA-Z]*\).*/\1/'`
105     fi
106
107     if test x"${HAVESVN}" = x"yes";then
108         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-SVN-build-${TMP_REVISION}"
109         echo "#define SAMBA_VERSION_SVN_REVISION ${TMP_REVISION}" >> $OUTPUT_FILE
110     elif test x"${HAVESVK}" = x"yes";then
111         if test -n "$TMP_MIRRORED_REVISION"; then
112             TMP_SVK_REVISION_STR="${TMP_REVISION}-${USER}@${HOSTNAME}-[SVN-${TMP_MIRRORED_REVISION}]"
113         else
114             TMP_SVK_REVISION_STR="${TMP_REVISION}-${USER}@${HOSTNAME}"
115         fi
116         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-SVK-build-${TMP_SVK_REVISION_STR}"
117     elif test x"${HAVEBZR}" = x"yes";then
118         TMP_BZR_REVISION_STR="${TMP_REVISION}"
119
120         if test -n "$TMP_BRANCH_NICK"; then
121             TMP_BZR_REVISION_STR="${TMP_BZR_REVISION_STR}${TMP_MOD_STR}@${TMP_BRANCH_NICK}"
122         fi
123
124         if test -n "$TMP_MIRRORED_REVISION"; then
125             TMP_BZR_REVISION_STR="${TMP_BZR_REVISION_STR}-[SVN-${TMP_MIRRORED_REVISION}]"
126         fi
127
128         if test  x"$TMP_CLEAN_TREE" != x"True"; then
129             TMP_BZR_REVISION_STR="${TMP_BZR_REVISION_STR}-[modified]"
130         fi
131
132         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-BZR-${TMP_BZR_REVISION_STR}"
133     else
134         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-SVN-build-UNKNOWN"
135     fi
136     LANG=${_SAVE_LANG}
137 fi
138
139 echo "#define SAMBA_VERSION_OFFICIAL_STRING \"${SAMBA_VERSION_STRING}\"" >> $OUTPUT_FILE
140
141 ##
142 ## Add the vendor string if present
143 ##
144 if test -n "${SAMBA_VERSION_VENDOR_SUFFIX}";then
145     echo "#define SAMBA_VERSION_VENDOR_SUFFIX ${SAMBA_VERSION_VENDOR_SUFFIX}" >> $OUTPUT_FILE
146     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-${SAMBA_VERSION_VENDOR_SUFFIX}"
147     if test -n "${SAMBA_VERSION_VENDOR_PATCH}";then
148         echo "#define SAMBA_VERSION_VENDOR_PATCH ${SAMBA_VERSION_VENDOR_PATCH}" >> $OUTPUT_FILE
149         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-${SAMBA_VERSION_VENDOR_PATCH}"
150     fi
151 fi
152
153 ##
154 ## Add a release nickname
155 ##
156 if test -n "${SAMBA_VERSION_RELEASE_NICKNAME}";then
157     echo "#define SAMBA_VERSION_RELEASE_NICKNAME ${SAMBA_VERSION_RELEASE_NICKNAME}" >> $OUTPUT_FILE
158     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING} (${SAMBA_VERSION_RELEASE_NICKNAME})"
159 fi
160
161 echo "#define SAMBA_VERSION_STRING \"${SAMBA_VERSION_STRING}\"" >> $OUTPUT_FILE
162
163 echo "$0: '$OUTPUT_FILE' created for Samba(\"${SAMBA_VERSION_STRING}\")"
164
165 exit 0