packaging(RHEL-CTDB): autodetect the samba version number from version.h
[metze/samba/wip.git] / packaging / RHEL-CTDB / makerpms.sh
1 #!/bin/sh
2 # Copyright (C) John H Terpstra 1998-2002
3 #               Gerald (Jerry) Carter 2003
4
5 # The following allows environment variables to override the target directories
6 #   the alternative is to have a file in your home directory calles .rpmmacros
7 #   containing the following:
8 #   %_topdir  /home/mylogin/redhat
9 #
10 # Note: Under this directory rpm expects to find the same directories that are under the
11 #   /usr/src/redhat directory
12 #
13
14 # set DOCS_TARBALL to the path to a docs release tarball in .tar.bz2 format
15
16 # extra options passed to rpmbuild
17 EXTRA_OPTIONS="$1"
18
19 RPMSPECDIR=`rpm --eval %_specdir`
20 RPMSRCDIR=`rpm --eval %_sourcedir`
21
22 # At this point the RPMSPECDIR and RPMSRCDIR variables must have a value!
23
24 DIRNAME=$(dirname $0)
25 TOPDIR=${DIRNAME}/../..
26 SRCDIR=${TOPDIR}/source
27 VERSION_H=${SRCDIR}/include/version.h
28
29 SPECFILE="samba.spec"
30 DOCS="docs.tar.bz2"
31 RPMVER=`rpm --version | awk '{print $3}'`
32 RPM="rpmbuild"
33
34 ##
35 ## Check the RPM version (paranoid)
36 ##
37 case $RPMVER in
38     4*)
39        echo "Supported RPM version [$RPMVER]"
40        ;;
41     *)
42        echo "Unknown RPM version: `rpm --version`"
43        exit 1
44        ;;
45 esac
46
47 ##
48 ## determine the samba version and create the SPEC file
49 ##
50 pushd ${SRCDIR}
51 ./script/mkversion.sh
52 popd
53 if [ ! -f ${VERSION_H} ] ; then
54         echo "Error creating version.h"
55         exit 1
56 fi
57
58 VERSION=`grep SAMBA_VERSION_OFFICIAL_STRING ${VERSION_H} | awk '{print $3}'`
59 vendor_version=`grep SAMBA_VERSION_VENDOR_SUFFIX ${VERSION_H} | awk '{print $3}'`
60 if test "x${vendor_version}"  != "x" ; then
61         VERSION="${VERSION}-${vendor_version}"
62 fi
63 VERSION=`echo ${VERSION} | sed 's/\"//g'`
64 echo "VERSION: ${VERSION}"
65 sed -e s/PVERSION/${VERSION}/g \
66         < ${DIRNAME}/${SPECFILE}.tmpl \
67         > ${DIRNAME}/${SPECFILE}
68
69 ##
70 ## create the tarball
71 ##
72 pushd ${TOPDIR}
73 echo -n "Creating samba-${VERSION}.tar.bz2 ... "
74 git archive --prefix=samba-${VERSION}/ HEAD | bzip2 > ${RPMSRCDIR}/samba-${VERSION}.tar.bz2
75 RC=$?
76 popd
77 echo "Done."
78 if [ $RC -ne 0 ]; then
79         echo "Build failed!"
80         exit 1
81 fi
82
83
84 ##
85 ## copy additional source files
86 ##
87 if [ "x${DOCS_TARBALL}" != "x" ] && [ -f ${DOCS_TARBALL} ]; then
88     cp ${DOCS_TARBALL} ${RPMSRCDIR}/${DOCS}
89 fi
90
91 pushd ${DIRNAME}
92
93 chmod 755 setup/filter-requires-samba.sh
94 tar --exclude=.svn -jcvf - setup > ${RPMSRCDIR}/setup.tar.bz2
95
96 cp -p ${SPECFILE} ${RPMSPECDIR}
97
98 popd
99
100 ##
101 ## Build
102 ##
103 echo "$(basename $0): Getting Ready to build release package"
104 pushd ${RPMSPECDIR}
105 ${RPM} -ba $EXTRA_OPTIONS $SPECFILE
106 if [ "x$?" = "x0" ] && [ `arch` = "x86_64" ]; then
107     echo "Building 32 bit winbind libs"
108     # hi ho, a hacking we will go ...
109     ln -sf /lib/libcom_err.so.2 /lib/libcom_err.so
110     ln -sf /lib/libuuid.so.1 /lib/libuuid.so
111     ${RPM} -ba --rebuild --target=i386 $SPECFILE
112 fi
113
114 popd
115
116 echo "$(basename $0): Done."
117