Sunday, December 7, 2008

Building Qt 4.4 for RHEL 5

As explained here, I wanted to build RPMs for Qt 4.4 for Red Hat Enterprise Linux 5. Compiling from sources was taking way too much time and was not attracting any developer love.

If you want to use Qt 4.4 with RHEL 5, you'll need an updated version of KDevelop ( > 3.4) too. And that requires an updated version of GDB (v6.8). So you'll need to find those RPMs as well.

Building an RPM is apparently a complicated process and you'll find lots of articles online (some very dated). But there's a way to reuse the packaging generated for Fedora. That way, you don't have to mess with source archives, patches and write spec files from scratch.

Getting the source packages

Koji is Fedora Project's build system. You can checkout source packages from and use it to build on RHEL. Cool, huh? But be aware of possible compatibility issues.
Using the search facility of Koji site, I downloaded the following src.rpm files.

In Koji, you'll find packages for several Fedora versions. I'll recommend using the lower Fedora versions (which matches the version of software you are looking for, of course), since RHEL is an old (F6 based) distro. Later Fedora versions may use different package versions or install paths and may cause problems with RHEL.

Preparing the build setup

Information on how to do this can be found in all rpm building tutorials. But I'll put it here too ;-)
1. Create an RPM build directory structure

$ cd ~
$ mkdir myrpms
$ cd myrpms
$ mkdir -p RPMS/i386 RPMS/athlon RPMS/i486 RPMS/i586 RPMS/i686 RPMS/noarch

2. Create a file named .rpmmacros in your home directory with contents:
%_topdir /home/yourusername/myrpms
or whatever to reflect your settings.

Apparently, this says that you can do all that with:
$ mkdir -p ~/myrpms/{BUILD,RPMS,S{OURCE,PEC,RPM}S}
$ echo -e "%_topdir\t$HOME/myrpms" >> ~/.rpmmacros

Installing the source rpm
$ rpm -ivh qt-4.4.0-11.fc10.src.rpm

The source (and patches) will go to the SOURCES directory, SPEC file in SPECS, and rpms after build will go in the RPMS directory.

Building Qt 4.4

The 'spec' file contains the instructions to the rpmbuild command to build the rpm. Open SPECS/qt.spec and see how it looks like. Note the BuildRequires: lines. Those are the packages that you must have inorder to build a package.
Some spec files will have conditional constructs using which they handle multiple build environments. To compile Qt 4.4 on RHEL 5, do this:
$ cd ~/myrpms/SPECS
$ ls qt.spec
$ rpmbuild --define "webkit:1" --define "rhel 5" -bb qt.spec

Most probably the above command will fail with lots of BuildRequires messages. You need to install all those packages before you can continue. You can make use of EPEL and RPMForge repositories to locate packages that are not in the official RHEL repos. The --define stuff is only required for Qt 4.4, and not for KDevelop, gdb etc. (in case you were wondering!).

In some cases (KDevelop, for example), you'll find that the spec file (originally meant for later versions of Fedora) will require packages like kdelibs3-devel, kdesdk3-devel etc. You need to install kdelibs-devel, kdesdk-devel etc. instead and modify the spec file.

Once you've installed the required packages, execute the rpmbuild command again. If all goes well, you'll see the RPM file in RPMS/ directory. For me it's i386. Try installing the rpm on your machine before you start distributing!

Note on KDevelop 3.5.3

You can find this RPM from This works fine with RHEL 5. But if you want to customize an RHEL install DVD, don't use that package. It has a self-obsoletion problem which will make the installer fail. Building the RPM by yourself is the only safe way.

Packages I've successfully built
Qt 4.4
KDevelop 3.5.3
GDB 6.8
Kst 1.7

Good luck. Build away..

Update: RHEL 5.3 now comes with gdb 6.8.27. Combined with a new kernel, all issues with debugging are now resolved. Hooray!

Saturday, December 6, 2008

Remastering Red Hat Enterprise Linux 5 DVD

In my office, the Linux buzz is growing, with more and more engineers trying their hand at Qt programming. I've been helping people install Red Hat Enterprise Linux 5 (RHEL 5) and get started with Qt 4. RHEL 5.1 comes with older (aka stable, or proven, as we like to call in our industry) versions of Qt, KDevelop and GDB.

So, to make things easier, I set out to customise an RHEL 5 DVD. My original plan was to create a kick-start file for easier installation. Then I became too ambitious and decided to customise the whole damn thing. After several days of meddling with rpms and xml files, I'm happy to announce SUCCESS!!

This post is meant to be a guide to all those brave souls who wish to do the same. Fear not, comrades, it's not as difficult as it looks like. In fact, if you don't want to build any new RPMs, it's quite easy. You can reportedly use a tool called Revisor to easily customise a Fedora / Red Hat distribution. I'm no sure about the effectiveness of this tool for RHEL, since I want to update and add packages to the base distro. The manual method I describe here involves copying RPM files, editing some XML files (simple) and re-creating the ISO image.
Here we go..

Before we start

I guess it's possible to do this from another installed distro, Fedora for instance. Since I wanted to download additional packages and didn't know how to do that from another distro, I first installed RHEL 5.1 on my machine. All steps I describe were done within that installation.
If you want to add more packages to your custom RHEL, checkout EPEL and RPMForge repositories. You'll find the setup instructions in the repective sites. You'll also need yumdownloader tool from the yum-utils package to download RPM files from the repositories. To install, do:

