wiki:RPMBuilding

Version 3 (modified by thomas, 14 years ago) (diff)

--

Getting started with RPM Building

How to get started with building RPMS - in particular how to setup your build environment and the basics of spec file writing.

Getting Started

RPM Building (PDF)

To build rpms you need to have a .rpmmacros file in your home directory which configures your build tree location. The minimum you'll need is the location of your top directory for building

[joe@host ~] cat .rpmmacros
%_topdir $HOME/src

You'll need to create /home/$USER/src as well, with the following subdir's: SRPMS SPECS BUILD SOURCES RPMS

[joe@host ~] cd
[joe@host ~] mkdir -p src/SRPMS src/SPECS src/BUILD src/SOURCES src/RPMS

to build your first rpm, start simple. Download a known to be good source rpm of something small, tar is a good first package since it is small and quick to build. Install the src rpm using

[joe@host ~] rpm -Uvh packagex.src.rpm

This will install the packagex.spec file in your SPECS directory and the source files (usually a tarball, eg package-version.release.tar.gz) in your SOURCES directory. To build this rpm using that spec:

[joe@host ~] rpmbuild -ba packagex.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.55587
+ umask 022 + cd %_topdir/BUILD + LANG=C + export LANG + unset DISPLAY + cd %_topdir/BUILD + rm -rf packagex + /bin/gzip -dc %_topdir/SOURCES/packagex-1.2.5.tar.gz + tar -xvvf - .
.
.
Wrote: %_topdir/SRPMS/packagex-1.2.5-2.PU_IAS.1.src.rpm
Wrote: %_topdir/RPMS/x86_64/packagex-1.2.5-2.PU_IAS.1.x86_64.rpm
Wrote: NaVclean): /bin/sh -e /var/tmp/rpm-tmp.90228
+ umask 022 + cd %_topdir/BUILD + cd packagex + rm -rf /tmp/packagex-1.2.5-2.PU_IAS.1-root + exit 0 

If all goes well you've built your first rpm :). If your package built successfully, you will see lines like those shown above "Wrote: package", if your build fails you will not see these lines and the exit status will not be 0 :(.

Writing your own Spec Files

Typical spec file

A typical rpm spec file contains a header section, description, prep, build, install, files, and script sections.

Mandatory headers are listed below in italics, there are many other optional fields, included here are some common ones.

Summary: Example spec file for a typical rpm package
Name: example
Version: 0.11
Release: 1.PU.2
License: GPL
Group: X11/Libraries
Source: ftp://ftp.princeton.edu/pub/example/example-%{version}.tar.gz
Source1: ftp://ftp.princeton.edu/pub/example/example-doc-%{version}.tar.gz
Source2: ftp://ftp.princeton.edu/pub/example/moreexamples.tgz
Patch0: example-fixpaths.patch
Patch1: example-security.patch
BuildRequires: XFree86-devel
BuildRequires: perl >
Icon: example.xpm
Vendor: Mathematics Dept. PU
Packager: Josko Plazonic < plazonic@math.princeton.edu>
URL: http://world.std.com/~xforms/
BuildRoot: /var/tmp/NaV{version}-root
Requires: /etc/blabla
plazonic@math.princeton.edu>
Description

%description
This is an example rpm, with no useful content or purpose, just here to show how to do it.
Prep

%setup -q -a 1
%patch0 -p1 -b .paths
%patch1 -p2
mkdir examples-additional
cd examples-additional
gunzip -dc % | tar xf -
Build

%build
%configure --with-special-option=princeton --exclude-motif
make
make additionalstuff
cd example-doc-%{version}
%configure --with-tex --with-pdf
make all
Install

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT{NaV{_sysconfdir}/example}
%makeinstall
pushd example-doc-%{version}
%makeinstall EXAMPLESPATH=$RPM_BUILD_ROOT%{_datadir}/example-doc
install -m755 examples-additional/example2 $RPM_BUILD_ROOT%{_datadir}/example-doc
perl -pi -e "s|$RPM_BUILD_ROOT||g" $RPM_BUILD_ROOT%{_mandir}/man*/*
Scripts

# post install script for the example-doc rpm
%post doc
echo "Thank you for installing me..."
# pre un-install script
%preun
echo "Oh why, why, are you removing me..."
Files

%files
%doc README COPYRIGHT
%attr(755,root,daemon) %{_bindir}/example
%{_sysconfdir}/example

#files to be contained in example-doc package
%files doc
%doc example-doc-%{version}/README
%{_datadir}/example-doc

# clean the build root - highly advisable
%clean
rm -rf $RPM_BUILD_ROOT

%changelog
* Tue Dec 11 2001 Josko Plazonic <plazonic@....> 0.11-1
- upgraded to the new version and fixed a few bugs plazonic@....>

Additional useful directives:

  • BuildArch?? - to force a particular architecture on build, e.g. for perl modules ("BuildArch?: noarch")
  • %postun (post install), %pre (pre install) scripts
  • %setup options (setup macro understands tar.gz, tgz, tar.bz2, zip and maybe other archives...)
  • -n name will set the name of the build directory to the listed name. The default is $NAME-$VERSION.
  • -c will create and cd to the named directory before doing the untar
  • -b # will untar Source# before cd'ing into the directory (and this makes no sense with -c so don't do it). This is only useful with multiple source files
  • a # will untar Source# after cd'ing into the directory
  • -T This option overrides the default action of untarring the Source and requires a -b 0 or -a 0 to get the main source file untarred. You need this when there are secondary sources
  • -D Do not delete the directory before unpacking. This is only useful where you have more than one setup macro. It should only be used in setup macros after the first one (but never in the first one).

Attachments (1)

Download all attachments as: .zip