Sunday 5 February 2012

RPM Writing

Writing my first RPM was a rough and interesting process which required some effort put into build and testing. For this post I will explain the steps I took to write and build an rpm successfully. The RPM Package Manager (RPM) will contain a compiled version of software, which for me was the gnuchess software package.

There are some preparations we will have to do before we can start building RPM packages.

packages that we will require and need to install using yum command 
yum groupinstall "Fedora Packager"
yum install rpmlint yum-utils

next we will create the ~/rpmbuild directory which also creates six subdirectories within
The command to create ~/rpmbuild will also create ~/.rpmmacros file alongside, entering the one single command will create all this
rpmdev-setuptree

note: To clean out dev directories, we can use command rpmdev-wipetree

Now that we have the required packages installed and directories created we can start building our RPM package!!!

First we will put the source code in the form of a tarball in ~/rpmbuild/SOURCES directory, my tarball was gnuchess-6.0.1.tar.gz

Once this is done, we will change directory to ~/rpmbuild/SPECS to create an empty skeleton spec file. The spec file is essentially important as it defines the RPM we are building by containing metadata and scripting necessary for the build. We will create the skeleton spec file with the command
rpmdev-newspec nameofPackage example of name is gnuchess.spec

We can attempt to build our package right now with the command
rpmbuild -ba gnuchess.spec where -ba is for build all. However it's certain to get several errors as there is nothing written in the spec files eight sections.

I found this part of writing rpm to be the most challenging as using the rpmbuild command countless times had produce errors seen below

error: Installed (but unpackaged) file(s) found:
   /usr/bin/gnuchess
   /usr/bin/gnuchessu
   /usr/bin/gnuchessx
   /usr/share/gnuchess/book.bin
   /usr/share/gnuchess/gnuchess.ini
   /usr/share/info/dir
   /usr/share/info/gnuchess.info.gz

RPM build errors:
    Installed (but unpackaged) file(s) found:
   /usr/bin/gnuchess
   /usr/bin/gnuchessu
   /usr/bin/gnuchessx
   /usr/share/gnuchess/book.bin
   /usr/share/gnuchess/gnuchess.ini
   /usr/share/info/dir
   /usr/share/info/gnuchess.info.gz
 
After a little bit of searching on the web I found the problem to be that I have not included these files in my spec file. The solution I found to this was to include n my %files section of my spec file which was empty

%defattr(-,root,root,-)
%{_bindir}/*
%{_infodir}/*
/usr/share/gnuchess

note: This line will differ depending on the package that you are trying to build

After including these lines I re-ran rpmbuild -ba gnuchess.spec and finally created my RPM successfully as the command did not produce any errors and last line returned an exit status 0. To confirm I checked the RPMS folder for the binary rpm and the SRPMS for the source RPM to confirm the builds success as shown from the print screen of my terminal above.

We have now got a RPM created and in my next post I will be testing it with rpmlint for errors and warnings. This process I would say took me a good couple of hours to get to this stage as it involved some reading on spec file and testing. I have included some links that I found helpful to understand rpm's and also spec files and their sections.

packaging software with RPM from ibm.com 

how to create Spec file from fedoraproject.org

creating spec file from rpm.org


No comments:

Post a Comment