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