RPM Writing

In this post, I will illustrate the steps I took in order to build a RPM with my own modified spec file.

First I installed the necessary packages:

    yum groupinstall “Fedora Packager”
    yum install rpmlint yum-utils

Under my user account, I ran this command to set up my rpmbuild directories:

    rpmdev-setuptree

I copied my tarball (using http://mirror.csclub.uwaterloo.ca/gnu/hello/hello-2.7.tar.gz) from my previous post to ~/rpmbuild/SOURCES.

Changed to ~/rpmbuild/SPECS and created a new skeleton spec file using:

   rpmdev-newspec hello.spec

I’ve edit the specfile to my own requirements as shown below.

Name:           hello
Version:        2.7
Release:        99
Summary:        Cho Long (Tommy) Chor’s Hello World program

License:    GPLv3+
URL:        http://www.clchor.com
Source0:    hello-2.7.tar.gz

BuildRequires: gettext
# Requires:       
Requires(post): info
Requires(preun): info

%description
This is a test “Hello World” RPM package created by a student. Please advise before installing.

%prep
%setup -q

%build
%configure
make %{?_smp_mflags}

%install

make install DESTDIR=%{buildroot}
%find_lang %{name}
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 -f %{name}.lang
%{_bindir}/hello
%doc %{_mandir}/man1/hello.1.gz
%doc %{_infodir}/%{name}.info.gz

%changelog
* Wed Oct 4 2011 Hello World package modified by Cho Long (Tommy) Chor 2.7-99
– Initial release for testing purposes

To build my package using my spec file, run:

    rpmbuild -ba nameOfPackage.spec

Getting the above step to work was the hardest part. Initially, I had errors with missing or wrong sections like having the wrong Source0 field. And then the build proceeded into later sections, the variables I used were wrong. But after much effort, the build was successful and the binary RPM and source RPM was created.

To further test the RPM, I ran rpmlint on the binary and source RPM and was error free.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment