|
|
(76 intermediate revisions by 35 users not shown) |
Line 1: |
Line 1: |
| This is a tutorial on writing RPM files, suitable for someone familiar with
| | {{autolang|base=yes}} |
| the FOSS software building process, and with using pre-made RPM packages.
| |
|
| |
|
| This tutorial uses the GNU "Hello World". While 'Hello World" is a trivial program, the GNU project | | {{admon/important|This page is deprecated|As part of documentation move to docs.fp.o, this page has moved to https://docs.fedoraproject.org/en-US/quick-docs/create-hello-world-rpm/}} |
| contains most of the usual peripheral components associated with a typical FOSS software project,
| |
| such as the configuration/build/install environment, documentation, internationalization, etc., so it
| |
| is a reasonable vehicle to practice building RPMs on.
| |
| | |
| I wrote this tutorial after reading Christoph Wickert's IRC class on building RPMs.
| |
| Rahul Sundaram suggested using GNU "Hello World" as a test case, and it turns out
| |
| that Christian Lyder Jacobsen also had
| |
| [http://www.absolutepanic.org/blog/2009/07/building-a-gnu-hello-world-rpm this idea]
| |
| in 2009. Christian is not intending to update his website, so I decided to publish my
| |
| version in this wiki.
| |
| | |
| == Development environment ==
| |
| | |
| To build RPMs we need a set of development tools. This is a one-time-only setup,
| |
| installed by running those commands from a system administration (<code>root</code>) account:
| |
| | |
| <pre>
| |
| yum groupinstall development-tools
| |
| yum install rpm-build rpmdevtools
| |
| </pre>
| |
| | |
| Those are the only commands requiring <code>root</code> privileges. All the remaining
| |
| work should be done from your regular, non-privileged account. Modern RPM-based
| |
| systems, including Fedora, are set up to build and test RPM packages purely from
| |
| within a non-privileged account. The command
| |
| | |
| <pre>rpmdev-setuptree</pre>
| |
| | |
| sets up a RPM build
| |
| area in your <code>~/rpmbuild</code>. This directory will contain several subdirectories,
| |
| for the project source code, RPM configuration files and for the resulting source and binary
| |
| packages.
| |
| | |
| == Building "Hello World" ==
| |
| | |
| We need the source code of the project we are packaging in the ~/rpm/SOURCE directory. We need
| |
| a compressed tarball, which happens to be a preferred distribution form for most FOSS projects
| |
| | |
| <pre>
| |
| cd ~/rpm/SOURCE
| |
| wget http://ftp.gnu.org/gnu/hello/hello-2.5.tar.gz
| |
| </pre>
| |
| | |
| The
| |
| Next, you want to create a template .spec file in the ~/rpm/SPECS directory:
| |
| | |
| cd ~/rpm/SPECS
| |
| rpmdev-newspec hello
| |
| | |
| This will create a template spec file, hello.spec. The fields in
| |
| this file need slight editing as described below:
| |
| | |
| Name: hello
| |
| Version: 2.5 (the version is from upstream while Release is from Fedora)
| |
| Release: 1
| |
| Summary: should be short and precise. Only keywords, simple phrases
| |
| e.g. "Widget management application". First letter uppercase to avoid
| |
| rpmlint complaints
| |
| Group: from /usr/share/doc/rpm-4.6.0/GROUPS but groups not used any more
| |
| License: GPLv3 (check the source for the license it is released under)
| |
| URL: http://ftp.gnu.org/gnu/hello (The homepage of the program)
| |
| Source0: http://ftp.gnu.org/gnu/hello/hello-2.5.tar.gz (the URL for
| |
| the source distribution files)
| |
| | |
| Now comment out BuildRequires and Requires with a # for now,
| |
| | |
| %description:
| |
| Package summary; text starts on next line, ends with empty line
| |
| | |
| BuildRoot is the location where we are building the package,
| |
| temporary folder, default is OK
| |
| | |
| %prep is for preparing , eg. extracting the source and applying patches
| |
| if there are any
| |
| | |
| The actual build commands are specified in %build
| |
| usually you run ./configure and make.
| |
| A recently popular 'make' replacement waf is sometimes used used for
| |
| builds; it automatically configures the build:
| |
| ./waf build replaces %configure; make %{?_smp_mflags}
| |
| | |
| | |
| After that the files are installed to a temporary location during
| |
| %install, usually 'make install'
| |
| | |
| %install
| |
| rm -rf $RPM_BUILD_ROOT remains as is for cleaning up old stuff
| |
| from a previous build that failed
| |
| "make install DESTDIR=$RPM_BUILD_ROOT" or
| |
| "DESTDIR=$RPM_BUILD_ROOT ./waf install"
| |
| | |
| %clean remains as is
| |
| | |
| The template %changelog is as follows (include the version to avoid
| |
| rpmlint complains)
| |
| * Sun Apr 05 2009 Foo Bar <foo@bar.com> - 0.3.1-1
| |
| - Initial attempt
| |
| | |
| We are ready for the first run to build source, binary and debugging packages:
| |
| | |
| rpmbuild -ba hello.spec
| |
| | |
| It will probably complain about unpackaged files. We need to declare them in the
| |
| %files section. When you add them, do not hardcode /usr/bin/, but use
| |
| %{_bindir}/hello instead
| |
| After editing, rerun rpmbuild.
| |
| | |
| If the program uses translations, use %find_lang ${name}
| |
| in %install and BuildRequires: gettext , and %files -f ${name}.lang as
| |
| explained in
| |
| https://fedoraproject.org/wiki/Packaging/Guidelines#Handling_Locale_Files
| |
| | |
| If the program uses GNU info files, you need to do some magic:
| |
| - delete the 'dir' file in %install: rm -f $RPM_BUILD_ROOT/usr/share/info/dir
| |
| - Requires(post): info and Requires(preun): info
| |
| - add postinstall and preuninstall steps to configure info:
| |
| | |
| %post
| |
| /sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || :
| |
| | |
| %preun
| |
| if [ $1 = 0 ] ; then
| |
| /sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || :
| |
| fi
| |
| | |
| With this spec file, you should be able to successfully recreate the
| |
| RPMs. Next you should check them for conformance with RPM design
| |
| rules, by running rpmlint
| |
| on the spec file and all RPMs: rpmlint hello.spec ../SRPMS/hello*
| |
| ../RPMS/*/hello*
| |
| If there are no warnings or errors, we've succeeded.
| |
| | |
| To check that the package build will succeed in the Fedora restricted
| |
| build environment, check it with mock. Your account needs to be in the
| |
| 'mock' group for
| |
| mock to work, so you may need to do one-time setup, like so:
| |
| | |
| sudo usermod -a -G mock przemek
| |
| | |
| and then run mock:
| |
| | |
| mock -r fedora-12-i386 --rebuild ../SRPMS/hello-2.5-1.fc12.src.rpm
| |