7. Advanced RPM Building

Contents of this section

RPM has some very advanced features available for larger, more complex packages. It has the ability to build and output multiple binary subpackages. An example of this is the ability to produce separate Tcl/Tk binary packages from one spec file. Another example is the ability to use one spec file to create a single XFree86 package with no servers, and a separate package for each of the servers.

7.1 How to Get Started

The best way to get started is to look at an example spec file. The following tcl/tk spec file is a good one to start with (though you can also view the spec file of any package by installing the sources and looking in /usr/src/redhat-2.0/SPECS):

%package tcl
Description: Tool Command Language
Name: tcltk
Version: 7.4_4.0
Release: 1
Icon: tcl.gif
Source0: ftp.cs.berkeley.com:/pub/tcl/tcl7.4.tar.Z
Source1: ftp.cs.berkeley.com:/pub/tcl/tk4.0.tar.Z
Copyright: BSD
Group: Development/Languages/Tcl
Patch0: sunsite.unc.edu:/pub/Linux/devel/tcl7.4-1.diff.gz
Patch1: sunsite.unc.edu:/pub/Linux/devel/tk4.0-1.diff.gz
%package tk
Icon: tk.gif
Description: Tk toolkit
Group: Development/Languages/Tcl

%prep
%setup -T -c -a 0
%setup -T -D -a 1
%patch0 -p0
%patch1 -p0

%build
cd tcl7.4
./configure --prefix=/usr
make 
cd ../tk4.0
./configure --prefix=/usr
make

%install
cd tcl7.4
make install
ln -sf libtcl7.4.a /usr/lib/libtcl.a
ln -sf libtcl7.4.so.1 /usr/lib/libtcl.so.1
ln -sf libtk4.0.a /usr/lib/libtk.a
ln -sf libtk4.0.so.1 /usr/lib/libtk.so.1
cd ../tk4.0
make install

%post tcl
/sbin/ldconfig

%post tk
/sbin/ldconfig

%postun tcl
/sbin/ldconfig

%postun tk
/sbin/ldconfig

%files tcl
/usr/lib/libtcl7.4.a
/usr/lib/libtcl.a
/usr/lib/libtcl7.4.so.1
/usr/lib/libtcl.so.1
/usr/include/tcl/tcl*
/usr/bin/tclsh
/usr/bin/tclsh7.4
/usr/lib/tcl7.4
/usr/man/man1/*tcl
/usr/man/man3/*tcl

%files tk
/usr/lib/libtk4.0.a
/usr/lib/libtk.a
/usr/lib/libtk4.0.so.1
/usr/lib/libtk.so.1
/usr/include/tcl/ks_names.h
/usr/include/tcl/default.h
/usr/include/tcl/tk*
/usr/lib/tk4.0
/usr/man/man1/*tk
/usr/man/man3/*tk
/usr/bin/wish
/usr/bin/wish4.0

7.2 Sub-Packages

One of the main advanced features of RPM is the ability to build subpackages. They are easy to build as for most macros you can just add the subpackage name as a parameter for anything specific to a subpackage (and if you leave it off the section will apply to the main package).

7.3 The Header

The header only has one major difference, the %package macro. This macro is used in the header to tell which subpackage name to match the description with. If you omit the macro in the initial part of the header, you will get a main package with no change to the name. In the XFree86 package, however, there is no %package macro in the top of the header. This is because we wanted a base XFree86 package with all the common stuff in it and then several subpackages (XFree86-SVGA, etc.) with the servers. Tcl/Tk does not need a main package, so the macro is at the top.

Another difference is the fact that this package has multiple source and patch lines. If you'll notice, there is now a Source0 line instead of just Source. They are functionally equivalent, though it is a good idea to use Source0 when there is more than one source file (and the same applies to patches as well).

7.4 Prep

Prep is basically the same as in the simple example, except it uses more of the options available to the setup and patch macros.

7.5 Build

Build is basically the same, with the exception that the setup macro above used the -T option. Because of that, you have to do a manual cd to get into the source directory.

You will also notice that the build does a configure before it can build. This is the section where any of this type of configuration should go.

7.6 Install

Again, everything is pretty normal with the exception of the fact that you must manually cd into the source directories.

7.7 Optional pre and post Install/Uninstall Scripts

This section is almost the same as in a simple RPM case (see the above section). It has two post install scripts that run ldconfig for each of the subpackages upon install. It should have two post uninstall scripts to run ldconfig as well.

7.8 Files

Here you will declare which files go in which packages. You really have multiple file sections, each started with a new %files macro and the name of the subpackage (except in the case where you have a main package...that %files macro will have no argument given to it). The other macros (doc, config, etc) work exactly the same as in the simple case.

You also have the option to use the * to glob filenames out of a directory. You need to be careful with this (perhaps test it first) so as not to include files you didn't mean to. The above example does this with the man pages.

7.9 What Now?

Please see the above sections on Testing and What to do with new RPMs. We want all the RPMs available we can get, and we want them to be good RPMs. Please take the time to test them well, and then take the time to upload them for everyone's benefit. Also, please make sure you are only uploading freely available software. Commercial software and shareware should not be uploaded unless they have a copyright expressly stating that this is allowed.


Next Chapter, Previous Chapter

Table of contents of this chapter, General table of contents

Top of the document, Beginning of this Chapter