Since you have read HOWTO: How to create rpmbuild directory and have an RPM building environment all set up, let's put it to use. (Note that the fedora-buildrpmtree does not create the architecture-specific sub-directories in /BUILD, but that's not really a problem.)
The canonical reference for RPM is the sadly outdated book Maximum RPM (last updated in 2000), but it's still a useful reference and required reading for serious RPM building.
There are three places (four actually, if you use the option to specify any random location) that RPM building configurations are kept. The architecture-specific macros are kept in /usr/lib/rpm//macros. You'll find a macros file in the /redhat directory as well. That one looks like the master template, full of variables that the other config files set. It is suggested that you not modify any of these files since you should be able to pass any changes along with an entry to ~/.rpmmacros.
If you want to make any system-level changes, they will go in /etc/rpm/macros.*; the files are 'macros.prelink', 'macros.solve', 'macros.specspo', and 'macros.up2date' plus an additional file, 'platform'. I'm not really sure of a resource that explains the workings of these files in /etc/rpm.
User-specific changes are kept in ~/.rpmmacros. You can, for example, add "%optflags -funroll-loops" to the ~./rpmmacros file and then "rpmbuild --showrc | grep unroll" to see the optflag become part of the environment (Do that before and after to see the change; see below about using --showrc. Note that you can have several different .rpmmacro files and specify which one to use with the --rcfile directive ).
The files are commented (not the .rpmmacros file, however), so you can look at them in a text editor and see what they do. You can also refer to Appendix B in Maximum RPM at http://ftp.redhat.com/pub/redhat/linux/9/en/doc/RH-DOCS/maximum-rpm-1.0/html/ch-rpmrc-file.html. The man pages for rpm, rpmbuild, and gcc will come in handy
You can see the current default values with:
$ rpmbuild --showrc
The format of the entries is in the form:
name value
When you ran fedora-buildtree, it created a ~.rpmmacros file with the following contents:
%_topdir %(echo $HOME)/rpmbuild
You may wish to add:
%_tmppath %(echo $HOME)/tmp
to point toward your own /tmp directory,
and
%optflags -march=athlon
%_vendor fedora
and any other variable you feel is appropriate. With the --rcfile option, you can experiment with different .rpmmacros.
Building an RPM file from a *.src.rpm file
We'll use a popular example by re-compiling the src.rpm file for Freetype so that the normally disabled bytecode interpreter is re-enabled, providing better-looking font rendering for your viewing pleasure.
Step 1
Install the freetype-2.1.4-5.src.rpm. It will be put in your ~/rpmbuild/SOURCES and ~/rpmbuild/SPECS directory. You can install source rpms as non-root.
Step 2
Open the .spec file in the /SPECS sub-directory in any text editor. the first three lines look like:
# Disables freetype 1 and 2 bytecode interpreter. Setting to 0 enables # the bytecode interpreter in both freetype 1 and 2. %define without_bytecode_interpreter 1
Change the value of '1' to '0' to enable the bytecode interpreter and save and close the file. It's also a good idea to note in the description field what you have changed.
Step 3
Build the new RPM with:
$ rpmbuild -bb ~/rpmbuild/SPECS/freetype.spec
and you will find several new binary RPM files in the /RPM sub-directory.
Note: Had you wanted to over-ride the architecture choice, for example, you can pass that in the command:
$ rpmbuild -bb --target=athlon ~/rpmbuild/SPECS/freetype.spec
for example).
Step 4
Install the new RPM file with:
# rpm -Uvh --replacepkgs ~/rpmbuild//freetype-2.1.4-5*rpm
The '--replacepkgs' allows you to "upgrade" to the same package version.
Step 5
Actually, had we known the variable name 'withhout_bytecode_interpreter', we could have rebuilt the src.rpm file by passing the changed value on the command line like this:
$ rpmbuild -bb --with withhout_bytecode_interpreter=0 ~/rpmbuild/SPECS/freetype.spec
As you can see, RPM is very powerful and flexible. Have fun!
RESOURCES
RPM.Org - http://www.rpm.org/
Maximum RPM download- http://www.redhat.com/docs/books/max-rpm/max-rpm.pdf
Maximum RPM - http://ftp.redhat.com/pub/redhat/linux/9/en/doc/RH-DOCS/maximum-rpm-1.0/html/
Fedora RPMDev Tools - http://www.fedora.us/wiki/FedoraRPMDevTools
Fedora RPMDev Tools download - http://download.fedora.us/fedora/fedora/1/i386/RPMS.stable/fedora-rpmdevtools-0.1.6-0.fdr.1.1.noarch.rpm
RPM related documentation - file:/usr/share/doc/rpm-devel-4.2.1/apidocs/html/pages.html
Write to me at hoyt@maximumhoyt.com.
Copyright © 2004 Hoyt Duff. Permission granted for use on FedoraNEWS.ORG. All rights reserved.