Please wait while the page is being loaded Skip this advertisement >

PC World Business

Brought to you by
Compiling software with Rpmbuild
Alastair Cousins (PC World) 20/06/2003 07:54:13

The performance and space-saving advantages of compiling software from source are regularly championed in this column. Many users, however, find it much easier to install pre-compiled applications distributed in the RPM or DEB formats. In this column, we instruct you in using a tool that combines the performance advantages of compiling software from source with the ease of installation offered by pre-compiled binaries.

Have you ever downloaded a Linux application from the Internet and noticed files of the type .src.rpm as available downloads? These files are called source RPMs and contain the source code to the application, as well as instructions on how to turn it into a binary RPM. The rpmbuild tool can use these instructions, known as a spec file, to automatically compile the application and produce a binary RPM for you.

Any distribution based on RPM should already have rpmbuild installed. You can check this by typing into a shell:

$ rpmbuild

which will display if rpmbuild is installed:

rpmbuild: no spec files given for build

To compile a .src.rpm with rpmbuild, use the --rebuild flag as shown below. You may need to be the root user to build an RPM with rpmbuild. To compile a large application with rpmbuild you will potentially need a large amount of free disk space, up to 1GB, available under /usr/src. Note that compiling a large application with rpmbuild may take up to a couple of hours, depending on your CPU speed.

$ rpmbuild --rebuild program.src.rpm

The process of compiling the application and building an RPM is entirely automated from start to finish and will be displayed on the screen. Often when rebuilding a .src.rpm, you will encounter what is known as a missing dependency. These usually take the form of a missing system file. To compile a .src.rpm, many development packages, identifiable by the presence of the string ‘-devel’ in the filename, may be required. To list the dependencies of a .src.rpm, type the following in a shell:

$ rpm -qp --requires program.src.rpm

Before attempting to rebuild a .src.rpm, first verify that all of these dependencies have been installed. At the conclusion of the rpmbuild process the location of the freshly compiled binary RPMs generated by rpmbuild will be displayed. Under Red Hat Linux, this location is /usr/src/redhat/. Often two or more RPMs will be generated from a single .src.rpm file. You can install these RPMs as you would any other, by typing as root: $ rpm -ivh program.rpm

Optimisations

The key advantage of compiling software is the optimisations, which can be used to improve performance and reduce space requirements. Rpmbuild can be used to optimise RPMs for your CPU, potentially significantly increasing the performance of your Linux system. To use optimisations when building a .src.rpm, add the --target= flag to the rpmbuild command. For example, to optimise a .src.rpm for an AMD Athlon CPU use the following command:

$ rpmbuild --rebuild --target=athlon program.src.rpm

Pentium II/III/IV owners should change ‘athlon’ to ‘i686’.

Optimisation flags for each architecture are stored in the file /usr/lib/rpm/rpmrc. You can modify the default optimisations by editing this file or, if you wish to use different optimisation flags for individual users, by making a copy of this file named ~/.rpmrc. The section of the rpmrc file concerned with optimisations is structured as follows:

optflags:

For example, the default optimisation flags for an AMD Athlon CPU are:

optflags: athlon -O2 -march=athlon

Users experienced with compiler optimisations should replace the default optimisation flags with their own. GCC offers many optimisation flags that can significantly improve the performance of applications. A more aggressive set of optimisations for an AMD Athlon or Intel Pentium IV is as follows:

optflags: i686 -O3 -march=i686 -fomit-frame-pointer -mcpu=pentium4 optflags: athlon -O3 -march=athlon -fomit-frame-pointer

These optimisations should safely compile almost all RPMs. If you encounter problems compiling or running a program compiled with these optimisations, try reverting to the default optimisations for your CPU. Aggressive optimisation can sometimes result in instability and errors in applications.

Where to start

Most distributions include a number of source CDs alongside their installation CDs. These source CDs include .src.rpm files of identical versions of the applications installed with the distribution. To start experimenting with rpmbuild, try rebuilding an application you regularly use that is included on these CDs. On my system I have rebuilt Evolution, XFree86 and many components of both KDE and GNOME. Often the performance increases are very noticeable and worth the extra time and effort involved.

More about KDE, Intel, Red Hat, O2, AMD
Recommend this article?
Yes1 votes
No1 votes

Comments

Post new comment

Login or register to link comments to your user profile, or you may also post a comment without being logged in.
The content of this field is kept private and will not be shown publicly.
Enter the fully qualified URL, eg. http://www.example.com/
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Syndicate content
 
Dell Shop