Create A Basic RPM Package For PCLinuxOS

by Daniel MeiƟ-Wilhelm (Leiche)

In the last issues we created a servicemenu for KDE4 in PCLinuxOS. We discovered what works well, and we want share it with other PCLinuxOS users. But how do we do it?

First, you should read this:

Neal wrote about creating an RPM Package. Following his advice in his article, you will find his description about the commands within a specfile, how the commands work, and how the specfile should be structured.

I keep a blank specfile in my work directory, with most of the commands that are needed to build a package.

%define prefix /usr
 %define name
 %define version
 %define release %mkrel 1
 %define url 
Name:        %{name}
 Version:      %{version}
 Release:      %{release}
 URL:        %{url}
 BuildRoot:     %{_tmppath}/%{name}-buildroot
 Obsoletes:     %name < %version 

%description -l de 
%setup -q -n %{name}-%{version} 
 rm -rf $RPM_BUILD_ROOT 
 rm -rf %{buildroot}
 rm -rf $RPM_BUILD_DIR/%{name}-%{version} 

Now we fill in the empty rows. I added the information for Zip_Player in italics.

%define prefix /usr
Where it should be installed seamlessly in /usr
%define name Zip_Player
add the name of the package
%define version 0.1
the actual version of your program
%define release %mkrel 3
needed for rebuild information by the actual version. Currently, release 0.1-3 of Zip_Player is in our repositories.
%define url — add your homepage or something else, for example: sourceforge

The header is done, but we can still add more to it. We have defined the macros, and now we can work with them.

It's time to get the ingredients for our package.

Name: %{name}
With the %{name} macros we set the name of our package
Version: %{version}
Version has the same function as Name
Release: %{release}
Release has the same function as Name
License: GPL
the license our program will have
Group: Sound
the category displayed by the package manager
URL: %{url}
URL has the same function as Name
Source: %{name}-%{version} .tar.gz
the archive containing the program
Summary: Zip_Player plays Your music in zip-archive
summary of the program
Summary(de): Zip_Player spielt Musik aus Zip Archive
summary of the program in German language (you can add other languages, also)
BuildRoot: %{_tmppath}/%{name}-buildroot
where the package should be built
Requires: xmms, unzip, zenity,
other packages needed by the program at runtime
Obsoletes: %name < %version
will remove the older version of a package
%description Z ip Player XMMS plays Your music in zip-archive. (Created by leiche)
a description of the package
#german %description -l de Zip Player XMMS spielt Musik aus Zip Archive. (Erstellt von leiche)
for the German user, the description for synaptic or smart package management.

Now we have the ingredients, and we can build our package for PCLinuxOS.

With these commands

%setup -q -n %{name}-%{version}

the archive will unpack in the BUILD directory.

What is needed for an archive?

We must create a tar.bz2 or tar.gz archive to add our script and desktop files. But we need only the scripts that handle our program. Why only the script files? The answer comes later.

To create an archive, we generate a folder named zip_player.-0.1. In this folder we put our script files, then click on the folder with the right mouse button. In the right click menu you find Compress >> CompressAsTar. Select that option and the archive zip_player-0.1.tar.gz is created. This must be stored in SOURCES in our RPM directory.

Now our archive will unpack the BUILD directory to install in the buildroot directory, which is /tmp directory.

But our program is still just source code, not executable code. So we must create the executable from the sourc with cmake, or configure and make, before we can install it. Our app doesn't need configure or cmake, so we can remove the following lines from our specfile.


In my opinion, we can use direct install...

If an older build exists in the buildroot directory, it will be removed, so we have no errors when building a new package.
install -d -m 755 $RPM_BUILD_ROOT%{_bindir}
The directory where the compiled package will be installed (/usr/bin), and what permissions are given to the installed package
install -m 755 zip_player $RPM_BUILD_ROOT%{_bindir}
What should be installed ( zip_player) and what permissions are given to the installed package

Now our scripts are installed, but not the desktop files. Those can we now generate with our specfile.

mkdir -p %{buildroot}%{_datadir}/applications
Create the application's folder in /usr/share/. This is the path for all desktop files that are placed in the start menu.
cat > %{buildroot}%{_datadir}/applications/%{name}.desktop
[Desktop Entry]
Name=Zip Player XMMS
Name[de]=Zip Player XMMS
Comment=plays music in zip archives
Comment[de]=spielt Musik aus den ZIP Archiven

cat creates the desktop file Zip_Player.desktop in /usr/share/applications/. Between EOF stanzas is where the desktop entry should be placed.

Now we can add the servicemenu for KDE4 in /usr/share/kde4/services/ServiceMenus.

mkdir -p %{buildroot}%{_datadir}/kde4/services/ServiceMenus
Create the folder ServiceMenus in /usr/share/kde4/services
%__cat > %{buildroot}%{_datadir}/kde4/services/ServiceMenus/%{name}.desktop << EOF

[Desktop Entry]
[Desktop Action zip_player]
Name=Zip Player XMMS

cat generates the desktop file zip_player in /usr/share/kde4/services/ServiceMenus



Texstar has said that %post and %postun is only needed if your package is installing library files say in /usr/lib and you need them to be registered or unregistered with your install. But the specfile is clean, and it updates the menus and desktop database. Is it needed? I don't know, but it doesn't seem to do any harm.

Finally, the files contained in the package are now defined.

This function defines the permissions and properties.
Install the zip_player in /usr/bin.
This is the same as zip_player.
Install the desktop file in /usr/share/applications, which will be displayed in the start menu.
Install the desktop file in /usr/share/services/ServiceMenus, which will be displayed in the right click menu.

Now the changelog, to see what is changed or added, and by whom.

* Wed May 26 2010 Texstar <texstar at> 0.1-4pclos2010
- fix rpm/synaptic group Sound

* Sat May 08 2010 leiche <meisssw01 at> 0.1-3pclos2010

- Open Browser filtering *.zip files - added correct name of Zip Player in Zip Player XMMS * Wed Apr 28 2010 leiche <meisssw01 at> 0.1-2pclos2010 - shows servicemenu only for zipfiles - change file open browser from kdialog to zenity * Thu Mar 04 2010 leiche <meisssw01 at> 0.1-1pclos2010 - created for pclinuxos

Now it's time to generate our package, so we open a konsole in the directory /home/daniel/src/rpm/SPECS/, and type the command:

rpm -ba Zip_player.spec

We did not save our specfile in rpm/SPECS/, so create it before you open a konsole, and name the file Zip_Player.


If the package compiles without errors, the result is a package named Zip_Player-0.1-4pclos2010.i586.rpm.


NOTE: I'm an absolute Rookie at creating an RPM package, and the tutorial is a little thin on the details. To learn more about RPM packaging, visit:,55.0.html.

Last words, I hope it helps somebody to work with scripts, ServiceMenus, and RPMs under PCLinuxOS.

Good luck.