s4:local_password LDB module - change counter variables to "unsigned" where appropriate
[ira/wip.git] / packaging / RHEL / makerpms.git.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 # This tarball should contain the compiled docs with a prefix of "docs/".
18
19 # extra options passed to rpmbuild
20 EXTRA_OPTIONS="$1"
21
22 RPMSPECDIR=`rpm --eval %_specdir`
23 RPMSRCDIR=`rpm --eval %_sourcedir`
24
25 # At this point the RPMSPECDIR and RPMSRCDIR variables must have a value!
26
27 USERID=`id -u`
28 GRPID=`id -g`
29
30 DIRNAME=$(dirname $0)
31 TOPDIR=${DIRNAME}/../..
32 SRCDIR=${TOPDIR}/source3
33 VERSION_H=${SRCDIR}/include/version.h
34
35 SPECFILE="samba.spec"
36 DOCS="docs.tar.bz2"
37 RPMVER=`rpm --version | awk '{print $3}'`
38 RPM="rpmbuild"
39
40 ##
41 ## Check the RPM version (paranoid)
42 ##
43 case $RPMVER in
44     4*)
45        echo "Supported RPM version [$RPMVER]"
46        ;;
47     *)
48        echo "Unknown RPM version: `rpm --version`"
49        exit 1
50        ;;
51 esac
52
53 ##
54 ## determine the samba version and create the SPEC file
55 ##
56 pushd ${SRCDIR}
57 ./script/mkversion.sh
58 popd
59 if [ ! -f ${VERSION_H} ] ; then
60         echo "Error creating version.h"
61         exit 1
62 fi
63
64 VERSION=`grep "^#define SAMBA_VERSION_OFFICIAL_STRING " ${VERSION_H} | awk '{print $3}'`
65 vendor_version=`grep "^#define SAMBA_VERSION_VENDOR_SUFFIX " ${VERSION_H} | awk '{print $3}'`
66 if test "x${vendor_version}"  != "x" ; then
67         VERSION="${VERSION}-${vendor_version}"
68 fi
69 VERSION=`echo ${VERSION} | sed 's/-/_/g'`
70 VERSION=`echo ${VERSION} | sed 's/\"//g'`
71 echo "VERSION: ${VERSION}"
72 sed -e s/PVERSION/${VERSION}/g \
73         -e s/PRELEASE/1/g \
74         -e s/PRPMREV//g \
75         < ${DIRNAME}/${SPECFILE}.tmpl \
76         > ${DIRNAME}/${SPECFILE}
77
78
79 ##
80 ## create the tarball
81 ##
82 pushd ${TOPDIR}
83 rm -rf ../samba-${VERSION}
84 git archive --prefix=samba-${VERSION}/ HEAD | (cd .. && tar -xf -)
85 RC=$?
86 popd
87 if [ $RC -ne 0 ]; then
88         echo "Build failed!"
89         exit 1
90 fi
91
92 if [ "x${DOCS_TARBALL}" != "x" ] && [ -f ${DOCS_TARBALL} ]; then
93         cp ${DOCS_TARBALL} /tmp/${DOCS}
94         pushd ${TOPDIR}/../samba-${VERSION}
95         tar xjf /tmp/${DOCS}
96         RC=$?
97         rm -f /tmp/${DOCS}
98         popd
99         if [ $RC -ne 0 ]; then
100                 echo "Build failed!"
101                 exit 1
102         fi
103 fi
104
105 pushd ${TOPDIR}/..
106 chown -R ${USERID}.${GRPID} samba-${VERSION}${REVISION}
107 if [ ! -d samba-${VERSION} ]; then
108         ln -s samba-${VERSION}${REVISION} samba-${VERSION} || exit 1
109 fi
110 echo -n "Creating samba-${VERSION}.tar.bz2 ... "
111 tar --exclude=.svn -cf - samba-${VERSION}/. | bzip2 > ${RPMSRCDIR}/samba-${VERSION}.tar.bz2
112 RC=$?
113 rm -rf samba-${VERSION}/
114 popd
115 echo "Done."
116 if [ $RC -ne 0 ]; then
117         echo "Build failed!"
118         exit 1
119 fi
120
121
122 ##
123 ## copy additional source files
124 ##
125 pushd ${DIRNAME}
126 chmod 755 setup/filter-requires-samba.sh
127 tar --exclude=.svn -jcvf - setup > ${RPMSRCDIR}/setup.tar.bz2
128 cp -p ${SPECFILE} ${RPMSPECDIR}
129 popd
130
131 ##
132 ## Build
133 ##
134 echo "$(basename $0): Getting Ready to build release package"
135 pushd ${RPMSPECDIR}
136 ${RPM} -ba $EXTRA_OPTIONS $SPECFILE
137 if [ "x$?" = "x0" ] && [ `arch` = "x86_64" ]; then
138     echo "Building 32 bit winbind libs"
139     # hi ho, a hacking we will go ...
140     ln -sf /lib/libcom_err.so.2 /lib/libcom_err.so
141     ln -sf /lib/libuuid.so.1 /lib/libuuid.so
142     ln -sf /lib/libkeyutils.so.1 /lib/libkeyutils.so
143     ${RPM} -ba --rebuild --target=i386 $SPECFILE
144 fi
145
146 popd
147
148 echo "$(basename $0): Done."
149