Changes between Initial Version and Version 1 of RPMBuilding

Aug 3, 2010 12:00:29 PM (11 years ago)



  • RPMBuilding

    v1 v1  
     1= Getting started with RPM Building =
     3ow to get started with building RPMS - in particular how to setup your build environment and the basics of spec file writing.
     4Getting Started
     6RPM Building (PDF)
     7To 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
     9[joe@host ~] cat .rpmmacros
     10%_topdir $HOME/src
     12You'll need to create /home/$USER/src as well, with the following subdir's: SRPMS SPECS BUILD SOURCES RPMS
     14[joe@host ~] cd
     15[joe@host ~] mkdir -p src/SRPMS src/SPECS src/BUILD src/SOURCES src/RPMS
     17to 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
     19[joe@host ~] rpm -Uvh packagex.src.rpm
     21This 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.
     22To build this rpm using that spec:
     24[joe@host ~] rpmbuild -ba packagex.spec
     25Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.55587
     26+ 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 - .
     29Wrote: %_topdir/SRPMS/packagex-1.2.5-2.PU_IAS.1.src.rpm
     30Wrote: %_topdir/RPMS/x86_64/packagex-1.2.5-2.PU_IAS.1.x86_64.rpm
     31Wrote: NaVclean): /bin/sh -e /var/tmp/rpm-tmp.90228
     32+ umask 022 + cd %_topdir/BUILD + cd packagex + rm -rf /tmp/packagex-1.2.5-2.PU_IAS.1-root + exit 0
     34If 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 :(.
     36Writing your own Spec Files
     38Typical spec file
     40A typical rpm spec file contains a header section, description, prep, build, install, files, and script sections.
     44Mandatory headers are listed below in italics, there are many other optional fields, included here are
     45some common ones.
     47Summary: Example spec file for a typical rpm package
     48Name: example
     49Version: 0.11
     50Release: 1.PU.2
     51License: GPL
     52Group: X11/Libraries
     56Patch0: example-fixpaths.patch
     57Patch1: example-security.patch
     58BuildRequires: XFree86-devel
     59BuildRequires: perl >
     60Icon: example.xpm
     61Vendor: Mathematics Dept. PU
     62Packager: Josko Plazonic <>
     64BuildRoot: /var/tmp/NaV{version}-root
     65Requires: /etc/blabla>
     70This is an example rpm, with no useful content or purpose, just here to show how to do it.
     73%setup -q -a 1
     74%patch0 -p1 -b .paths
     75%patch1 -p2
     76mkdir examples-additional
     77cd examples-additional
     78gunzip -dc % | tar xf -
     82%configure --with-special-option=princeton --exclude-motif
     84make additionalstuff
     85cd example-doc-%{version}
     86%configure --with-tex --with-pdf
     87make all
     91rm -rf $RPM_BUILD_ROOT
     92mkdir -p $RPM_BUILD_ROOT{NaV{_sysconfdir}/example}
     94pushd example-doc-%{version}
     95%makeinstall EXAMPLESPATH=$RPM_BUILD_ROOT%{_datadir}/example-doc
     96install -m755 examples-additional/example2 $RPM_BUILD_ROOT%{_datadir}/example-doc
     97perl -pi -e "s|$RPM_BUILD_ROOT||g" $RPM_BUILD_ROOT%{_mandir}/man*/*
     100# post install script for the example-doc rpm
     101%post doc
     102echo "Thank you for installing me..."
     103# pre un-install script
     105echo "Oh why, why, are you removing me..."
     110%attr(755,root,daemon) %{_bindir}/example
     113#files to be contained in example-doc package
     114%files doc
     115%doc example-doc-%{version}/README
     118# clean the build root - highly advisable
     120rm -rf $RPM_BUILD_ROOT
     122== Changelog ==
     126* Tue Dec 11 2001 Josko Plazonic <plazonic@....> 0.11-1
     127- upgraded to the new version and fixed a few bugs plazonic@....>
     130== Additional useful directives: ==
     132* BuildArch? - to force a particular architecture on build, e.g. for perl modules ("BuildArch: noarch")
     133* %postun (post install), %pre (pre install) scripts
     134* %setup options (setup macro understands tar.gz, tgz, tar.bz2, zip and maybe other archives...)
     135* -n name will set the name of the build directory to the listed name. The default is $NAME-$VERSION.
     136* -c will create and cd to the named directory before doing the untar
     137* -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
     138* a # will untar Source# after cd'ing into the directory
     139* -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
     140* -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).