3f1b01
# Sensible Perl-specific RPM build macros.
3f1b01
#
3f1b01
# Note that these depend on the generic filtering system being in place in
3f1b01
# rpm core; but won't cause a build to fail if they're not present.
3f1b01
#
3f1b01
# Chris Weyl <cweyl@alumni.drew.edu> 2009
3f1b01
# Marcela Mašláňová <mmaslano@redhat.com> 2011
3f1b01
3f1b01
# This macro unsets several common vars used to control how Makefile.PL (et
3f1b01
# al) build and install packages.  We also set a couple to help some of the
3f1b01
# common systems be less interactive.  This was blatantly stolen from
3f1b01
# cpanminus, and helps building rpms locally when one makes extensive use of
3f1b01
# local::lib, etc.
3f1b01
#
3f1b01
# Usage, in %build, before "%{__perl} Makefile.PL ..."
3f1b01
#
3f1b01
#   %{?perl_ext_env_unset}
3f1b01
3f1b01
%perl_ext_env_unset %{expand:
3f1b01
unset PERL_MM_OPT MODULEBUILDRC PERL5INC
3f1b01
export PERL_AUTOINSTALL="--defaultdeps"
3f1b01
export PERL_MM_USE_DEFAULT=1
3f1b01
}
3f1b01
3f1b01
#############################################################################
3f1b01
# Perl specific macros, no longer part of rpm >= 4.15
3f1b01
%perl_vendorarch %(eval "`%{__perl} -V:installvendorarch`"; echo $installvendorarch)
3f1b01
%perl_vendorlib  %(eval "`%{__perl} -V:installvendorlib`"; echo $installvendorlib)
3f1b01
%perl_archlib    %(eval "`%{__perl} -V:installarchlib`"; echo $installarchlib)
3f1b01
%perl_privlib    %(eval "`%{__perl} -V:installprivlib`"; echo $installprivlib)
3f1b01
3f1b01
#############################################################################
3f1b01
# Filtering macro incantations
3f1b01
3f1b01
# keep track of what "revision" of the filtering we're at.  Each time we
3f1b01
# change the filter we should increment this.
3f1b01
3f1b01
%perl_default_filter_revision 3
3f1b01
3f1b01
# By default, for perl packages we want to filter all files in _docdir from 
3f1b01
# req/prov scanning.
3f1b01
# Filtering out any provides caused by private libs in vendorarch/archlib
3f1b01
# (vendor/core) is done by rpmbuild since Fedora 20
3f1b01
# <https://fedorahosted.org/fpc/ticket/353>.
3f1b01
#
3f1b01
# Note that this must be invoked in the spec file, preferably as 
3f1b01
# "%{?perl_default_filter}", before any %description block.
3f1b01
3f1b01
%perl_default_filter %{expand: \
3f1b01
%global __provides_exclude_from %{?__provides_exclude_from:%__provides_exclude_from|}^%{_docdir}
3f1b01
%global __requires_exclude_from %{?__requires_exclude_from:%__requires_exclude_from|}^%{_docdir}
3f1b01
%global __provides_exclude %{?__provides_exclude:%__provides_exclude|}^perl\\\\(VMS|^perl\\\\(Win32|^perl\\\\(DB\\\\)|^perl\\\\(UNIVERSAL\\\\)
3f1b01
%global __requires_exclude %{?__requires_exclude:%__requires_exclude|}^perl\\\\(VMS|^perl\\\\(Win32
3f1b01
}
3f1b01
3f1b01
#############################################################################
3f1b01
# Macros to assist with generating a "-tests" subpackage in a semi-automatic
3f1b01
# manner.
3f1b01
#
3f1b01
# The following macros are still in a highly experimental stage and users
3f1b01
# should be aware that the interface and behaviour may change. 
3f1b01
#
3f1b01
# PLEASE, PLEASE CONDITIONALIZE THESE MACROS IF YOU USE THEM.
3f1b01
#
3f1b01
# See http://gist.github.com/284409
3f1b01
3f1b01
# These macros should be invoked as above, right before the first %description
3f1b01
# section, and conditionalized.  e.g., for the common case where all our tests
3f1b01
# are located under t/, the correct usage is:
3f1b01
#
3f1b01
#   %{?perl_default_subpackage_tests}
3f1b01
#
3f1b01
# If custom files/directories need to be specified, this can be done as such:
3f1b01
#
3f1b01
#   %{?perl_subpackage_tests:%perl_subpackage_tests t/ one/ three.sql}
3f1b01
#
3f1b01
# etc, etc.
3f1b01
3f1b01
%perl_version   %(eval "`%{__perl} -V:version`"; echo $version)
3f1b01
%perl_testdir   %{_libexecdir}/perl5-tests
3f1b01
%cpan_dist_name %(eval echo %{name} | %{__sed} -e 's/^perl-//')
3f1b01
3f1b01
# easily mark something as required by -tests and BR to the main package
3f1b01
%tests_req() %{expand:\
3f1b01
BuildRequires: %*\
3f1b01
%%tests_subpackage_requires %*\
3f1b01
}
3f1b01
3f1b01
# fixup (and create if needed) the shbang lines in tests, so they work and
3f1b01
# rpmlint doesn't (correctly) have a fit
3f1b01
%fix_shbang_line() \
3f1b01
TMPHEAD=`mktemp`\
3f1b01
TMPBODY=`mktemp`\
3f1b01
for file in %* ; do \
3f1b01
    head -1 $file > $TMPHEAD\
3f1b01
    tail -n +2 $file > $TMPBODY\
3f1b01
    %{__perl} -pi -e '$f = /^#!/ ? "" : "#!%{__perl}$/"; $_="$f$_"' $TMPHEAD\
3f1b01
    cat $TMPHEAD $TMPBODY > $file\
3f1b01
done\
3f1b01
%{__perl} -MExtUtils::MakeMaker -e "ExtUtils::MM_Unix->fixin(qw{%*})"\
3f1b01
%{__rm} $TMPHEAD $TMPBODY\
3f1b01
%{nil}
3f1b01
3f1b01
# additional -tests subpackage requires, if any
3f1b01
%tests_subpackage_requires() %{expand: \
3f1b01
%global __tests_spkg_req %{?__tests_spkg_req} %* \
3f1b01
}
3f1b01
3f1b01
# additional -tests subpackage provides, if any
3f1b01
%tests_subpackage_provides() %{expand: \
3f1b01
%global __tests_spkg_prov %{?__tests_spkg_prov} %* \
3f1b01
}
3f1b01
3f1b01
#
3f1b01
# Runs after the body of %check completes.
3f1b01
#
3f1b01
3f1b01
%__perl_check_pre %{expand: \
3f1b01
%{?__spec_check_pre} \
3f1b01
pushd %{buildsubdir} \
3f1b01
%define perl_br_testdir %{buildroot}%{perl_testdir}/%{cpan_dist_name} \
3f1b01
%{__mkdir_p} %{perl_br_testdir} \
3f1b01
%{__tar} -cf - %{__perl_test_dirs} | ( cd %{perl_br_testdir} && %{__tar} -xf - ) \
3f1b01
find . -maxdepth 1 -type f -name '*META*' -exec %{__cp} -vp {} %{perl_br_testdir} ';' \
3f1b01
find %{perl_br_testdir} -type f -exec %{__chmod} -c -x {} ';' \
3f1b01
T_FILES=`find %{perl_br_testdir} -type f -name '*.t'` \
3f1b01
%fix_shbang_line $T_FILES \
3f1b01
%{__chmod} +x $T_FILES \
3f1b01
%{_fixperms} %{perl_br_testdir} \
3f1b01
popd \
3f1b01
}
3f1b01
3f1b01
#
3f1b01
# The actual invoked macro
3f1b01
#
3f1b01
3f1b01
%perl_subpackage_tests() %{expand: \
3f1b01
%global __perl_package 1\
3f1b01
%global __perl_test_dirs %* \
3f1b01
%global __spec_check_pre %{expand:%{__perl_check_pre}} \
3f1b01
%package tests\
3f1b01
Summary: Test suite for package %{name}\
3f1b01
Group: Development/Debug\
3f1b01
Requires: %{name} = %{?epoch:%{epoch}:}%{version}-%{release}\
3f1b01
Requires: /usr/bin/prove \
3f1b01
%{?__tests_spkg_req:Requires: %__tests_spkg_req}\
3f1b01
%{?__tests_spkg_prov:Provides: %__tests_spkg_prov}\
3f1b01
AutoReqProv: 0 \
3f1b01
%description tests\
3f1b01
This package provides the test suite for package %{name}.\
3f1b01
%files tests\
3f1b01
%defattr(-,root,root,-)\
3f1b01
%{perl_testdir}\
3f1b01
}
3f1b01
3f1b01
# shortcut sugar
3f1b01
%perl_default_subpackage_tests %perl_subpackage_tests t/
3f1b01