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