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