
# perl library paths
%perl_vendor_privlib	%(eval "`%__perl -V:installvendorlib`"; echo "$installvendorlib")
%perl_vendor_archlib	%(eval "`%__perl -V:installvendorarch`"; echo "$installvendorarch")
%perl_vendor_autolib	%perl_vendor_archlib/auto

# MDK compatibility
%perl_vendorlib		%perl_vendor_privlib
%perl_vendorarch	%perl_vendor_archlib
%makeinstall_std	%make_install install DESTDIR=%buildroot

# mandirs
%perl_vendor_man1dir	%_man1dir
%perl_vendor_man3dir	%_man3dir

# build with the same optimization as perl
%perl_vendor_optflags	%(eval "`%__perl -V:optimize`"; echo "$optimize")

# automate various rpmbuild stages
# MM stands for ExtUtils::MakeMaker
# MB stands for Module::Build

# %%build helpers
%perl_vendor_build \
_perl_vendor_MB_build() { \
	: writing Build script \
	%__perl Build.PL installdirs=vendor "$@" </dev/null \
	: running Build script \
	%__perl Build \
	%{?!_without_test:%{?!_disable_test:: running tests; LD_BIND_NOW=1 PERL_DL_NONLAZY=1 %__perl Build test %{?_enable_debug:test_verbose=1}}} \
} \
_perl_vendor_MM_build() { \
	%{?_without_smp:NPROCS=1; : NOTE: SMP-incompatible} \
	%{?_disable_smp:NPROCS=1; : NOTE: SMP-incompatible} \
	: looking for PREREQ dependencies \
	%__perl Makefile.PL PRINT_PREREQ=1 "$@" </dev/null | tee .perl.req \
	: writing Makefile \
	%__perl Makefile.PL PREFIX=%_prefix INSTALLDIRS=vendor "$@" </dev/null \
	: running make \
	%make_build OPTIMIZE="%{!?_enable_debug:%perl_vendor_optflags}%{?_enable_debug:%optflags}%{?_enable_Werror: -Werror}" CP="%__cp -p" \
	%{?!_without_test:%{?!_disable_test:: running tests; LD_BIND_NOW=1 PERL_DL_NONLAZY=1 %__make test CP="%__cp -p" %{?_enable_debug:TEST_VERBOSE=1} </dev/null}} \
} \
_perl_vendor_fixin() { \
	find . -type f -print0 | xargs -r0 %__subst -p \\\
	'1s,^#![[:space:]]*\\([^[:space:]]*/\\)\\?perl\\([^/[:alpha:][:space:]][^/[:space:]]*\\)\\?\\([[:space:]]\\|$\\),#!%__perl\\3,' \
} \
_perl_vendor_check_dso() { \
	: checking for undefined symbols \
	BLIBS="$BLIBS${BLIBS:+ }$(find $PWD/blib -type f -name '*.so' ||:)" \
	[ -n "$BLIBS" ] || return 0 \
	echo 'int main(){return 0;}' >ldtest.c \
	gcc ldtest.c ${LD_LIBRARY_PATH:+-L$LD_LIBRARY_PATH} -lperl $BLIBS $EXTRA_BLIBS \
	LD_BIND_NOW=1 ./a.out \
	rm -f ldtest.c ./a.out \
} \
perl_vendor_build() { \
		_perl_vendor_fixin \
	if [ -f Build.PL ]; then \
		_perl_vendor_MB_build "$@" \
	else \
		_perl_vendor_MM_build "$@" \
	fi \
		_perl_vendor_check_dso \
} \
perl_vendor_build

# %%install helpers
%perl_vendor_install \
_perl_vendor_MB_install() { \
	: installing \
	%__perl Build install destdir=%buildroot installdirs=vendor "$@" </dev/null \
} \
_perl_vendor_MM_install() { \
	: installing \
	%make_install UNINST=undef CP="%__cp -p" \\\
		DESTDIR=%buildroot PREFIX=%_prefix INSTALLDIRS=vendor \\\
		INSTALLMAN1DIR=%buildroot%perl_vendor_man1dir \\\
		INSTALLMAN3DIR=%buildroot%perl_vendor_man3dir \\\
 		pure_install "$@" </dev/null \
	if %__grep -Fqs 'perl(' .perl.req; then %__cat .perl.req >>%buildroot/.perl.req; fi \
} \
_perl_vendor_check_buildroot() { \
	: prompting for files that contain /usr/local \
	find %buildroot -type f -exec %__grep -FH /usr/local {} ';' \
	: prompting for files that contain /tmp \
	find %buildroot -type f -not -name .packlist -exec %__grep -FH /tmp '{}' ';' \
} \
perl_vendor_install() { \
	if [ -f Build.PL ]; then \
		_perl_vendor_MB_install "$@" \
	else \
		_perl_vendor_MM_install "$@" \
	fi \
		_perl_vendor_check_buildroot \
} \
perl_vendor_install

# sugar
%perl_fix_local %__subst -p 's,/usr/local\\>,/usr,g'
%CPAN() http://search.cpan.org/dist/%1/%nil
