In today’s post, I will be documenting how to build an RPM package. I will be using “units” and “zile” as my two applications (from the Building from Source post) that will be packaged as RPMs. The process will involve the following steps:
- Preparing the build environment
- Create default SPEC file/edit SPEC file
- Build RPM package
- Testing the SPEC, RPM, debuginfo RPM, and SRPM files
*Please Note* – This guide assumes that you already have the source tarball for “units” and “zile” already downloaded. Please refer to the Building from Source post for links and descriptions of the applications used here.
Part 1 – Prepare the build environment
To begin the process of building RPMs, we first need to install the Fedora Packager, rpmlint, and yum-utils packages.
su -
(enter root password)
yum groupinstall “Fedora Packager”
When complete, run the following command (as root user) to install the remaining packages:
yum install rpmlint yum-utils
Change back to your regular user account and create the default rpmbuild directories by running the following command:
exit
rpmdev-setuptree
Once the above command is completed, you should have a folder structure in your home directory that looks like this:
[dliscio@merk ~]$ tree rpmbuild/
rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS
Copy the source tarball for “units” and “zile” to the ~/rpmbuild/SOURCES directory.
cp ~/Downloads/units-1.88.tar.gz zile-2.3.24.tar.gz ~/rpmbuild/SOURCES
Part 2 – Create and edit the Spec file
The next step in packaging an RPM is to create a default SPEC file. The SPEC file contains info such as the name, version, revision, summary and dependencies or requirements of the application. A SPEC file dictates how a package will be configured, what will be installed, the location of the install, and tasks that the system will need to complete pre and post install.
Change to the SPECS directory.
cd ~/rpmbuild/SPECS
Create the default SPEC files.
rpmbuild-newspec units
rpmbuild-newspec units
Edit the SPEC file using your preferred text editor, filling in all fields. If a field is not required, comment it out using the “#” character.
vi units.spec
vi zile.spec
Units SPEC file:
For this SPEC file, I ran into a few issues regarding a number of files not being copied to their proper locations during the build. The error was as shown below:
RPM build errors:
Installed (but unpackaged) file(s) found:
/usr/bin/units
/usr/share/info/units.info.gz
/usr/share/man/man1/units.1.gz
/usr/share/units.dat
I fixed this error by editing SPEC file with the following entries.
BuildRequires: gettext
Requires(post): info
Requires(preun): info
%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT
rm -f %{buildroot}/%{_infodir}/dir
%post
/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || :
%preun
if [ $1 = 0 ] ; then
/sbin/install-info –delete %{_infodir}/%{name}.info %{_infodir}/dir || :
fi
%files
%doc README NEWS ChangeLog COPYING INSTALL
%{_bindir}/*
%{_mandir}/man1/*
%{_infodir}/%{name}.info.gz
%{_datadir}/%{name}.dat
I added to the %doc entry, files from the extracted tarball that looked like documentation files. For the info.gz file, more steps were required which is why you see the build dependencies listed as “gettext” and the post and preun requires fields filled in with “info”
Zile SPEC file:
This SPEC file did not contain an info.gz file, but did require the addition of filenames to the %files section.
%files
%doc
%{_bindir}/*
%{_mandir}/man1/*
%{_datadir}/%{name}/FAQ
%{_datadir}/%{name}/dotzile-extra.el
Save your SPEC files when you have finished editing them and continue to part 3.
Part 3 – Build the RPM package
To build an RPM package, the command “rpmbuild -ba specfile.spec” is used. The -ba option tells rpmbuild to build the source and RPM packages from the specfile specified.
Attempt to build the RPM package:
rpmbuild -ba units.spec
rpmbuild -ba zile.spec
After running the build, fix any errors that may occur. The last few lines of a successful build for units is shown below as an example.
Wrote: /home/dliscio/rpmbuild/SRPMS/units-1.88-1.fc15.src.rpm
Wrote: /home/dliscio/rpmbuild/RPMS/x86_64/units-1.88-1.fc15.x86_64.rpm
Wrote: /home/dliscio/rpmbuild/RPMS/x86_64/units-debuginfo-1.88-1.fc15.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.PhVm9O
+ umask 022
+ cd /home/dliscio/rpmbuild/BUILD
+ cd units-1.88
+ /bin/rm -rf /home/dliscio/rpmbuild/BUILDROOT/units-1.88-1.fc15.x86_64
+ exit 0
If the build completes with an exit status of 0 without errors, continue to part 4 for testing.
Part 4 – Testing using rpmlint
Now that you have built an RPM package, we need to test the package for errors using a tool called rpmlint.
Run rpmlint on each of your SPEC, RPM, debuginfo RPM, and SRPM files to ensure that they do not contain errros.
Units:
[dliscio@merk SPECS]$ rpmlint units.spec
0 packages and 1 specfiles checked; 0 errors, 0 warnings.
[dliscio@merk SPECS]$ rpmlint ../RPMS/x86_64/units-1.88-1.fc15.x86_64.rpm
1 packages and 0 specfiles checked; 0 errors, 0 warnings.
[dliscio@merk SPECS]$ rpmlint ../RPMS/x86_64/units-debuginfo-1.88-1.fc15.x86_64.rpm
1 packages and 0 specfiles checked; 0 errors, 0 warnings.
[dliscio@merk SPECS]$ rpmlint ../SRPMS/units-1.88-1.fc15.src.rpm
1 packages and 0 specfiles checked; 0 errors, 0 warnings.
Zile:
[dliscio@merk SPECS]$ rpmlint zile.spec
0 packages and 1 specfiles checked; 0 errors, 0 warnings.
[dliscio@merk SPECS]$ rpmlint ../RPMS/x86_64/zile-2.3.24-1.fc15.x86_64.rpm
zile.x86_64: W: name-repeated-in-summary C Zile
zile.x86_64: W: spelling-error %description -l en_US customizable -> customization
1 packages and 0 specfiles checked; 0 errors, 2 warnings.
[dliscio@merk SPECS]$ rpmlint ../RPMS/x86_64/zile-debuginfo-2.3.24-1.fc15.x86_64.rpm
1 packages and 0 specfiles checked; 0 errors, 0 warnings.
[dliscio@merk SPECS]$ rpmlint ../SRPMS/zile-2.3.24-1.fc15.src.rpm
zile.src: W: name-repeated-in-summary C Zile
zile.src: W: spelling-error %description -l en_US customizable -> customization
1 packages and 0 specfiles checked; 0 errors, 2 warnings.
The warnings marked by a W for the zile files are not critical items, but rather recommendations in this case for a repeat name in the summary field and a “spelling” error in the description (not actually an error). Warnings will not cause your package to be unusable, but if you start seeing many warnings when checking with rpmlint, you should further analyze the warnings to ensure that no major problems are occurring behind the scenes.
Summary
This is a basic overview of the build process for packaging an RPM file from source. There is plenty of documentation available online for a more in-depth look into SPEC files and what you can do with each field in the file. I will post links to the files I created during the build process in the links section below. I will also provide links to a few websites I found useful while working through the build process that may help you in configuring the SPEC file for other packages.
Links