64f1a778aeb13027d236db7d8a59561a0cf37d88
[samba.git] / source3 / 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="include/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 SAMBA_VERSION_REVISION=`sed -n 's/^SAMBA_VERSION_REVISION=//p' $SOURCE_DIR$VERSION_FILE`
20 SAMBA_VERSION_PRE_RELEASE=`sed -n 's/^SAMBA_VERSION_PRE_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
21 SAMBA_VERSION_RC_RELEASE=`sed -n 's/^SAMBA_VERSION_RC_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
22 SAMBA_VERSION_IS_SVN_SNAPSHOT=`sed -n 's/^SAMBA_VERSION_IS_SVN_SNAPSHOT=//p' $SOURCE_DIR$VERSION_FILE`
23 SAMBA_VERSION_VENDOR_SUFFIX=`sed -n 's/^SAMBA_VERSION_VENDOR_SUFFIX=//p' $SOURCE_DIR$VERSION_FILE`
24 SAMBA_VENDOR_PATCH=`sed -n 's/^SAMBA_VENDOR_PATCH=//p' $SOURCE_DIR$VERSION_FILE`
25
26 echo "/* Autogenerated by script/mkversion.sh */" > $OUTPUT_FILE
27
28 echo "#define SAMBA_VERSION_MAJOR ${SAMBA_VERSION_MAJOR}" >> $OUTPUT_FILE
29 echo "#define SAMBA_VERSION_MINOR ${SAMBA_VERSION_MINOR}" >> $OUTPUT_FILE
30 echo "#define SAMBA_VERSION_RELEASE ${SAMBA_VERSION_RELEASE}" >> $OUTPUT_FILE
31
32
33 ##
34 ## start with "3.0.22"
35 ##
36 SAMBA_VERSION_STRING="${SAMBA_VERSION_MAJOR}.${SAMBA_VERSION_MINOR}.${SAMBA_VERSION_RELEASE}"
37
38
39 ##
40 ## maybe add "3.0.22a" or "3.0.22pre1" or "3.0.22rc1"
41 ## We do not do pre or rc version on patch/letter releases
42 ##
43 if test -n "${SAMBA_VERSION_REVISION}";then
44     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}${SAMBA_VERSION_REVISION}"
45     echo "#define SAMBA_VERSION_REVISION \"${SAMBA_VERSION_REVISION}\"" >> $OUTPUT_FILE
46 elif test -n "${SAMBA_VERSION_PRE_RELEASE}";then
47     ## maybe add "3.0.22pre2"
48     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}pre${SAMBA_VERSION_PRE_RELEASE}"
49     echo "#define SAMBA_VERSION_PRE_RELEASE ${SAMBA_VERSION_PRE_RELEASE}" >> $OUTPUT_FILE
50 elif test -n "${SAMBA_VERSION_RC_RELEASE}";then
51     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}rc${SAMBA_VERSION_RC_RELEASE}"
52     echo "#define SAMBA_VERSION_RC_RELEASE ${SAMBA_VERSION_RC_RELEASE}" >> $OUTPUT_FILE
53 fi
54
55 ##
56 ## Add the vendor string if present
57 ##
58 if test -n "${SAMBA_VERSION_VENDOR_SUFFIX}";then
59     echo "#define SAMBA_VERSION_VENDOR_SUFFIX ${SAMBA_VERSION_VENDOR_SUFFIX}" >> $OUTPUT_FILE
60     if test -n "${SAMBA_VENDOR_PATCH}";then
61         echo "#define SAMBA_VENDOR_PATCH ${SAMBA_VENDOR_PATCH}" >> $OUTPUT_FILE
62     fi
63 fi
64
65
66
67 ##
68 ## SVN revision number? 
69 ##
70 if test x"${SAMBA_VERSION_IS_SVN_SNAPSHOT}" = x"yes";then
71     _SAVE_LANG=${LANG}
72     LANG=""
73     HAVESVN=no
74     svn info ${SOURCE_DIR} >/dev/null 2>&1 && HAVESVN=yes
75     TMP_REVISION=`(svn info ${SOURCE_DIR} 2>/dev/null || svk info ${SOURCE_DIR} 2>/dev/null) |grep 'Last Changed Rev.*:' |sed -e 's/Last Changed Rev.*: \([0-9]*\).*/\1/'`
76     if test x"${HAVESVN}" = x"no";then
77         HAVESVK=no
78         svk info ${SOURCE_DIR} >/dev/null 2>&1 && HAVESVK=yes
79         TMP_MIRRORED_REVISION=`(svk info ${SOURCE_DIR} 2>/dev/null) |grep 'Mirrored From:.*samba\.org.*' |sed -e 's/Mirrored From: .* Rev\..* \([0-9]*\).*/\1/'`
80         if test -n "$TMP_MIRRORED_REVISION"; then
81             TMP_SVK_REVISION_STR="${TMP_REVISION}-${USER}@${HOSTNAME}-[SVN-${TMP_MIRRORED_REVISION}]"
82         else
83             TMP_SVK_REVISION_STR="${TMP_REVISION}-${USER}@${HOSTNAME}"
84         fi
85         if test x"${HAVESVK}" = x"no";then
86             HAVEBZR=no
87             bzr revno > /dev/null 2>&1 && HAVEBZR=yes
88             TMP_BZR_REVNO=`bzr revno 2> /dev/null`
89             TMP_BZR_NICK=`bzr nick 2> /dev/null`
90             TMP_BZR_REVISION_STR="${TMP_BZR_NICK}-${TMP_BZR_REVNO}"
91         fi
92     fi
93
94     if test x"${HAVESVN}" = x"yes";then
95             SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-SVN-build-${TMP_REVISION}"
96             echo "#define SAMBA_VERSION_SVN_REVISION ${TMP_REVISION}" >> $OUTPUT_FILE
97     elif test x"${HAVESVK}" = x"yes";then
98             SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-SVK-build-${TMP_SVK_REVISION_STR}"
99     elif test x"${HAVEBZR}" = x"yes";then
100             SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-BZR-build-${TMP_BZR_REVISION_STR}"
101     else
102             SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-SVN-build-UNKNOWN"
103     fi
104     LANG=${_SAVE_LANG}
105 fi
106
107 echo "#define SAMBA_VERSION_OFFICIAL_STRING \"${SAMBA_VERSION_STRING}\"" >> $OUTPUT_FILE
108
109 echo "#define SAMBA_VERSION_STRING samba_version_string()" >> $OUTPUT_FILE
110
111 echo "$0: 'include/version.h' created for Samba(\"${SAMBA_VERSION_STRING}\")"
112
113 if test -n "${SAMBA_VERSION_VENDOR_SUFFIX}";then
114     echo -n "$0: with VENDOR_SUFFIX = \""
115     echo -n ${SAMBA_VERSION_VENDOR_SUFFIX} | sed 's/"//g'
116     if test -n ${SAMBA_VENDOR_PATCH}; then
117        echo -n "-${SAMBA_VENDOR_PATCH}"
118    fi
119    echo "\""
120 fi
121
122 exit 0