1#!/bin/sh
2# Copyright (C) John H Terpstra 1998-2002
3# Updated for RPM 3 by Jochen Wiedmann, joe@ispsoft.de
4# Changed for a generic tar file rebuild by abartlet@pcug.org.au
5# Taken from Red Hat build area by JHT
6# Changed by John H Terpstra to build on RH8.1 - should also work for earlier versions jht@samba.org
7# Changes from Buchan Milne <bgmilne@cae.co.za>
8
9# The following allows environment variables to override the target directories
10#   the alternative is to have a file in your home directory calles .rpmmacros
11#   containing the following:
12#   %_topdir  /home/mylogin/RPM
13#
14
15# rpm --eval should always give a correct answer for this
16SPECDIR=`rpm "$@" --eval "%{_specdir}"`
17SRCDIR=`rpm "$@" --eval "%{_sourcedir}"`
18
19# At this point the (SPECDIR and) SRCDIR vaiables must have a value!
20
21USERID=`id -u`
22GRPID=`id -g`
23VERSION='PVERSION'
24
25RPMVER=`rpm --version | awk '{print $3}'`
26echo The RPM Version on this machine is: $RPMVER
27
28case $RPMVER in
29    2*)
30       echo Building for RPM v2.x
31       sed -e "s/MANDIR_MACRO/\%\{prefix\}\/man/g" < samba2.spec > samba.spec
32       ;;
33    3*)
34       echo Building for RPM v3.x
35       sed -e "s/MANDIR_MACRO/\%\{prefix\}\/man/g" < samba2.spec > samba.spec
36       ;;
37    4*)
38       echo Building for RPM v4.x
39       sed -e "s/MANDIR_MACRO/\%\{_mandir\}/g" < samba2.spec > samba.spec
40       ;;
41    *)
42       echo "Unknown RPM version: `rpm --version`"
43       exit 1
44       ;;
45esac
46
47( cd ../../source; if [ -f Makefile ]; then make distclean; fi )
48( cd ../../.. ; chown -R ${USERID}.${GRPID} samba-${VERSION} )
49echo "Compressing the source as bzip2, may take a while ..."
50( cd ../../.. ; tar --exclude=CVS -cjf ${SRCDIR}/samba-${VERSION}.tar.bz2 samba-${VERSION} )
51
52cp -av samba.spec ${SPECDIR}
53# cp -a *.patch.bz2 *.xpm.bz2 smb.* samba.xinetd samba.log $SRCDIR
54# Prepare to allow straight patches synced from Mandrake cvs:
55# Updating of sources and patches can be done more easily and accurately
56# by using info in the spec file. It won't work for files that use an rpm
57# macro in their name, but that shouldn't be a problem.
58
59SOURCES=`awk '/^Source/ {print $2}' samba.spec |grep -v "%{"`
60PATCHES=`awk  '/^Patch/ {print $2}' samba.spec`
61
62for i in $PATCHES $SOURCES;do
63	# We have two cases to fix, one where it's bzip2'ed
64	# in the spec and not in CVS, one where it's bzip2'ed 
65	# in CVS but not in the spec
66	[ -e $i ] && cp -av $i $SRCDIR
67	i_nobz2=`echo $i|sed -e 's/.bz2$//'`
68	i_bz2=$i.bz2
69	[ -e $i_nobz2 ] && bzip2 -kf $i_nobz2  && mv -fv $i $SRCDIR
70	[ -e $i_bz2 ] && bunzip2 -kf $i_bz2 && mv -fv $i $SRCDIR
71done
72
73echo Getting Ready to build release package
74cd ${SPECDIR}
75rpm -ba -v --clean --rmsource samba.spec $@
76
77echo Done.
78