Building a Fedora RPM

The RPM build process starts with having the proper software on your system. I installed the packages below (as the root user):
root@LoneWolf:~# yum groupinstall “Fedora Packager”
root@LoneWolf:~# yum install rpmlint yum-utils

Package rpmlint-1.0-2.fc14.noarch already installed and latest version
Package yum-utils-1.1.28-1.fc14.noarch already installed and latest version
Nothing to do

Change to a regular user account to build RPMs; it is best if you do not execute builds as the root user, it could really mess up your system if something gets installed improperly.
root@LoneWolf:~# logout

The directory structure for an RPM build must now be set up:
LoneWolf@LoneWolf:~$ rpmdev-setuptree

This command makes a directory called “rpmbuild” in your home directory:
LoneWolf@LoneWolf:~$ dir
Desktop    Downloads  Pictures    rpmbuild Videos
Documents  Music      Public    Templates

There are six directories inside the “rpmbuild” directory:
LoneWolf@LoneWolf:~$ cd /home/LoneWolf/rpmbuild/
LoneWolf@LoneWolf:rpmbuild$ dir
BUILD  BUILDROOT  RPMS    SOURCES  SPECS    SRPMS

First your source code packages must be in the “SOURCES” directory:
cp /home/LoneWolf/Desktop/MakeTest/*.gz.* rpmbuild/SOURCES/

As you can see I am trying to build RPMS for “less” and “gawk”. These packages are found here.
LoneWolf@LoneWolf:~$ cd rpmbuild/SOURCES
LoneWolf@LoneWolf:SOURCES$ dir
gawk-3.1.8.tar.gz  less-418.tar.gz

The next step is to change to the “SPECS” directory:
LoneWolf@LoneWolf:rpmbuild$ cd SPECS/

You then must generate a “spec” file for your RPM build. Skeleton spec files for the new RPM packages are generated with the command: rpmdev-newspec filename
LoneWolf@LoneWolf:SPECS$ rpmdev-newspec gawk-3.1.8
Skeleton specfile (minimal) has been created to “gawk-3.1.8.spec”.

LoneWolf@LoneWolf:SPECS$ rpmdev-newspec less-418
Skeleton specfile (minimal) has been created to “less-418.spec”.

Then edit the spec files for your RPM(s); some helpful resources can be found here:
Internet Resources:
Rpm specs file syntax
Packaging software with RPM, Part 1

rpm-guide.pdf (chapters 8,9,10 )

Handy Terminal Commands:
List the metadata for an RPM:
rpm -qi packagename

List the shared object and program dependencies for an RPM:
rpm -qR packagename

After reading (hopefully all) of the material posted above and with your (hopefully error-free) “spec” file ready to go, it is time to make an RPM! Execute the command:
rpmbuild -ba SPECS/yourRPMname.spec
LoneWolf@LoneWolf:rpmbuild$ rpmbuild -ba SPECS/less-418.spec

Result:
error: File not found: /home/LoneWolf/rpmbuild/BUILDROOT/less-418-1.fc14.x86_64/usr/doc/less-418/LICENSE
It would seem that one of the %doc files under the %files section in the specfile needs some fine-tuning.

Debugging specfiles can be tedious! The program “rpmlint” is used to check three files generated from your build: name.spec, your SRPM and your RPM. The “rpmlint” command is executed by entering “rpmlint /path/to/file“. After fixing all the errors reported from running rpmlint, this was the result from building the “less” package:
LoneWolf@LoneWolf:SPECS$ rpmlint ../RPMS/x86_64/less-418-1.fc14.x86_64.rpm
less.x86_64: W: spurious-executable-perm /usr/share/doc/less-418/COPYING
less.x86_64: W: spurious-executable-perm /usr/share/doc/less-418/INSTALL
less.x86_64: W: spurious-executable-perm /usr/share/doc/less-418/LICENSE
1 packages and 0 specfiles checked; 0 errors, 3 warnings.

LoneWolf@LoneWolf:SPECS$ rpmlint ../SRPMS/less-418-1.fc14.src.rpm
1 packages and 0 specfiles checked; 0 errors, 0 warnings.

LoneWolf@LoneWolf:SPECS$ rpmlint less.spec
0 packages and 1 specfiles checked; 0 errors, 0 warnings.

I am unsure about the warnings generated by running rpmlint on my RPM package; defining the executables as “%doc files” or defining the executables as just “files” makes no difference in this error message. From what I can gather, defining executables in the %files section of a SPEC file is considered bad practice because this may introduce additional dependencies in the finished RPM.

My “.spec” file for the “less” package is shown below:

Name:           less
Version:        418
Release:        1%{?dist}
Summary:        This is the distribution of “less”, a page navigator similar to “more” or “pg”

Group:          Applications/Text
License:        GPLv3+
URL:            http://www.greenwoodsoftware.com/less/
Source0:        http://ftp.gnu.org/gnu/less/%{name}-%{version}.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

%description
Less is a program similar to more.
Less allows backward  movement in the file as well as forward movement.

%prep
%setup -q

%build
%configure
make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
# Same as /usr/bin
%{_bindir}/*
# Same as path to man pages
%{_mandir}/*/*
%doc LICENSE
%doc COPYING
%doc  INSTALL
%doc NEWS
%doc README

%changelog
*Sat Jan 23 2011 – ldsoura (at) learn.senecac.on.ca 418-1
-Verbose descriptions for changes in packages are put here.
-This keeps track of specific changes and bug fixes in new builds.
-Note the the date and the version must both be present in the first line of changelog.

This next topic is a continuation of testing to assure that the RPM you have built will install without errors. Next topic: Building a Fedora RPM with “mock”.

Advertisements

About gr8can8dian

Certified Linux geek.
This entry was posted in SBR600. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s