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