Friday, February 19, 2010

How to rebuild an RPM package

This is the 1st time for me to patch and rebuild an RPM package, when I tried to add Unicode Support on CentOS 5.4 with PHP and PCRE. I received some PHP warning message when I had the regex testing characters (‘\X’, ‘\pL’, etc) inside of a character class, such as ‘[\X-]‘. After I googled the Internet, I found that's because the Unicode Support is missing in the PCRE.

Note: This is an example which using PCRE SOURCE RPM package.

Since I downloaded PHP 5.3.1 and compiled manually by enable the configure option:


And PHP 5.3.x includes PCRE support built in; however, the yum package for PCRE is not built with Unicode support; so, need to download the rpm and patched according to this page:

This is needed for Unicode regexp support, so we can do input validation in a variety of character sets.

By default, at least on a Red Hat box, rpm uses /usr/src/redhat as the location of the %_topdir macro, which specifies where most of the work involved in building an RPM takes place.

You can and should change this; it is a good idea to make this a directory that you can write to with a non-privileged account, to avoid compiling and building packages as root.


A lot of commands get executed when building a package. Sometimes things go wrong. If you're root, important things may be damaged. A big mess may be made. I once (foolishly) rebuilt a proftpd package as root, and the "make install" stage blew up and left newly compiled files all over the place, whereas if I'd been a regular user, I'd have simply gotten a bunch of "permission denied" messages.

  1. Anyway, the macro is easily changed by adding something like the following to ~/.rpmmacros:

    # Path to top of build area
    %_topdir /home/you/src/rpm

  2. If you have never worked on RPMs in this manner, you will need to create a few directories in which to work. I use a sub-directory in my homedir:

    #> mkdir -p ~/src/rpm
    #> cd ~/src/rpm
    #> mkdir RPMS/i[3456]86 RPMS/noarch RPMS/athlon

  3. Download the PCRE Source RPM, and install it:

    #> wget

    #>rpm -ivh pcre-6.6-2.el5_1.7.src.rpm

    Then install the following package from iso image if you didn't install them during the 1st time OS installation:

    #> rpm -ivh beecrypt-4.1.2-10.1.1.x86_64.rpm rpm-libs- rpm- elfutils-0.137-3.el5.x86_64.rpm elfutils-libs-0.137-3.el5.x86_64.rpm rpm-build-

  4. Rebuild the PCRE RPM package and reinstall the new PCRE RPM package:

    opened up the ~/src/rpm/SPECS/pcre.spec file and found the following line:

    %configure --enable-utf8

    changed it to include the Unicode properties option:

    %configure --enable-utf8 --enable-unicode-properties

    Then saved and closed the file.

  5. Rebuils the PCR RPM package:

    #> rpmbuild -ba ~/src/rpm/SPECS/pcre.spec
    #> rpm -Uvh RPMS/x86_64/pcre-6.6-2.7.x86_64.rpm RPMS/x86_64/pcre-devel-6.6-2.7.x86_64.rpm –-force

  6. Then run pcretest program, and you should see "Unicode properties support" shown in the result.

    $ pcretest -C
    PCRE version 6.6 06-Feb-2006
    Compiled with
    UTF-8 support
    No Unicode properties support
    Newline character is LF
    Internal link size = 2
    POSIX malloc threshold = 10
    Default match limit = 10000000
    Default recursion depth limit = 10000000
    Match recursion uses stack

I also found a very helpful guide that details this process out very nicely: How to patch and rebuild an RPM package.

No comments :

Post a Comment

Comments System

Disqus Shortname