| 1 | = Getting started with RPM Building = |
| 2 | |
| 3 | ow to get started with building RPMS - in particular how to setup your build environment and the basics of spec file writing. |
| 4 | Getting Started |
| 5 | |
| 6 | RPM Building (PDF) |
| 7 | 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 |
| 8 | |
| 9 | [joe@host ~] cat .rpmmacros |
| 10 | %_topdir $HOME/src |
| 11 | |
| 12 | You'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 | |
| 17 | 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 |
| 18 | |
| 19 | [joe@host ~] rpm -Uvh packagex.src.rpm |
| 20 | |
| 21 | 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. |
| 22 | To build this rpm using that spec: |
| 23 | |
| 24 | [joe@host ~] rpmbuild -ba packagex.spec |
| 25 | Executing(%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 | . |
| 29 | Wrote: %_topdir/SRPMS/packagex-1.2.5-2.PU_IAS.1.src.rpm |
| 30 | Wrote: %_topdir/RPMS/x86_64/packagex-1.2.5-2.PU_IAS.1.x86_64.rpm |
| 31 | Wrote: 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 | |
| 34 | 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 :(. |
| 35 | |
| 36 | Writing your own Spec Files |
| 37 | |
| 38 | Typical spec file |
| 39 | |
| 40 | A typical rpm spec file contains a header section, description, prep, build, install, files, and script sections. |
| 41 | |
| 42 | Header |
| 43 | |
| 44 | Mandatory headers are listed below in italics, there are many other optional fields, included here are |
| 45 | some common ones. |
| 46 | |
| 47 | Summary: Example spec file for a typical rpm package |
| 48 | Name: example |
| 49 | Version: 0.11 |
| 50 | Release: 1.PU.2 |
| 51 | License: GPL |
| 52 | Group: X11/Libraries |
| 53 | Source: ftp://ftp.princeton.edu/pub/example/example-%{version}.tar.gz |
| 54 | Source1: ftp://ftp.princeton.edu/pub/example/example-doc-%{version}.tar.gz |
| 55 | Source2: ftp://ftp.princeton.edu/pub/example/moreexamples.tgz |
| 56 | Patch0: example-fixpaths.patch |
| 57 | Patch1: example-security.patch |
| 58 | BuildRequires: XFree86-devel |
| 59 | BuildRequires: perl > |
| 60 | Icon: example.xpm |
| 61 | Vendor: Mathematics Dept. PU |
| 62 | Packager: Josko Plazonic < [email protected]> |
| 63 | URL: http://world.std.com/~xforms/ |
| 64 | BuildRoot: /var/tmp/NaV{version}-root |
| 65 | Requires: /etc/blabla |
| 66 | [email protected]> |
| 67 | Description |
| 68 | |
| 69 | %description |
| 70 | This is an example rpm, with no useful content or purpose, just here to show how to do it. |
| 71 | Prep |
| 72 | |
| 73 | %setup -q -a 1 |
| 74 | %patch0 -p1 -b .paths |
| 75 | %patch1 -p2 |
| 76 | mkdir examples-additional |
| 77 | cd examples-additional |
| 78 | gunzip -dc % | tar xf - |
| 79 | Build |
| 80 | |
| 81 | %build |
| 82 | %configure --with-special-option=princeton --exclude-motif |
| 83 | make |
| 84 | make additionalstuff |
| 85 | cd example-doc-%{version} |
| 86 | %configure --with-tex --with-pdf |
| 87 | make all |
| 88 | Install |
| 89 | |
| 90 | %install |
| 91 | rm -rf $RPM_BUILD_ROOT |
| 92 | mkdir -p $RPM_BUILD_ROOT{NaV{_sysconfdir}/example} |
| 93 | %makeinstall |
| 94 | pushd example-doc-%{version} |
| 95 | %makeinstall EXAMPLESPATH=$RPM_BUILD_ROOT%{_datadir}/example-doc |
| 96 | install -m755 examples-additional/example2 $RPM_BUILD_ROOT%{_datadir}/example-doc |
| 97 | perl -pi -e "s|$RPM_BUILD_ROOT||g" $RPM_BUILD_ROOT%{_mandir}/man*/* |
| 98 | Scripts |
| 99 | |
| 100 | # post install script for the example-doc rpm |
| 101 | %post doc |
| 102 | echo "Thank you for installing me..." |
| 103 | # pre un-install script |
| 104 | %preun |
| 105 | echo "Oh why, why, are you removing me..." |
| 106 | Files |
| 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 |
| 120 | rm -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). |