Information on RPM spec files is hard to come by. Here’s what I have. It isn’t much but might help somebody trying to build an RPM package for the first time. See also http://blag.wiki.aktivix.org/Rpm_tips
What the Spec File Does Overall
The spec file is used by the “rpmbuild” command to create a distributable RPM file for a piece of software. The “software” can be a large application including source code, or it might just be the application binary files, or even just a script or two.
The RPM file is a single file containing the software and scripts needed to install/uninstall it on a target system.
When the rpmbuild command is issued, it reads the spec file, performing some actions
by default and some as directed by the specfile. After processing the spec file it packs the software into an RPM file.
Parts of the Spec File and What They Do
This variable holds the name of a temporary build directory. Often set to “/var/tmp/
Contains commands to be run prior to other processing. Rpmbuild will cd into the SOURCE directory and then run whatever commands you place into the spec file at this point. Often the only entry is “%setup”, as below.
%setup (a macro, always part of %prep)
Unzips the files in SOURCE/myproject-1.1.tar.gz into a directory SOURCE/myproject-1.1. “%setup -q” will do so qietly.
Contains commands to build the software. At the least, this part of the file should copy project files from (for example) SOURCE/myproject-1.1 into the temporary build directory specified in the variable BUILDROOT. When putting commands here remember that the current working directory is BUILDROOT, so you are copying files to the current directory. If there are no commands here, rpmbuild can fail at the install phase with this sort of error:
find: /var/tmp/uk-cfg2html-1.1: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.1959 (%install)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.1959 (%install)
Contains commands to install the software. For compilable programs it might include a “make install” command (given an appropriate Makefile), which install the target, given the presence of an appropriate makefile.
Commands placed here will be run after the build. The main purpose is often to remove the temporary build directory BUILDROOT. Care should be taken when putting “rm” commands in here. An “rm -f” run as root can be dangerous. Eg “rm -rf /$mydir” might delete files and directories from root if the $mydir variable is empty or not set, potentially trashing the whole machine. If in doubt, don’t add commands here. The build directory will be left around in /tmp or wherever, but that is not such a big problem.
This lists the files that are part of the project, shown as their eventual target paths. All of these will be packaged into the final rpm file. It is not necessary to list actual directories here, just the files.
rpmbuild -ba will run a check on each file in the list, producing messages like this as
this as it does so. Note the files being checked here are still in the BUILD directory, not at the installed pathnames (though they are listed like so in the spec file).
Processing files: uk-cfg2html-1.1-1
Requires(interp): /bin/sh /bin/sh /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 Requires(pre): /bin/sh Requires(post): /bin/sh Requires(postun): /bin/sh Requires: /bin/bash /usr/bin/env Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/uk-cfg2html-1.1 A file listed under %files which is not found in the BUILD directory will cause rpmbuild to throw this sort of error:
RPM build errors:
File not found: /var/tmp/uk-cfg2html-1.1/var/tmp/myfile
Conversely, if you forget to list a file under %files, expect to see this sort of thing from rpmbuild:
error: Installed (but unpackaged) file(s) found:
RPM build errors:
Installed (but unpackaged) file(s) found: