Changes between Initial Version and Version 1 of RPMBuilding


Ignore:
Timestamp:
Aug 3, 2010 12:00:29 PM (11 years ago)
Author:
thomas
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RPMBuilding

    v1 v1  
     1= Getting started with RPM Building =
     2
     3ow to get started with building RPMS - in particular how to setup your build environment and the basics of spec file writing.
     4Getting Started
     5
     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
     8
     9[joe@host ~] cat .rpmmacros
     10%_topdir $HOME/src
     11
     12You'll need to create /home/$USER/src as well, with the following subdir's: SRPMS SPECS BUILD SOURCES RPMS
     13
     14[joe@host ~] cd
     15[joe@host ~] mkdir -p src/SRPMS src/SPECS src/BUILD src/SOURCES src/RPMS
     16
     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
     18
     19[joe@host ~] rpm -Uvh packagex.src.rpm
     20
     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:
     23
     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 - .
     27.
     28.
     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
     33
     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 :(.
     35
     36Writing your own Spec Files
     37
     38Typical spec file
     39
     40A typical rpm spec file contains a header section, description, prep, build, install, files, and script sections.
     41
     42Header
     43
     44Mandatory headers are listed below in italics, there are many other optional fields, included here are
     45some common ones.
     46
     47Summary: Example spec file for a typical rpm package
     48Name: example
     49Version: 0.11
     50Release: 1.PU.2
     51License: GPL
     52Group: X11/Libraries
     53Source: ftp://ftp.princeton.edu/pub/example/example-%{version}.tar.gz
     54Source1: ftp://ftp.princeton.edu/pub/example/example-doc-%{version}.tar.gz
     55Source2: ftp://ftp.princeton.edu/pub/example/moreexamples.tgz
     56Patch0: example-fixpaths.patch
     57Patch1: example-security.patch
     58BuildRequires: XFree86-devel
     59BuildRequires: perl >
     60Icon: example.xpm
     61Vendor: Mathematics Dept. PU
     62Packager: Josko Plazonic < plazonic@math.princeton.edu>
     63URL: http://world.std.com/~xforms/
     64BuildRoot: /var/tmp/NaV{version}-root
     65Requires: /etc/blabla
     66plazonic@math.princeton.edu>
     67Description
     68
     69%description
     70This is an example rpm, with no useful content or purpose, just here to show how to do it.
     71Prep
     72
     73%setup -q -a 1
     74%patch0 -p1 -b .paths
     75%patch1 -p2
     76mkdir examples-additional
     77cd examples-additional
     78gunzip -dc % | tar xf -
     79Build
     80
     81%build
     82%configure --with-special-option=princeton --exclude-motif
     83make
     84make additionalstuff
     85cd example-doc-%{version}
     86%configure --with-tex --with-pdf
     87make all
     88Install
     89
     90%install
     91rm -rf $RPM_BUILD_ROOT
     92mkdir -p $RPM_BUILD_ROOT{NaV{_sysconfdir}/example}
     93%makeinstall
     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*/*
     98Scripts
     99
     100# post install script for the example-doc rpm
     101%post doc
     102echo "Thank you for installing me..."
     103# pre un-install script
     104%preun
     105echo "Oh why, why, are you removing me..."
     106Files
     107
     108%files
     109%doc README COPYRIGHT
     110%attr(755,root,daemon) %{_bindir}/example
     111%{_sysconfdir}/example
     112
     113#files to be contained in example-doc package
     114%files doc
     115%doc example-doc-%{version}/README
     116%{_datadir}/example-doc
     117
     118# clean the build root - highly advisable
     119%clean
     120rm -rf $RPM_BUILD_ROOT
     121
     122== Changelog ==
     123
     124{{{
     125%changelog
     126* Tue Dec 11 2001 Josko Plazonic <plazonic@....> 0.11-1
     127- upgraded to the new version and fixed a few bugs plazonic@....>
     128}}}
     129
     130== Additional useful directives: ==
     131
     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).