d8ba8af008e74b7df7db174543805e6a583802c1
[kai/samba-autobuild/.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
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_GIT_SNAPSHOT=`sed -n 's/^SAMBA_VERSION_IS_GIT_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 SAMBA_VERSION_VENDOR_FUNCTION=`sed -n 's/^SAMBA_VERSION_VENDOR_FUNCTION=//p' $SOURCE_DIR$VERSION_FILE`
34
35 echo "/* Autogenerated by script/mkversion.sh */" > $OUTPUT_FILE
36
37 echo "#define SAMBA_VERSION_MAJOR ${SAMBA_VERSION_MAJOR}" >> $OUTPUT_FILE
38 echo "#define SAMBA_VERSION_MINOR ${SAMBA_VERSION_MINOR}" >> $OUTPUT_FILE
39 echo "#define SAMBA_VERSION_RELEASE ${SAMBA_VERSION_RELEASE}" >> $OUTPUT_FILE
40
41
42 ##
43 ## start with "3.0.22"
44 ##
45 SAMBA_VERSION_STRING="${SAMBA_VERSION_MAJOR}.${SAMBA_VERSION_MINOR}.${SAMBA_VERSION_RELEASE}"
46
47
48 ##
49 ## maybe add "3.0.22a" or "4.0.0tp11" or "3.0.22pre1" or "3.0.22rc1"
50 ## We do not do pre or rc version on patch/letter releases
51 ##
52 if test -n "${SAMBA_VERSION_REVISION}";then
53     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}${SAMBA_VERSION_REVISION}"
54     echo "#define SAMBA_VERSION_REVISION \"${SAMBA_VERSION_REVISION}\"" >> $OUTPUT_FILE
55 elif test -n "${SAMBA_VERSION_TP_RELEASE}";then
56     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}tp${SAMBA_VERSION_TP_RELEASE}"
57     echo "#define SAMBA_VERSION_TP_RELEASE ${SAMBA_VERSION_TP_RELEASE}" >> $OUTPUT_FILE
58 elif test -n "${SAMBA_VERSION_PRE_RELEASE}";then
59     ## maybe add "3.0.22pre2"
60     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}pre${SAMBA_VERSION_PRE_RELEASE}"
61     echo "#define SAMBA_VERSION_PRE_RELEASE ${SAMBA_VERSION_PRE_RELEASE}" >> $OUTPUT_FILE
62 elif test -n "${SAMBA_VERSION_RC_RELEASE}";then
63     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}rc${SAMBA_VERSION_RC_RELEASE}"
64     echo "#define SAMBA_VERSION_RC_RELEASE ${SAMBA_VERSION_RC_RELEASE}" >> $OUTPUT_FILE
65 fi
66
67 ##
68 ## GIT commit details
69 ##
70 if test x"${SAMBA_VERSION_IS_GIT_SNAPSHOT}" = x"yes";then
71     _SAVE_LANG=${LANG}
72     LANG="C"
73     HAVEVER="no"
74
75     if test x"${HAVEVER}" != x"yes" -a -d "${SOURCE_DIR}../.git";then
76         HAVEGIT=no
77         GIT_INFO=`git show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD 2>/dev/null`
78         GIT_COMMIT_ABBREV=`printf "%s" "${GIT_INFO}" | sed -n 1p`
79         COMMIT_TIME=`printf "%s" "${GIT_INFO}" | sed -n 2p`
80         GIT_COMMIT_FULLREV=`printf "%s" "${GIT_INFO}" | sed -n 3p`
81         COMMIT_DATE=`printf "%s" "${GIT_INFO}" | sed -n 4p`
82         if test -n "${GIT_COMMIT_ABBREV}";then
83             HAVEGIT=yes
84             HAVEVER=yes
85         fi
86     fi
87
88     if test x"${HAVEGIT}" = x"yes";then
89         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-GIT-${GIT_COMMIT_ABBREV}"
90
91         echo "#define SAMBA_VERSION_GIT_COMMIT_ABBREV \"${GIT_COMMIT_ABBREV}\"" >> $OUTPUT_FILE
92         echo "#define SAMBA_VERSION_COMMIT_TIME ${COMMIT_TIME}" >> $OUTPUT_FILE
93         echo "#define SAMBA_VERSION_GIT_COMMIT_FULLREV \"${GIT_COMMIT_FULLREV}\"" >> $OUTPUT_FILE
94         echo "#define SAMBA_VERSION_COMMIT_DATE \"${COMMIT_DATE}\"" >> $OUTPUT_FILE
95     else
96         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-GIT-UNKNOWN"
97     fi
98     LANG=${_SAVE_LANG}
99 fi
100
101 echo "#define SAMBA_VERSION_OFFICIAL_STRING \"${SAMBA_VERSION_STRING}\"" >> $OUTPUT_FILE
102
103 ##
104 ## Add the vendor string if present
105 ##
106 if test -n "${SAMBA_VERSION_VENDOR_FUNCTION}"; then
107   echo "#define SAMBA_VERSION_VENDOR_FUNCTION ${SAMBA_VERSION_VENDOR_FUNCTION}" >> $OUTPUT_FILE
108 fi
109
110 if test -n "${SAMBA_VERSION_VENDOR_SUFFIX}";then
111     echo "#define SAMBA_VERSION_VENDOR_SUFFIX \"${SAMBA_VERSION_VENDOR_SUFFIX}\"" >> $OUTPUT_FILE
112     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-${SAMBA_VERSION_VENDOR_SUFFIX}"
113     if test -n "${SAMBA_VERSION_VENDOR_PATCH}";then
114         echo "#define SAMBA_VERSION_VENDOR_PATCH \"${SAMBA_VERSION_VENDOR_PATCH}\"" >> $OUTPUT_FILE
115         echo "#define SAMBA_VERSION_VENDOR_PATCH_STRING \"${SAMBA_VERSION_VENDOR_PATCH}\"" >> $OUTPUT_FILE
116         SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}-${SAMBA_VERSION_VENDOR_PATCH}"
117     fi
118 fi
119
120 ##
121 ## Add a release nickname
122 ##
123 if test -n "${SAMBA_VERSION_RELEASE_NICKNAME}";then
124     echo "#define SAMBA_VERSION_RELEASE_NICKNAME \"${SAMBA_VERSION_RELEASE_NICKNAME}\"" >> $OUTPUT_FILE
125     SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING} (${SAMBA_VERSION_RELEASE_NICKNAME})"
126 fi
127
128 cat >>$OUTPUT_FILE<<CEOF
129 #ifdef SAMBA_VERSION_VENDOR_FUNCTION
130 #  define SAMBA_VERSION_STRING SAMBA_VERSION_VENDOR_FUNCTION
131 #else /* SAMBA_VERSION_VENDOR_FUNCTION */
132 #  ifdef SAMBA_VERSION_VENDOR_SUFFIX
133 #    ifdef SAMBA_VERSION_VENDOR_PATCH
134 #      define SAMBA_VERSION_STRING SAMBA_VERSION_OFFICIAL_STRING "-" SAMBA_VERSION_VENDOR_SUFFIX "-" SAMBA_VERSION_VENDOR_PATCH_STRING
135 #    else /* SAMBA_VERSION_VENDOR_PATCH */
136 #      define SAMBA_VERSION_STRING SAMBA_VERSION_OFFICIAL_STRING "-" SAMBA_VERSION_VENDOR_SUFFIX
137 #    endif /* SAMBA_VERSION_VENDOR_SUFFIX */
138 #  else /* SAMBA_VERSION_VENDOR_FUNCTION */
139 #    define SAMBA_VERSION_STRING SAMBA_VERSION_OFFICIAL_STRING
140 #  endif
141 #endif
142 CEOF
143
144 echo "$0: '$OUTPUT_FILE' created for Samba(\"${SAMBA_VERSION_STRING}\")"
145
146 exit 0