develooper Front page | perl.perl5.porters | Postings from August 2012

Cross-compiling, Errno_pm.PL and include paths..

Thread Next
From:
Jess Robinson
Date:
August 14, 2012 09:31
Subject:
Cross-compiling, Errno_pm.PL and include paths..
Message ID:
alpine.LNX.2.00.1208141648200.13078@insel

I asked this briefly on #p5p the other day, and well, not enough yelling 
ensued, so I thought I'd better double-check.. :)

Through the Android standalone-toolchain docs, I learnt of the --sysroot 
option to gcc, which seems quite useful. This sets the logical root dir 
for all libraries and headers, which is lovely for using a cross compiler 
with its own set of said libraries and headers.

Thus my current cross-compiling cc looks like this:

/usr/src/android/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc 
--sysroot=/usr/src/android/android-ndk-r8/platforms/android-8/arch-arm/

The only issue I've discovered so far is that Errno_pm.PL (ext/Errno), 
contains a series of checks to find /usr/include/errno.h. Under this 
scenario, it should look under $sysroot/usr/include/errno.h.

So I've added code to do so, under the check for gcc:

diff --git a/ext/Errno/Errno_pm.PL b/ext/Errno/Errno_pm.PL
index 56bc815..61111a2 100644
--- a/ext/Errno/Errno_pm.PL
+++ b/ext/Errno/Errno_pm.PL
@@ -142,10 +142,15 @@ sub get_files {
  	      $Config{gccversion} !~ /intel/i
  	      # might be using, say, Intel's icc
  	     ) {
+	# General cross-compiling use, cross-compiler in $SYSROOT
+	my $sysroot = `$Config{cc} -print-sysroot` || '';
+        chomp($sysroot);
+
  	# Some Linuxes have weird errno.hs which generate
  	# no #file or #line directives
-	my $linux_errno_h = -e '/usr/include/errno.h' ?
-	    '/usr/include/errno.h' : '/usr/local/include/errno.h';
+	my $linux_errno_h = -e "$sysroot/usr/include/errno.h" 
+	    ? "$sysroot/usr/include/errno.h" 
+	    : "$sysroot/usr/local/include/errno.h";
  	$file{$linux_errno_h} = 1;
      } elsif ($^O eq 'beos' || $^O eq 'haiku') {
  	# hidden in a special place
@@ -495,3 +500,15 @@ under the same terms as Perl itself.
  ESQ

  }
+
+#
+# Local variables:
+# c-indentation-style: bsd
+# c-basic-offset: 4
+# indent-tabs-mode: t
+# tab-width: 8
+# End:
+#
+# ex: set ts=8 sts=4 sw=4 noet:
+#
+

(Plus the sty;e variables to keep me from going crazy..)

Objections?

Jess


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About