Censorship, Freedom of Speech, Privacy

Please join the Electronic Frontier Foundation ( EFF.org ) and the fight for your rights on the Internet.

I have not received any National Security Letter.

HOME Software Lotus Cars DWARF Kindle eeepc PALM RPM Building

graphic with lotus europa and lotus elan

David A's RPM Build Hints

RPM Building Hints

RPM is a popular tool for software distribution and installation on Red Hat Linux. It took me a while (and help from others) to understand how to create an rpm without becoming root (superuser). So I wrote up this simple example of use of rpmbuild in case some other software developer might find it of interest as an introduction to the topic. I found existing documents on rpmbuild were helpful but inadequate.

So the following is a simple example

This is documented here in terms of a mythical product zzz, version 6.2.

Corrections and suggests for improvement of this page are always welcome. Created Sep 21, 2004.

Build Goals

I wanted the simplest rpmbuild I could manage and did not want to be root during creation of the RPMs. The non-rootness is very easy to accomplish, but it was difficult to figure out how to do that. Finally someone helped me, so now I'm helping you! I hope.

[top]

The Files

You need to write a .spec file. Here I'll use zzz-6.2.spec as the example. You need to write ~HOME/.rpmmacros. You need a buildable source tree. A simple shell script can then do the work. That's all you really need. rpmbuild creates three rpm's when rpmbuild succeeds.

The three rpm's a successful build will create are under SRPMS (the source rpm) and under RPMS (the installable binary and a debuginfo rpm). For this example, if one were building on ia64 Linux (an SGI Altix, for example) one would find SRPMS/zzz-6.2-2.src.rpm, RPMS/ia64/zzz-6.2-2.ia64.rpm, RPMS/ia64/zzz-debuginfo-6.2-2.ia64.rpm

The src.rpm is the buildable source, with source code and configure and Makefile present. The debuginfo rpm is source without build stuff, usable with a debugger: installed by default in /usr/src/debug/zzz. The zzz-6.2-2.ia64.rpm is the executable tool (zzz in this case), the rpm folks simply wanting to use the tool would install.

If you have a package from the internet and wish to build RPM's you must sometimes apply patches. I won't describe that part here, I assume no patching is needed. See the References below for more info.

To make the example concrete, I'll use $HOME/.rpmmacros, $HOME/zzz-6.2.spec as the spec file, and $HOME/zzz as the location of my original source file. I'm assuming that the package builds like most packages, in that one does

	sh configure
	make

to build the product.

[top]

spec file

Summary: An example tool. To show a simple rpm build of the tool.
Name: zzz
Version: 6.2
Release: 2
Copyright: GPL
Source:%{name}-%{version}.tar.gz
Group: Development/Debuggers
BuildRoot:/var/tmp/davea/%{name}-root
%description
zzz is not a real tool, it's an example showing one way
to build an rpm.

%prep

%setup -q

%build
sh configure
make

%install
make 
install -D zzz/zzz  $RPM_BUILD_ROOT/usr/bin/zzz

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)

/usr/bin/zzz

%changelog
* Tue Sep  22 2004  David Anderson <davea@fake.any>
- Removed debug printf's that were accidentally left in.
* Tue Sep  21 2004  David Anderson <davea@fake.any>
- Initial example

There is a lot one can say about spec files, and the references give lots of useful info, most of which I won't repeat here. The sections, briefly are as follows.

[top]

rpmmacros file

This is the key to enabling safe rpm building as yourself. The file $HOME/.rpmmacros should contain the line:

%_topdir /var/tmp/davea/rpm

This line overrides the default _topdir of /usr/src/redhat and enables the build to work in the directory of your choice (/var/tmp/davea/rpm for this example).

The "Maximum RPM" document writes about 'topdir' in .rpmrc, but that simply does not work in current rpmbuild.

[top]

Shell Script

Given the spec file, .rpmmacros, and the application source tree, this file pulls it all together and builds the RPMs.

#!/bin/sh
# Build a zzz rpm set. 
# Uses temp space here, does not touch the source.
# Runnable as myself, does not use root permission at all.
set -x
# Relies on ~/.rpmmacros setting _topdir to what is here ($r, see below)
d=/var/tmp/davea
if [ ! -d $d ] 
then
        mkdir $d
fi

# clean out  /var/tmp/davea/rpm
# and then recreates the basic redhat dirs, like SOURCES SPECS there.
cd $d
r=$d/rpm
o=zzz-6.2
s=$r/SOURCES
spec=${o}.spec
rm -rf $r
mkdir rpm
mkdir rpm/SOURCES
mkdir rpm/SRPMS
mkdir rpm/SPECS
mkdir rpm/BUILD
mkdir rpm/RPMS

# First setup and copy the source.
cd  $s
rm -rf $o
mkdir $o
cp -r $HOME/zzz/* $o

# ensure no old junk present. (overkill)
rm  -f $o.tar
rm  -f $o.tar.gz
tar -cf $o.tar $o
ls -l $o.tar
gzip  $o.tar
ls -l
cp $HOME/$spec $r/SPECS
#rm -rf $o
# Now build the binaries and the rpms.
rpmbuild -ba $r/SPECS/$spec

[top]

References

[top]

http://a/rpmbuild.html