Linux Migration for the Home PC User, Part 8

The ultimate step in DIY Linux for the home PC user is building a piece of software for yourself.

In essence, that is what we will do here, but we will take some shortcuts to make it as painless and simple as possible. This means instead of simply building something directly from source, with all the command line incantations, we will build an RPM package from an RPM source package.

I mentioned in the previous lesson a problem I had with the font rendering on CentOS. This has been a issue with Linux over the years. The default package set from CentOS (and Red Hat) don’t enable something called “bytecode interpreter” in the Freetype font rendering library. A few brands of Linux do this for you, but we have to fix it ourselves in CentOS.

First, you have to install the packages which allow you to build your own software. This is the easy part. If you installed from the stack of CDs or a DVD, you’ll need to have that at hand. In the “Applications” menu, go all the way to the bottom for “Add/Remove Software” and prepare to enter your root password. Once you’ve done that, you’ll see a window labeled “Package Manager”. This application will run for a few minutes taking an inventory of what is already installed. When it’s ready to work, you’ll see a window on the left side with a list of categories. Click on “Development” and take a look at the window on the right side. There is a list with check boxes. We need to make sure we have checked “Development Libraries” and “X Software Development” — X is the Linux nickname for the service which creates the Linux GUI framework itself, while the GNOME Desktop runs on top of that framework. We need the libraries for X because what we are building will need them. The Package Manager will most likely require you insert your install disks, but may pull some files down from the repo on the Net.

When it tells you it’s done, close it. Now we need to get that source RPM package. Start at the official CentOS Mirrors List. Scan down this list for a site relatively close to your geographical location. Keep this page open, because it’s just possible the one you choose may not respond well at any give time. You can open any link in a second browser page by clicking that link with your middle mouse button. In this case, you need to click on either an HTTP or FTP link on the far right side of the list to find your CentOS repository. On the next page click on the link to “5.3”, then “os”, then “SRPMS”. What you should now see is a list of files. Scan down to “freetype” — at this writing what would be “freetype-2.2.1-20.el5_2.src.rpm”. Right-click and choose “Save Link As…” and allow the “save” dialog to pop up. The name can be changed, but we need to keep it as is; be sure to select your “home” folder from the drop down just below that.

Once you have that, you can close your browser and open that Terminal window again. Log in as root. We need to move that file where everything can be neatly organized. There is a space on your system already reserved for mucking about with SRPMs. Provided the file name matches what is above, your command would look like this (all on one line):

mv freetype-2.2.1-20.el5_2.src.rpm /usr/src/redhat/SRPMS/

If you want to be slick, you type the “mv freety” part, hit the TAB key and let it finish spelling out the file name, then copy the rest from above, or type it by hand. Now that the file is there, we have to move the prompt there.

cd /usr/src/redhat/SRPMS/

Make sure by typing your ls command; you should see your Freetype file listed. Now we will install it in the proper place by running the RPM command with some switches (all on one line):

rpm -ivh freetype-2.2.1-20.el5_2.src.rpm

By now, you should know you can type it using the TAB key after just typing “free” or you can use your mouse to copy that command and paste with the middle button into your Terminal window. The prompt should show RPM installing the file, but you don’t yet know where all the stuff in that RPM went. We don’t need to know all the gory details, but we do need to edit one file. Let’s go back up one level in the file system, then down into the SPECS folder. It looks like this:

cd ../SPECS/

If you use ls you’ll see a freetype.spec — this is the specification file for building the Freetype library package. We’ll call on our old friend, Nano:

nano freetype.spec

Drop down three lines to this:

%define without_bytecode_interpreter 1

Go to the end of the line, and change that “1” (one) to a “0” (zero). Save it and close. What we have done is turned on a switch, as it were, to make the software build it differently.

That software is a friend of the RPM command, called RPMBuild. You don’t have to know all the ugly details just yet, because you aren’t likely to do this very often. Here’s how we make it happen:

rpmbuild -bb freetype.spec

You’ll see a long bunch of lines scroll by as the software begins the process of checking to make sure everything is alright. On the outside chance your system is missing something for the job, RPMBuild will tell you what’s missing. It’s designed to do this no matter what you are building. Most of the time, you can fix it immediately, since you are logged in as root, and your friend Yum is standing by to help.

If you believe RPMBuild is telling you the name of a missing package, you can check by running a Yum search:

yum search packagename

Naturally, you would replace “packagename” with the name, or partial name, of the package. If Yum knows about that package, you’ll see a list. Most of the time, that package name will include a “-devel” telling you it’s a development package. You have to install it by asking for the package with that suffix in the name.

yum install packagename-devel

If it lists something with lots of dots and some numbers, rather like “libgettextlib-0.14.6.so” then you’ll know it’s not a package name, but a particular item from a package. If you simply search on the Net using that name plus “rhel” you’ll usually figure out what package it belongs to, and can install that by name. In this case, that’s “gettext”. So we can fix that by telling Yum we need it:

yum install gettext

Most of the time things will work out well that way, and when Yum is finished, you can run that RPMBuild command again, simply by pressing your up arrow key a few times until it reappears at the prompt, then hit ENTER. Provided nothing else is missing, and it starts to run through the checking process, then it will switch to building, then eventually creating the new RPM files.

When the prompt comes back, and there’s no errors, you’ll need to go find that new RPM you just built.

cd ../RPMS/

Run the ls command, but don’t get frustrated when you see a half-dozen folders named after various computer architectures. Unless you installed the 64-bit version of CentOS, you’ll find most stuff built this way under i386, so go there:

cd i386

Checking with our ls command, we find several files whose names begin with “freetype” — we need two of them. Now, before we install them, you’ll have to understand something. RPM will think these files are identical with what you already have, and will argue. You and I know it’s not the same, so we have to force RPM to install our new package over the old one. It looks like this (all on one line):

rpm -Uvh --force freetype-2.2.1-20.i386.rpm freetype-devel-2.2.1-20.i386.rpm

Unless something is wrong, you should see RPM prepare, then install the two files. Here, as with any other point in this complicated procedure, you should already have worked out where you will go for help. You can post here in the comments section, but it’s best if you cultivate a support group either on a forum or a mailing list.

Once you have this changed version of Freetype installed, you’ll need to close the root session, close the Terminal, log out of your computer, and then restart X. Most of the time, it’s simplest from that login window to hit the keys CTRL + ALT + BKSP all at once. The X server should restart automatically after a few seconds, and will be using the new Freetype libraries. Log back in again, and you should see a change in how the fonts appear on screen.

The only thing you have to remember is, from time to time, CentOS will update the Freetype package, and you’ll have to run through this drill again. Once any package gets updated, you’ll find the newest SRPMs in a different location on the mirror, by going from the “5.3” to “updates” then into the “SRPMS” folder. Should CentOS upgrade it all to 5.4, it should be automatic for your system, and you should know to follow that path through the new folders.

Once you get used to running Linux, it’s possible you’ll find you really need something nobody has prepared for CentOS, and you’ll want to build it from the source. It’s not hard to learn, but it’s outside the scope of introductions like this. You can get instructions from your new forum/list friends most likely.

As more than one tech writer has said, CentOS is Linux for grownups. It’s a little more work, but once you have it working as you wish, you can depend on it staying that way for a long time.

This entry was posted in computers and tagged , . Bookmark the permalink.