846ab7f70f8c13836a14e9ec839c7189376c3fca
[sahlberg/ctdb.git] / packaging / RPM / makerpms.sh
1 #!/bin/sh
2 #
3 # makerpms.sh  -  build RPM packages from the git sources
4 #
5 # Copyright (C) John H Terpstra 1998-2002
6 # Copyright (C) Gerald (Jerry) Carter 2003
7 # Copyright (C) Jim McDonough 2007
8 # Copyright (C) Andrew Tridgell 2007
9 # Copyright (C) Michael Adam 2008-2009
10 #
11 # This program is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by the Free
13 # Software Foundation; either version 3 of the License, or (at your option)
14 # any later version.
15 #
16 # This program is distributed in the hope that it will be useful, but WITHOUT
17 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19 # more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # this program; if not, see <http://www.gnu.org/licenses/>.
23 #
24
25 #
26 # The following allows environment variables to override the target directories
27 #   the alternative is to have a file in your home directory calles .rpmmacros
28 #   containing the following:
29 #   %_topdir  /home/mylogin/redhat
30 #
31 # Note: Under this directory rpm expects to find the same directories that are under the
32 #   /usr/src/redhat directory
33 #
34
35 EXTRA_OPTIONS="$1"
36
37 DIRNAME=$(dirname $0)
38 TOPDIR=${DIRNAME}/../..
39
40 SPECDIR=`rpm --eval %_specdir`
41 SRCDIR=`rpm --eval %_sourcedir`
42
43 SPECFILE="ctdb.spec"
44 RPMBUILD="rpmbuild"
45
46 VERSION=$(grep ^Version ${DIRNAME}/${SPECFILE} | sed -e 's/^Version:\ \+//')
47 RELEASE=$(grep ^Release ${DIRNAME}/${SPECFILE} | sed -e 's/^Release:\ \+//')
48
49 if echo | gzip -c --rsyncable - > /dev/null 2>&1 ; then
50         GZIP="gzip -9 --rsyncable"
51 else
52         GZIP="gzip -9"
53 fi
54
55 pushd ${TOPDIR}
56 echo -n "Creating ctdb-${VERSION}.tar.gz ... "
57 git archive --prefix=ctdb-${VERSION}/ HEAD | ${GZIP} > ${SRCDIR}/ctdb-${VERSION}.tar.gz
58 RC=$?
59 popd
60 echo "Done."
61 if [ $RC -ne 0 ]; then
62         echo "Build failed!"
63         exit 1
64 fi
65
66 # At this point the SPECDIR and SRCDIR vaiables must have a value!
67
68 ##
69 ## copy additional source files
70 ##
71 cp -p ${DIRNAME}/${SPECFILE} ${SPECDIR}
72
73 ##
74 ## Build
75 ##
76 echo "$(basename $0): Getting Ready to build release package"
77 ${RPMBUILD} -ba --clean --rmsource ${EXTRA_OPTIONS} ${SPECDIR}/${SPECFILE} || exit 1
78
79 echo "$(basename $0): Done."
80
81 exit 0