d23d14ed8abe3bdd27511a0bb7edfc7141335552
[gd/samba-autobuild/.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 RPMBUILDDIR=`rpm --eval %_builddir`
22
23 # At this point the RPMSPECDIR and RPMSRCDIR variables must have a value!
24
25 DIRNAME=$(dirname $0)
26 TOPDIR=${DIRNAME}/../..
27
28 SPECFILE="samba.spec"
29 RPMVER=`rpm --version | awk '{print $3}'`
30 RPM="rpmbuild"
31
32 ##
33 ## Check the RPM version (paranoid)
34 ##
35 case $RPMVER in
36     4*)
37        echo "Supported RPM version [$RPMVER]"
38        ;;
39     *)
40        echo "Unknown RPM version: `rpm --version`"
41        exit 1
42        ;;
43 esac
44
45 mkdir -p `rpm --eval %_specdir`
46 mkdir -p `rpm --eval %_sourcedir`
47 mkdir -p `rpm --eval %_builddir`
48 mkdir -p `rpm --eval %_srcrpmdir`
49 mkdir -p `rpm --eval %_rpmdir`/noarch
50 mkdir -p `rpm --eval %_rpmdir`/i386
51 mkdir -p `rpm --eval %_rpmdir`/x86_64
52
53 ##
54 ## Delete the old debuginfo remnants:
55 ##
56 ## At least on RHEL 5.5, we observed broken debuginfo packages
57 ## when either old build directories were still present or old
58 ## debuginfo packages (of samba) were installed.
59 ##
60 ## Remove the debuginfo samba RPMs and old RPM build
61 ## directories, giving the user a 10 second chance to quit.
62 ##
63
64 if rpm -qa | grep -q samba-debuginfo || test -n "$(echo ${RPMBUILDDIR}/samba* | grep -v \*)" ; then
65         echo "Removing debuginfo remnants to fix debuginfo build:"
66         if rpm -qa | grep -q samba-debuginfo ; then
67                 echo "Uninstalling the samba-debuginfo RPM"
68                 echo -n "Press Control-C if you want to quit (you have 10 seconds)"
69                 for count in $(seq 1 10) ; do
70                         echo -n "."
71                         sleep 1
72                 done
73                 echo
74                 echo "That was your chance... :-)"
75                 rpm -e samba-debuginfo
76         fi
77         if test -n "$(echo ${RPMBUILDDIR}/samba* | grep -v \*)" ; then
78                 echo "Deleting ${RPMBUILDDIR}/samba*"
79                 echo -n "Press Control-C if you want to quit (you have 10 seconds)"
80                 for count in $(seq 1 10) ; do
81                         echo -n "."
82                         sleep 1
83                 done
84                 echo
85                 echo "That was your chance... :-)"
86                 rm -rf ${RPMBUILDDIR}/samba*
87         fi
88 fi
89
90 ##
91 ## determine the samba version and create the SPEC file
92 ##
93 ${DIRNAME}/makespec.sh
94 RC=$?
95 if [ $RC -ne 0 ]; then
96         exit ${RC}
97 fi
98
99 RELEASE=$(grep ^Release ${DIRNAME}/${SPECFILE} | sed -e 's/^Release:\ \+//')
100 VERSION=$(grep ^Version ${DIRNAME}/${SPECFILE} | sed -e 's/^Version:\ \+//')
101
102 ##
103 ## create the tarball
104 ##
105 pushd ${TOPDIR}
106 echo -n "Creating samba-${VERSION}.tar.bz2 ... "
107 git archive --prefix=samba-${VERSION}/ HEAD | bzip2 > ${RPMSRCDIR}/samba-${VERSION}.tar.bz2
108 RC=$?
109 popd
110 echo "Done."
111 if [ $RC -ne 0 ]; then
112         echo "Build failed!"
113         exit 1
114 fi
115
116
117 ##
118 ## copy additional source files
119 ##
120 pushd ${DIRNAME}
121
122 chmod 755 setup/filter-requires-samba.sh
123 tar --exclude=.svn -jcvf - setup > ${RPMSRCDIR}/setup.tar.bz2
124
125 cp -p ${SPECFILE} ${RPMSPECDIR}
126
127 popd
128
129 ##
130 ## some symlink fixes for building 32bit compat libs
131 ##
132 if [ `arch` = "x86_64" ]; then
133     ln -sf /lib/libcom_err.so.2 /lib/libcom_err.so
134     ln -sf /lib/libuuid.so.1 /lib/libuuid.so
135 fi
136
137 ##
138 ## Build
139 ##
140 echo "$(basename $0): Getting Ready to build release package"
141
142 case ${EXTRA_OPTIONS} in
143         *-b*)
144                 BUILD_TARGET=""
145                 ;;
146         *)
147                 BUILD_TARGET="-ba"
148                 ;;
149 esac
150
151 pushd ${RPMSPECDIR}
152 ${RPM} ${BUILD_TARGET} ${EXTRA_OPTIONS} ${SPECFILE}
153 popd
154
155 echo "$(basename $0): Done."
156