Most of your work with the rpmbuild command will likely be to create binary RPMs after you have the sources for an application and a spec file. You can also get a lot of mileage out of source RPMs, whether you build them or download them.
Because they are RPMs themselves, source RPMs act like other RPMs. For example, you can use the rpm -i command to install a source RPM. This installs the sources provided by the source RPM, not the actual application. Normally, when you install a source RPM on a Red Hat Linux system, the package gets installed into /usr/src/redhat.
This directory is obviously specific to Red Hat Linux. On other Linux distributions, you'll likely see directories such as /usr/src/OpenLinux for SCO (formerly Caldera) OpenLinux.
Installing a source RPM is not exactly the same as installing a binary RPM. For example, the rpm command does not update the RPM database when you install a source RPM. In addition, listing the files in a source RPM only shows the relative paths, not the full paths.
11.3.1. Rebuilding binary RPMS from source RPMs
As a shortcut, you do not have to install a source RPM to create a binary RPM. Instead, you can build the binary RPM directory using the --rebuild option.
The --rebuild option tells the rpmbuild command to rebuild a binary RPM from a source RPM file. The basic syntax is:
rpmbuild --rebuild package.src.rpm
This command builds a binary RPM out of a source RPM with a minimum of fuss. For example:
$ rpmbuild --rebuild unix2dos-2.2-17.src.rpm
Installing unix2dos-2.2-17.src.rpm
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.15828
+ umask 022
+ cd /usr/src/redhat/BUILD
+ LANG=C
+ export LANG
+ cd /usr/src/redhat/BUILD
+ rm -rf unix2dos-2.2
+ /bin/mkdir -p unix2dos-2.2
+ cd unix2dos-2.2
+ /usr/bin/gzip -dc /usr/src/redhat/S OURCES/unix2dos-2.2.src.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
+ /bin/chmod -Rf a+rX,g-w,o-w .
+ echo 'Patch #0 (unix2dos-mkstemp.patch):'
Patch #0 (unix2dos-mkstemp.patch):
+ patch -p1 -b --suffix .sec -s
+ echo 'Patch #1 (unix2dos-2.2-segfault.patch):'
Patch #1 (unix2dos-2.2-segfault.patch):
+ patch -p1 -b --suffix .segf -s
+ echo 'Patch #2 (unix2dos-2.2-manpage.patch):'
Patch #2 (unix2dos-2.2-manpage.patch):
+ patch -p1 -b --suffix .man -s
+ perl -pi -e 's,^#endif.*,#endif,g;s,^#else.*,#else,g' unix2dos.c unix2dos.h
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.60650
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd unix2dos-2.2
+ LANG=C
+ export LANG
+ gcc -O2 -march=i386 -mcpu=i686 -ounix2dos unix2dos.c
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.35128
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd unix2dos-2.2
+ LANG=C
+ export LANG
+ rm -rf /var/tmp/unix2dos-root
+ mkdir -p /var/tmp/unix2dos-root/usr/bin /var/tmp/unix2dos-
root/usr/share/man/man1
+ install -m755 unix2dos /var/tmp/unix2dos-root/usr/bin
+ install -m444 unix2dos.1 /var/tmp/unix2dos-root/usr/share/man/man1
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note
Processing files: unix2dos-2.2-17
Executing(%doc): /bin/sh -e /var/tmp/rpm-tmp.12033
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd unix2dos-2.2
+ DOCDIR=/var/tmp/unix2dos-root/usr/share/doc/unix2dos-2.2
+ export DOCDIR
+ rm -rf /var/tmp/unix2dos-root/usr/share/doc/unix2dos-2.2
+ /bin/mkdir -p /var/tmp/unix2dos-root/usr/share/doc/unix2dos-2.2
+ cp -pr COPYRIGHT /var/tmp/unix2dos-root/usr/share/doc/unix2dos-2.2
+ exit 0
Finding Provides: /usr/lib/rpm/find-provides
Finding Requires: /usr/lib/rpm/find-requires
PreReq: rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames)
<= 3.0.4-1
Requires(rpmlib): rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(CompressedFileNames) <= 3.0.4-1
Requires: libc.so.6 libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1)
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/unix2dos-root
Wrote: /usr/src/redhat/RPMS/i386/unix2dos-2.2-17.i386.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.47653
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd unix2dos-2.2
+ rm -rf /var/tmp/unix2dos-root
+ exit 0
Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.47653
+ umask 022
+ cd /usr/src/redhat/BUILD
+ rm -rf unix2dos-2.2
+ exit 0
With the --rebuild option, the rpmbuild command installs the source RPM for you and then performs the preparation, compile, and installation stages of building a binary RPM. Unless there are errors, you should have a new binary RPM file.
When complete, the rpmbuild --rebuild command cleans out the built files in the build directory, as if the --clean option were used. The rpmbuild --rebuild command also removes the installed sources and spec file upon completion.