yum install yum-utils

Similarly, install the following programs/packages:
createrepo - for re-creating the YUM repo information
mkisofs - for creating the ISO image
anaconda-runtime - for inserting the 'media check' checksum

The install media structure

Make a copy of the install media tree. You can either copy files from the DVD, or mount the ISO file and copy from it.
To mount the ISO file:

mount -o loop /path/to/iso/file /path/to/mount/point

Make sure you copy all files. Including the hidden ones. There's one file named .discinfo. Make sure you get that one, otherwise the installer will not recognise your DVD. I'll assume you 've copied all files to some directory named rhel_custom.
The RPMs are located in Client, VT and Workstation directories. The isolinux directory contains files for the boot. We have license for Workstation edition, and so I'll explain for Client and Workstation directories, and I believe the steps are same for VT as well.

The repository information

Let's consider the Client directory. You'll find a directory called repodata which contains the repository information for YUM. You can delete all files except comps-rhel5-client-core.xml from that directory. We will re-create the repo information once we are done customizing.
Open the comps-rhel5-client-core.xml file using a text editor. Don't let the multi-lingual stuff scare you. The file is fairly straight forward. Scan through the first 7-8 lines.
As you can see, this file describes what you see in the package selection step of the installer. the tag defines the group called admin-tools and whose name is Administration Tools. Sound familiar?
Scroll down the the list of translations of the name, and you'll see description, and further down, the default and uservisible values. If default is true, that group will be selected by default. uservisible decides whether the group is visible to the user installing the distro. You'll find that some groups have this set to false.

Now comes the packagelist. Here are two sample lines:

<packagereq type="default">authconfig-gtk</packagereq>
<packagereq type="conditional" requires="aspell">aspell-af</packagereq>

The possible values for type are "mandatory", "default", "optional" and conditional.
Mandatory packages are installed if the group is selected, and won't even show up in the list. Default packages are shown in the list, and selected by default. Optional ones are listed, but not selected by default. Conditional packages are selected if the required package is selected.

Now it must be fairly simple to add a new package. For example, let's say we want to include kchmviewer, a CHM file viewer, to the distro.
We first download the RPM file (I assume you've setup EPEL and RPMForge correctly, and have yum-utils installed).

yumdownloader --resolve kchmviewer

This fetched the kchmviewer-3.1-1.el5.rf.i386.rpm file from RPMForge repo. Depending on your system configuration, it might pull other rpms also. make note of the files downloaded.
Copy the RPM file to the Client directory. If the RPM had dependencies, make sure you copy those files as well. Sometimes, an older version of the same package might be available on the DVD. In that case, you need to delete the old ones and copy the new ones. In short, make sure you don't violate any dependencies. Don't forget to check the Workstation directory too. You'll find that the devel packages for several libraries are available in the Workstation directory.

Once you've copied all necessary RPM file, edit the XML file to add the new package listing. Identify the group to which the package should belong. Select a group, and add an entry in the packagelist, selecting "mandatory", "default" or "optional". The XML file is supposed to be sorted. But don't worry about that now. We'll do an automatic cleanup later.

Sorting the XML files

Once you have a consistent RPM setup and XML files (in Client, Workstation and VT directories), it's time to do cleanup. You'll need a file comps-cleanup.xsl for doing cleanup. Download from
To prepare Client, copy the file to Client/repodata folder, and in a terminal, type:

xsltproc --novalid -o sorted-file.xml comps-cleanup.xsl comps-rhel5-client-core.xml

This will generate sorted-file.xml from the original XML file, printing some information as well. If everything is OK, you can backup the original XML file and rename the sorted file to comps-rhel5-client-core.xml. Delete all other files in 'repodata'.

Repeat the steps for Workstation and VT directories, if you've modified something there too. Note that the XML filenames are different for each directory.

Re-creating the repository information

cd to the Client directory, and do:
createrepo -g repodata/comps-rhel5-client-core.xml .

Repeat the same for Workstation and VT directories (again, note that the XML filenames are different). If all is OK, move on..

Creating the ISO image

All right! Move to the root directory (rhel_custom). Make sure .discinfo file is available there. Issue the following commands:

chmod a+w isolinux/isolinux.bin
find -name TRANS.TBL -exec rm '{}' \;

(Not sure if it is really necessary to delete TRANS.TBL file).

mkisofs -J -T -o ../rhel5_custom.iso -b isolinux/isolinux.bin -c isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -R -m TRANS.TBL .

../rhel5_custom.iso is obviously the output image file. Change the path if you need to.

Once you have the image file, move to the directory containing the image. Now we need to insert MD5 checksum in to this image. The Anaconda 'media check' feature uses this checksum to verify the integrity of the DVD. If you skip this step, media check will not be available.

/usr/lib/anaconda-runtime/implantisomd5 rhel5_custom.iso


That's it. Your very own RHEL 5 is ready. Before you burn to a DVD, it's better to test the image using a virtualized environment. Checkout Sun VirtualBox if you've never used one. This way, you need not use physical DVDs to test your distro.

Good luck.