Skip to content

Instantly share code, notes, and snippets.

@hercynium
Created December 8, 2013 23:40
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hercynium/7865220 to your computer and use it in GitHub Desktop.
RPM .spec file for building a specific version of perl to install under /opt
#!/bin/bash
#
# This is a simple script to allow someone on an RPM-based
# system to build the custom opt-perl package defined by
# the RPM specfile in this same directory.
#
# @author: Stephen R. Scaffidi <sscaffidi@tripadvisor.com>
# @date: Oct. 2012
#
# abort on any error
set -e
SCRIPTDIR=$(dirname $0)
SPECNAME="opt-perl.spec"
if [[ "$(whoami)" == "root" ]]; then
echo "Please don't build RPMs as root!"
echo "Run this script as a normal user."
exit 1
fi
# make sure we have the tools we need to build RPMs
if ! which rpmdev-setuptree &> /dev/null; then
echo "You need to install the rpmdevtools package."
echo "To do so automatically, please enter your password for sudo."
sudo yum -y install rpmdevtools
fi
# create an RPM build tree
rpmdev-setuptree
# download the perl source into the proper place in the build-tree
spectool --get-files -R "$SCRIPTDIR/opt-perl.spec"
# ask the RPM system where certain build-dirs will be
RPMDIR=$(rpm --eval "%{_rpmdir}")
SPECDIR=$(rpm --eval "%{_specdir}")
# copy the specfile into the build tree
cp "$SCRIPTDIR/$SPECNAME" "$SPECDIR"
# finally, build the rpm!
echo "Building the RPM, please wait..."
rpmbuild --quiet -ba "$SPECDIR/$SPECNAME"
echo
echo "Your new perl RPM should be under $RPMDIR"
echo "Please ignore any debuginfo packages that are there."
echo
%define perlver 5.16.1
%define perlname perl-%{perlver}
Name: opt-%{perlname}
Version: 1
Release: ta
Summary: Practical Extraction and Report Language - under /opt
Group: misc
License: GPLv1+
URL: http://www.perl.org
Source0: http://www.cpan.org/src/5.0/%{perlname}.tar.gz
BuildRoot: %{_tmppath}/%{perlname}-%{release}-root-%(%{__id_u} -n)
AutoReq: no
AutoProv: no
# this is necessary to prevent the scanning for rpaths in built libs
%undefine __arch_install_post
%description
A recent stable version of perl, installed under /opt
%prep
%setup -q -n %{perlname}
%build
./Configure -des -DEBUGGING=none -Duserelocatableinc -Dprefix=/opt/%{perlname}
%__make -j3
#make test
%install
rm -rf %{buildroot}
%__make install DESTDIR=%{buildroot}
chmod -R u+w %{buildroot}/*
%clean
rm -rf %{buildroot}
%files
/opt/%{perlname}
%defattr(-,root,root,-)
%changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment