From Fedora Project Wiki

(A tutorial on building RPM packages)
 
(Replace with notica about the new location at docs.fp.o)
Tag: Replaced
 
(78 intermediate revisions by 35 users not shown)
Line 1: Line 1:
Run these commands once from your personal account to prepare your
{{autolang|base=yes}}
system for development work:


sudo yum groupinstall development-tools
{{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/}}
sudo yum install rpm-build rpmdevtools
rpmdev-setuptree
 
You may have to set up sudo or just run the yum commands after
obtaining a root login shell. The last command sets up a RPM build
area in your home directory, usually in ~/rpmbuild or ~/rpm.
 
Next, retrieve the source code; presumably it will be a tar archive
from the project's website.
The tar archive has to end up in the ~/rpm/SOURCE, so you can
 
cd ~/rpm/SOURCE
wget  http://ftp.gnu.org/gnu/hello/hello-2.5.tar.gz
 
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

Latest revision as of 20:50, 26 May 2021