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