74d5f7b3d9508423de27a9e77f8eece20f014626
[obnox/samba-ctdb.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 # 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
27 SPECFILE="samba.spec"
28 RPMVER=`rpm --version | awk '{print $3}'`
29 RPM="rpmbuild"
30
31 ##
32 ## Check the RPM version (paranoid)
33 ##
34 case $RPMVER in
35     4*)
36        echo "Supported RPM version [$RPMVER]"
37        ;;
38     *)
39        echo "Unknown RPM version: `rpm --version`"
40        exit 1
41        ;;
42 esac
43
44 ##
45 ## determine the samba version and create the SPEC file
46 ##
47 ${DIRNAME}/makespec.sh
48 RC=$?
49 if [ $RC -ne 0 ]; then
50         exit ${RC}
51 fi
52
53 RELEASE=$(grep ^Release ${DIRNAME}/${SPECFILE} | sed -e 's/^Release:\ \+//')
54 VERSION=$(grep ^Version ${DIRNAME}/${SPECFILE} | sed -e 's/^Version:\ \+//')
55
56 ##
57 ## create the tarball
58 ##
59 pushd ${TOPDIR}
60 echo -n "Creating samba-${VERSION}.tar.bz2 ... "
61 git archive --prefix=samba-${VERSION}/ HEAD | bzip2 > ${RPMSRCDIR}/samba-${VERSION}.tar.bz2
62 RC=$?
63 popd
64 echo "Done."
65 if [ $RC -ne 0 ]; then
66         echo "Build failed!"
67         exit 1
68 fi
69
70
71 ##
72 ## copy additional source files
73 ##
74 pushd ${DIRNAME}
75
76 chmod 755 setup/filter-requires-samba.sh
77 tar --exclude=.svn -jcvf - setup > ${RPMSRCDIR}/setup.tar.bz2
78
79 cp -p ${SPECFILE} ${RPMSPECDIR}
80
81 popd
82
83 ##
84 ## some symlink fixes for building 32bit compat libs
85 ##
86 if [ `arch` = "x86_64" ]; then
87     ln -sf /lib/libcom_err.so.2 /lib/libcom_err.so
88     ln -sf /lib/libuuid.so.1 /lib/libuuid.so
89 fi
90
91 ##
92 ## Build
93 ##
94 echo "$(basename $0): Getting Ready to build release package"
95
96 pushd ${RPMSPECDIR}
97 ${RPM} -ba $EXTRA_OPTIONS $SPECFILE
98 popd
99
100 echo "$(basename $0): Done."
101