Monday, 22 October 2012

RPM Writing Lab

The purpose of doing this lab is to create an RPM package. So here we go.

Preparation

First, we need to install the building packages.


| yum groupinstall "Fedora Packager"
| yum install rpmlint yum-utils

Then I created ~/rpmbuild directories and ~/.rpmmacros by using this command.

Steps

First, we need to install the building packages.

| rpmdev-setuptree

* run this command as a regular user

This prepared the package environment for the next steps.


Create RPM package

To create an RPM package, I need to have a ".spec" file that contains infomation about the software being packaged. To generate a default spec file, issue the command rpmdev-newspec "package" under the SPEC directory. Edit the spec file until it compiles without an error. After that, check the spec file, SRPM, and RPM file by rpmlint for any error and warning. These are basic steps for creating an RPM package. For more detailed infomation related to the spec file, building process, and examples, please check the following wiki page.
 => How to create an RPM package

which

I copied the tarball into ~/rpmbuild/SOURCES. The file should be located in the SOURCES directory since the spec file will look for source file in this directory when you build the rpm package.

| cp which-2.20.tar.gz ~/rpmbuild/SOURCES

Create an empty skeleton spec file:

| rpmdev-newspec ~/rpmbuild/SPEC/which.spec

Edit the spec file to include necessary information for building "which" package. Below is my first spec file.


Time to build the package!

| cd ~/rpmbuild/SPEC/
| rpmbuild -ba which.spec


The build was successful! Then I got RPMs and source RPM built in the following directories.

rpmbuild
├── BUILD
│   └── which-2.20

├── BUILDROOT
├── RPMS
│   └── x86_64
│       ├── which-2.20-1.fc17.x86_64.rpm
│       └── which-debuginfo-2.20-1.fc17.x86_64.rpm
├── SOURCES
│   └── which-2.20.tar.gz
├── SPECS
│   └── which.spec
└── SRPMS
    └── which-2.20-1.fc17.src.rpm


The next step was to check if all of my package files can pass the rpmlint test. rpmlint is a tool to check common problems in rpm packages.

I ran rpmlint for the spec file, SRPM file, and two RPMs.

| rpmlint ~/rpmbuild/SPEC/which.spec
| rpmlint ~/rpmbuild/RPMS/x86_64/which-2.20-1.fc.17.x86_64.rpm
| rpmlint ~/rpmbuild/RPMS/x86_64/which-debuginfo-2.20-1.fc.17.x86_64.rpm
| rpmlint ~/rpmbuild/SRPMS/which-2.20-1.fc.17.src.rpm

I got some errors for RPMs.
 


And I did a lot of research on the Internet as well as the Common Rpmlint issues. I added "post" and "preun" sections in my spec file.This time the build went though without an error. Also the rpmlint which.spec and RPM, SRPM tests passed with 0 error and warning.

I still had 5 errors for debuginfo RPM package. I found this fix regarding to "incorrect-fsf-address" error on the wiki site.

"In all cases, upstream should be informed about this. This is the only requirement with respect to this error.

The license file, usually COPYING, must not be patched for legal reasons. Other files can be patched if deemed suitable. The updated GPL 2.0 license (the usual case) with correct address is at GPL-2.0.txt"

So I removed COPYING file in the %doc section of spec file and I still got the same error. The which package uses GPLv3 license and I think the reason for this error is because the COPYING file was not 100% equal to the original license file. So this error wouldn't affect the actual package building process.


hello

Follow the same steps as creating which package. I created "hello.spec" template and edited the spec file. When I tried to build the spec file, I got the following errors. And the build was unsucessful.

error: Installed (but unpackaged) file(s) found:
   /usr/share/locale/bg/LC_MESSAGES/hello.mo
   /usr/share/locale/ca/LC_MESSAGES/hello.mo
   /usr/share/locale/da/LC_MESSAGES/hello.mo
   /usr/share/locale/de/LC_MESSAGES/hello.mo
   /usr/share/locale/el/LC_MESSAGES/hello.mo
   /usr/share/locale/eo/LC_MESSAGES/hello.mo
   /usr/share/locale/es/LC_MESSAGES/hello.mo
   /usr/share/locale/et/LC_MESSAGES/hello.mo
   /usr/share/locale/eu/LC_MESSAGES/hello.mo
   /usr/share/locale/fa/LC_MESSAGES/hello.mo
...........................

...........................
   /usr/share/locale/uk/LC_MESSAGES/hello.mo
   /usr/share/locale/vi/LC_MESSAGES/hello.mo
   /usr/share/locale/zh_CN/LC_MESSAGES/hello.mo
   /usr/share/locale/zh_TW/LC_MESSAGES/hello.mo



Since the unpackaged files seemed like all language files, I added the following lines in the spec file.

%find_lang hello

%files -f hello.lang

Then the build was successful with "exit 0".

Also rpmlint for all four files were passed without errors and warnings.


Done!

Here's the link to all the files I've created in this lab.
=> which package (spec file, RPMs, SRPM)
=> hello package files

Until here my first RPMs have been created. Thanks for reading. :)



Build from Source

Intro...

For this lab, I'm going to install two packages from GNU software collection and check the package build and process. It is also a preparation before I build my first SPEC file for Fedora package.

The packages I've picked are "which" and "hello".

So let me start with the software building environment preparation.

Preparation

1. Install development tools for software building process.


yum groupinstall "Development Tools" "Development Libraries"

 (Note: need to be root to perform yum installs)


2. Download which and hello packages from GNU software collection.

Which => http://carlo17.home.xs4all.nl/which/
Hello => http://www.gnu.org/software/hello/

3. Now we are ready to build our packages!

Building package


- Which is used for locating a program file in the user's path.

- Hello is a simple greeting program.

The following is how I built my packages. First, I unpacked the tarball file by using the following command.

 | tar -xvzf which-2.20.tar.gz


| tar -xvzf hello-2.8.tar.gz

Then I read through the INSTALL file inside each folder for the build instruction. And both of them use make to build. I need to run the configure script which configures the build environment for Fedora 17. Then compile the package by make command, finally use make install to install package.

The following screenshots show successful building results as well as the building time it takes for which and hello package.

| ./configure
* configure the build environment

which: 
hello:


| make

* build the package

which:
hello:



| make install

 * install package



Now the build of two packages are complete. The compilation and building speeds are different based on the the size of the package.

Here is the running output of using which and hello.


Done and done..

Overall the building process is fun. Even though it's more steps to do than simply using "yum install", I can understand the package building better. I didn't get stuck during whole process. But when I choose which GNU package I will install has taken me a long time. In the beginning I choose "dia" which is a drawing program to build. Then I got into a issue for the build environment. I didn't want to install the x window on my fedora since I have very limited disk space for this VM... So I choose the tiny "hello" package to build instead.


My next blog will talk about how to create an RPM package... See you...