Creating RPMs from CPAN tarballs

cpan2rpm is a great utility to create RPMs from CPAN tarballs. You may want to download cpan2rpm from SourceForge, as the primary FTP site can be "maxed out" of anonymous FTP sessions.

Example usage

One of the tenets of RPM building is to never build as root. Building as root with an incorrect .spec file could, in the worst case, render the build system inoperable.

I will be building RPMs in ~/rpmbuild as my non-root user. If needed, create the RPM build directory structure, and modify ~/.rpmmacros to use the new directory structure instead of the default (i.e., /usr/src/redhat).

$ mkdir -p ~/rpmbuild/{BUILD,RPMS,S{OURCE,PEC,RPM}S}
$ echo -e "%_topdir\t$HOME/rpmbuild" >> ~/.rpmmacros

$ cpan2rpm --no-upgrade-chk Apache-DB-0.13.tar.gz

This creates perl-Apache-DB-0.13-1.i386.rpm and perl-Apache-DB-0.13-1.src.rpm. In my environment, I want a "repotag" of .nav to identify the RPMs as custom-built. This is similar to doing the following in a .spec file:

%define         repotag .nav
Release:        1%{?repotag}

From cpan2rpm(1):

           The package release number. Defaults to 1. Allows alphanumerics.

$ cpan2rpm --no-upgrade-chk --release="1.nav" Apache-DB-0.13.tar.gz

This creates perl-Apache-DB-0.13-1.nav.i386.rpm and perl-Apache-DB-0.13-1.nav.src.rpm.

Two other options may be useful on a build system that lacks Perl module prerequisites:

           At times the user may want to package a module that depends on
           other CPAN modules not presently installed.  This is generally not
           possible since cpan2rpm does an up-front check for modules listed
           in the PREREQ_PM field of the Makefile.PL.  This switch turns this
           checking off so that the process may continue and implies the
           --make-no-test since testing with missing module dependencies will
           certainly fail.

           Use this option to suppress running a module’s test suite during

Back to
Last modified: 2007/07/26