Step 0 : Build on the Work of Others
References:
[1] http://nailingjelly.wordpress.com/2009/06/03/cpan-rpm-packaging/
[2] http://perlhacks.com/2010/02/building-rpms-from-cpan-distributions.php
[3] http://www.slideshare.net/davorg/perl-in-rpmland-presentation
Step 1: Do you really need to do this?
See if you can find it using yum :
$ yum list available 'perl-*' | grep -i Some-Module
If so,
$ yum install perl-Some-Module
and get on with life.
Step 2: OK, We really do have to do this...
Make sure you have all the RPM bulid tools at your disposal.
$ yum install rpm-build
It's not there so we should really wrap it.
In this example I will attempt to install the following Perl CPAN module: Number::Spice
Setup the ~/.rpmmacros
$ cat ~/.rpmmacros
%__perl_requires %{nil}
%_topdir /home/me/rpmbuild
%packager <me@localhost>
$
Step 3. Set up the RPM build Area
$ mkdir ~/rpmbuild
$ cd ~/rpmbuild
$ mkdir BUILD RPMS SOURCES SPECS SRPM
Step 4. Create a source RPM
$ cd ~/Source
$ mkdir -p perl/spice
$ cd perl/spice
$ cpanspec --follow --srpm Number::Spice
So This is what happens when you run canspec
The package is downloaded will all dependencies.
A *.spec file is created
A *.src.rpm file is created.
Step 5. Install the source RPM
$ rpm -i perl-Number-Spice-0.011-1.fc12.src.rpm
The source RPM and .spec file are copied into the ~/rpmbuild tree by this command. This governed by the ~/.rpmmacros control file. Now is the time to review the .spec file and make any local modifications.
$ cd ~/rpmbuild/SPECS
$ vi perl-Number-Spice.spec
Step 6. Create the build binary RPM.
You can look at the build log to find the path to the installable RPM. I have identified it in black :
$ rpmbuild -bb perl-Number-Spice.spec
...
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/nicky/rpmbuild/BUILDROOT/perl-Number-Spice-0.011-1.fc12.i386
Wrote: /home/nicky/rpmbuild/RPMS/noarch/perl-Number-Spice-0.011-1.fc12.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.as9LwC
+ umask 022
+ cd /home/nicky/rpmbuild/BUILD
+ cd Number-Spice-0.011
+ rm -rf /home/nicky/rpmbuild/BUILDROOT/perl-Number-Spice-0.011-1.fc12.i386
+ exit 0
$ ls -l ~/rpmbuild/RPMS/noarch/perl-Number-Spice-0.011-1.fc12.noarch.rpm
-rw-r--r--. 1 nicky-mchp nicky-mchp 10804 2010-05-20 20:28 ~/rpmbuild/RPMS/noarch/perl-Number-Spice-0.011-1.fc12.noarch.rpm
I have noticed that there are occasions when compiling on an x64 based Fedora Core 13 that the build fails. An very confusing glob'ing error is presented. In order to make it pass I had to edit the .spec file. In the %files section there is an entry like %{perl_vendorlib}/* that to needed change to %{perl_vendorarch}/* in order for the build process to complete.
Step 7. Ultimate install
$ rpm -iv ~/rpmbuild/RPMS/noarch/perl-Number-Spice-0.011-1.fc12.noarch.rpm