merge of '21fe2445ed0bb510a34a0e01c77e30f0e6c021c3'
[openembedded.git] / classes / cpan.bbclass
1 #
2 # This is for perl modules that use the old Makefile.PL build system
3 #
4 FILES_${PN} += '${libdir}/perl5 ${datadir}/perl5'
5 EXTRA_CPANFLAGS ?= ""
6
7 DEPENDS  += "perl-native"
8 RDEPENDS += "perl"
9
10 # Determine the staged version of perl from the perl configuration file
11 def get_perl_version(d):
12         import os, bb, re
13         cfg = bb.data.expand('${STAGING_DIR}/${HOST_SYS}/perl/config.sh', d)
14         try:
15                 f = open(cfg, 'r')
16         except IOError:
17                 return None
18         l = f.readlines();
19         f.close();
20         r = re.compile("version='(\d\.\d\.\d)'")
21         for s in l:
22                 m = r.match(s)
23                 if m:
24                         return m.group(1)
25         return None
26
27 # Only 5.8.7 and 5.8.4 existed at the time we moved to the new layout
28 def is_new_perl(d):
29         ver = get_perl_version(d)
30         if ver == "5.8.4" or ver == "5.8.7":
31                 return "no"
32         return "yes"
33
34 # Determine where the library directories are
35 def perl_get_libdirs(d):
36         import bb
37         libdir = bb.data.getVar('libdir', d, 1)
38         if is_new_perl(d) == "yes":
39                 libdirs = libdir + '/perl5'
40         else:
41                 libdirs = libdir + '/*/*/perl5'
42         return libdirs
43
44 def is_target(d):
45     import bb
46     if not bb.data.inherits_class('native', d):
47         return "yes"
48     return "no"
49
50 IS_NEW_PERL = "${@is_new_perl(d)}"
51 PERLLIBDIRS = "${@perl_get_libdirs(d)}"
52
53 # Env var which tells perl if it should use host (no) or target (yes) settings
54 export PERLCONFIGTARGET = "${@is_target(d)}"
55
56 cpan_do_configure () {
57         perl Makefile.PL ${EXTRA_CPANFLAGS}
58         if [ "${BUILD_SYS}" != "${HOST_SYS}" ]; then
59                 . ${STAGING_DIR}/${TARGET_SYS}/perl/config.sh
60                 if [ "${IS_NEW_PERL}" = "yes" ]; then
61                         sed -i -e "s:\(SITELIBEXP = \).*:\1${sitelibexp}:" \
62                                 -e "s:\(SITEARCHEXP = \).*:\1${sitearchexp}:" \
63                                 -e "s:\(INSTALLVENDORLIB = \).*:\1${D}${datadir}/perl5:" \
64                                 -e "s:\(INSTALLVENDORARCH = \).*:\1${D}${libdir}/perl5:" \
65                                 -e "s:\(LDDLFLAGS.*\)${STAGING_DIR}/${BUILD_SYS}/lib:\1${STAGING_LIBDIR}:" \
66                                 Makefile
67                 else
68                         sed -i -e "s:\(SITELIBEXP = \).*:\1${sitelibexp}:" \
69                                 -e "s:\(SITEARCHEXP = \).*:\1${sitearchexp}:" \
70                                 -e "s:\(INSTALLVENDORLIB = \).*:\1${D}${libdir}/perl5/site_perl/${version}:" \
71                                 -e "s:\(INSTALLVENDORARCH = \).*:\1${D}${libdir}/perl5/site_perl/${version}:" \
72                                 -e "s:\(LDDLFLAGS.*\)${STAGING_DIR}/${BUILD_SYS}/lib:\1${STAGING_LIBDIR}:" \
73                                 Makefile
74                 fi
75         fi
76 }
77
78 cpan_do_compile () {
79         if [ "${IS_NEW_PERL}" = "yes" ]; then
80                 oe_runmake PASTHRU_INC="${CFLAGS}" CCFLAGS="${CFLAGS}" LD="${CCLD}"
81         else
82                 # You must use gcc to link on sh
83                 OPTIONS=""
84                 if test ${TARGET_ARCH} = "sh3" -o ${TARGET_ARCH} = "sh4"; then
85                         OPTIONS="LD=${TARGET_ARCH}-${TARGET_OS}-gcc"
86                 fi
87                 if test ${TARGET_ARCH} = "powerpc" ; then
88                         OPTIONS="LD=${TARGET_ARCH}-${TARGET_OS}-gcc"
89                 fi
90                 oe_runmake PASTHRU_INC="${CFLAGS}" CCFLAGS="${CFLAGS}" $OPTIONS
91         fi
92 }
93
94 cpan_do_install () {
95         oe_runmake install_vendor
96 }
97
98 EXPORT_FUNCTIONS do_configure do_compile do_install