summaryrefslogtreecommitdiff
path: root/patches/irssi/0001-perl-cross-compilation-use-staging-dir.patch
blob: 765233d694b3ec0153815fee970ebda48e87ef74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Use the target perl from $STAGING_DIR when cross-compiling the perl plugin

When cross-compiling (e.g. from Buildroot), the perl found by configure is a
host perl and ExtUtils::Embed reports host paths (/usr/lib/<host>/perl/...),
which the cross compiler rejects as "unsafe header/library path", so perl
support was silently disabled.

When $cross_compiling = yes and $STAGING_DIR is set (Buildroot exports it),
derive the perl flags from the target perl installation found in
$STAGING_DIR/usr/lib/perl5/*/*/CORE (ccflags/ldflags/lddlflags/libs and the
INSTALL* dirs are read from its Config_heavy.pl), and pass staging-rooted
PERL_LIB/PERL_ARCHLIB/PERL_INC plus LD/LDDLFLAGS and target-rooted INSTALL*
to the MakeMaker-generated Makefiles of the perl XS subdirectories, so that
both the build and "make install DESTDIR=..." use the right paths.

--- a/configure.ac
+++ b/configure.ac
@@ -442,6 +442,40 @@
 		    ;;
 		esac
 
+		dnl * When cross-compiling (e.g. from Buildroot), $perlpath is a host
+		dnl * perl and ExtUtils::Embed reports paths of the *host* perl
+		dnl * installation, which the cross compiler rejects as "unsafe
+		dnl * header/library path".  Buildroot exports STAGING_DIR pointing at
+		dnl * the target sysroot: use the target perl installation found there
+		dnl * instead, and override the MakeMaker variables of the perl XS
+		dnl * subdirectories with staging-rooted paths (and target-rooted
+		dnl * INSTALL* dirs, so that "make install DESTDIR=..." lands in the
+		dnl * target rootfs).
+		if test "x$cross_compiling" = "xyes" && test -n "$STAGING_DIR"; then
+			perl_core=
+			for d in "$STAGING_DIR"/usr/lib/perl5/*/*/CORE; do
+				if test -d "$d"; then perl_core="$d"; fi
+			done
+			if test -n "$perl_core"; then
+				perl_archlib=`dirname "$perl_core"`
+				perl_privlib=`dirname "$perl_archlib"`
+				perl_ccflags=`grep "^ccflags=" "$perl_archlib/Config_heavy.pl" | cut -d= -f2- | tr -d "\\047"`
+				perl_ldflags=`grep "^ldflags=" "$perl_archlib/Config_heavy.pl" | cut -d= -f2- | tr -d "\\047"`
+				perl_lddlflags=`grep "^lddlflags=" "$perl_archlib/Config_heavy.pl" | cut -d= -f2- | tr -d "\\047"`
+				perl_libs=`grep "^libs=" "$perl_archlib/Config_heavy.pl" | cut -d= -f2- | tr -d "\\047"`
+				perl_installprivlib=`grep "^installprivlib=" "$perl_archlib/Config_heavy.pl" | cut -d= -f2- | tr -d "\\047"`
+				perl_installarchlib=`grep "^installarchlib=" "$perl_archlib/Config_heavy.pl" | cut -d= -f2- | tr -d "\\047"`
+				perl_installsitelib=`grep "^installsitelib=" "$perl_archlib/Config_heavy.pl" | cut -d= -f2- | tr -d "\\047"`
+				perl_installsitearch=`grep "^installsitearch=" "$perl_archlib/Config_heavy.pl" | cut -d= -f2- | tr -d "\\047"`
+				PERL_CFLAGS="$perl_ccflags -I$perl_core"
+				PERL_LDFLAGS="-Wl,-E $perl_ldflags -L$perl_core -lperl $perl_libs"
+				PERL_CROSS_MAKE_PARAMS="LD=\"$CC\" LDDLFLAGS=\"$perl_lddlflags -fPIC\" PERL_LIB=$perl_privlib PERL_ARCHLIB=$perl_archlib PERL_INC=$perl_core INSTALLPRIVLIB=$perl_installprivlib INSTALLARCHLIB=$perl_installarchlib INSTALLSITELIB=$perl_installsitelib INSTALLSITEARCH=$perl_installsitearch"
+				AC_MSG_NOTICE([cross-compiling: using target perl from $perl_core])
+			else
+				perl_check_error="target perl not found in \$STAGING_DIR/usr/lib/perl5"
+			fi
+		fi
+
 		dnl * check that perl's ldflags actually work
 		echo "#include <EXTERN.h>" > conftest.c
 		echo "#include <perl.h>" >> conftest.c
@@ -538,6 +572,7 @@
 		AC_SUBST(PERL_MM_OPT)
 		AC_SUBST(PERL_MM_PARAMS)
 		AC_SUBST(PERL_STATIC_LIBS)
+		AC_SUBST(PERL_CROSS_MAKE_PARAMS)
 	fi
 fi
 
--- a/src/perl/Makefile.am
+++ b/src/perl/Makefile.am
@@ -143,14 +143,14 @@
 	  if [ ! -f Makefile ]; then \
 	    $(am_v_pl__show_gen)$(perlpath) Makefile.PL $(PERL_MM_PARAMS) $(am_v_pl__hide_gen); \
 	  fi && \
-	  ($(MAKE) CC="$(CC)" CCFLAGS="$(PERL_CFLAGS) $(CFLAGS)" $(PERL_EXTRA_OPTS) || \
-	   $(MAKE) CC="$(CC)" CCFLAGS="$(PERL_CFLAGS) $(CFLAGS)" $(PERL_EXTRA_OPTS)) && \
+	  ($(MAKE) CC="$(CC)" $(PERL_CROSS_MAKE_PARAMS) CCFLAGS="$(PERL_CFLAGS) $(CFLAGS)" $(PERL_EXTRA_OPTS) || \
+	   $(MAKE) CC="$(CC)" $(PERL_CROSS_MAKE_PARAMS) CCFLAGS="$(PERL_CFLAGS) $(CFLAGS)" $(PERL_EXTRA_OPTS)) && \
 	  cd ..; \
 	done
 
 install-exec-local:
 	for dir in $(perl_dirs); do \
-	  cd $$dir && $(MAKE) install && cd ..; \
+	  cd $$dir && $(MAKE) $(PERL_CROSS_MAKE_PARAMS) install && cd ..; \
 	done
 
 clean-generic: