1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7#
8# This is for perl modules that use the old Makefile.PL build system
9#
10inherit cpan-base perlnative
11
12EXTRA_CPANFLAGS ?= ""
13EXTRA_PERLFLAGS ?= ""
14
15# Env var which tells perl if it should use host (no) or target (yes) settings
16export PERLCONFIGTARGET = "${@is_target(d)}"
17
18# Env var which tells perl where the perl include files are
19export PERL_INC = "${STAGING_LIBDIR}${PERL_OWN_DIR}/perl5/${@get_perl_version(d)}/${@get_perl_arch(d)}/CORE"
20export PERL_LIB = "${STAGING_LIBDIR}${PERL_OWN_DIR}/perl5/${@get_perl_version(d)}"
21export PERL_ARCHLIB = "${STAGING_LIBDIR}${PERL_OWN_DIR}/perl5/${@get_perl_version(d)}/${@get_perl_arch(d)}"
22export PERLHOSTLIB = "${STAGING_LIBDIR_NATIVE}/perl5/${@get_perl_version(d)}/"
23export PERLHOSTARCHLIB = "${STAGING_LIBDIR_NATIVE}/perl5/${@get_perl_version(d)}/${@get_perl_hostarch(d)}/"
24
25cpan_do_configure () {
26	yes '' | perl ${EXTRA_PERLFLAGS} Makefile.PL INSTALLDIRS=vendor NO_PERLLOCAL=1 NO_PACKLIST=1 PERL=$(which perl) ${EXTRA_CPANFLAGS}
27
28	# Makefile.PLs can exit with success without generating a
29	# Makefile, e.g. in cases of missing configure time
30	# dependencies. This is considered a best practice by
31	# cpantesters.org. See:
32	#  * http://wiki.cpantesters.org/wiki/CPANAuthorNotes
33	#  * http://www.nntp.perl.org/group/perl.qa/2008/08/msg11236.html
34	[ -e Makefile ] || bbfatal "No Makefile was generated by Makefile.PL"
35
36	if [ "${BUILD_SYS}" != "${HOST_SYS}" ]; then
37		. ${STAGING_LIBDIR}${PERL_OWN_DIR}/perl5/config.sh
38		# Use find since there can be a Makefile generated for each Makefile.PL
39		for f in `find -name Makefile.PL`; do
40			f2=`echo $f | sed -e 's/.PL//'`
41			test -f $f2 || continue
42			sed -i -e "s:\(PERL_ARCHLIB = \).*:\1${PERL_ARCHLIB}:" \
43				-e 's/perl.real/perl/' \
44				-e "s|^\(CCFLAGS =.*\)|\1 ${CFLAGS}|" \
45				$f2
46		done
47	fi
48}
49
50do_configure:append:class-target() {
51       find . -name Makefile | xargs sed -E -i \
52           -e 's:LD_RUN_PATH ?= ?"?[^"]*"?::g'
53}
54
55do_configure:append:class-nativesdk() {
56       find . -name Makefile | xargs sed -E -i \
57           -e 's:LD_RUN_PATH ?= ?"?[^"]*"?::g'
58}
59
60cpan_do_compile () {
61	oe_runmake PASTHRU_INC="${CFLAGS}" LD="${CCLD}"
62}
63
64cpan_do_install () {
65	oe_runmake DESTDIR="${D}" install_vendor
66	for PERLSCRIPT in `grep -rIEl '#! *${bindir}/perl-native.*/perl' ${D}`; do
67		sed -i -e 's|${bindir}/perl-native.*/perl|/usr/bin/env nativeperl|' $PERLSCRIPT
68	done
69}
70
71EXPORT_FUNCTIONS do_configure do_compile do_install
72