OSETC TECH

Linux: Build RPMS For a Perl Module

This post will guide you how to build rpm package for a Perl module using Cpanspec and rpmbuild tools under the CentOS/RHEL Linux machine.

Build RPMS For a Perl Module


If you want to build rpm package for a Perl module, you need to install two new packages: cpanspec and rpmbuild packages. The cpanspec is used to parse a CPAN distribution and produces a spec file. and the rpmbuild tool is used to take a spec file and a distribution and truns them into an RPM.

Install CpanSpec and Rpmbuild

Type the following command:

#yum install cpanspec
#yum install rpmbuild

Make Directory Structure For Rpmbuild

You need to create a directory structure in which to build your rpms. Type the following command:

# mkdir rpm
#mkdir ./rpm/BUILD
#mkdir ./rpm/BUILDROOT
#mkdir ./rpm/RPMS
#mkdir ./rpm/SOURCES
#mkdir ./rpm/SPECS
#mkdir ./rpm/SRPMS

Then you need to create a file called .rpmmacros in your home directory, and added the below lines into it.

%packager osetc <osetc@gmail.com>
%vendor osetc
%_topdir /root/rpm

Building RPM For Perl Module

You need to use the cpanspec to make the spec file and then using rpmbuild to build the rpm. For example, you have a perl mode tarball called osetc-0.01.tar.gz, then you can pass this tarball name to cpanspec tool. type the following command:

# cpanspec osetc-0.01.tar.gz

it will generate a spec file into /root/rpm/SPEC directory.

Now you can build the RPM with rpmbuild command, type:

# rpmbuild -ba /root/rpm/SPEC/perl-osetc.spec