From 97cd27c460b8050b7446dcea92f05472146c5d50 Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Sat, 17 Nov 2018 19:27:42 +0200
Subject: Make Errno_pm.PL compatible with /usr/include/<ARCH>/errno.h

As seen in <https://bugs.debian.org/798955>, Debian glibc
maintainers intend to move system header files from /usr/include to
/usr/include/<arch> at some point. This would break Errno_pm.PL, which
has logic for asking cpp for the location of errno.h but fails earlier
if errno.h is not on a list of known paths.

Take the cpp fallback instead of dying. The behaviour should stay
identical as long as errno.h is not moved.

This will also enable multiarch (non-sysroot) cross builds.

Original patch by Helmut Grohne.

Bug-Debian: https://bugs.debian.org/875921
Bug: https://rt.perl.org/Public/Bug/Display.html?id=133662
Patch-Name: fixes/errno-include-path.diff
Origin: upstream, https://perl5.git.perl.org/perl.git/commit/6c5080f25fa3dcede391007ffe328ea53779c52f
---
 ext/Errno/Errno_pm.PL | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/ext/Errno/Errno_pm.PL b/ext/Errno/Errno_pm.PL
index 6a0031f0f7..9d1454c96a 100644
--- a/ext/Errno/Errno_pm.PL
+++ b/ext/Errno/Errno_pm.PL
@@ -2,7 +2,7 @@ use ExtUtils::MakeMaker;
 use Config;
 use strict;
 
-our $VERSION = "1.29";
+our $VERSION = "1.30";
 
 my %err = ();
 
@@ -111,6 +111,17 @@ sub default_cpp {
 
 sub get_files {
     my %file = ();
+    # When cross-compiling we may store a path for gcc's "sysroot" option:
+    my $sysroot = $Config{sysroot} || '';
+    my $linux_errno_h;
+    if ($^O eq 'linux') {
+	# Some Linuxes have weird errno.hs which generate
+	# no #file or #line directives
+	($linux_errno_h) = grep { -e $_ } map { "$_/errno.h" }
+	    "$sysroot/usr/include", "$sysroot/usr/local/include",
+	    split / / => $Config{locincpth};
+    }
+
     # VMS keeps its include files in system libraries
     if ($^O eq 'VMS') {
 	$file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
@@ -125,17 +136,10 @@ sub get_files {
 	}
     } elsif ($^O eq 'linux' &&
 	      $Config{gccversion} ne '' && 
-	      $Config{gccversion} !~ /intel/i
+	      $Config{gccversion} !~ /intel/i &&
 	      # might be using, say, Intel's icc
+	      $linux_errno_h
 	     ) {
-    # When cross-compiling we may store a path for gcc's "sysroot" option:
-    my $sysroot = $Config{sysroot} || '';
-	# Some Linuxes have weird errno.hs which generate
-	# no #file or #line directives
-	my ($linux_errno_h) = grep { -e $_ } map { "$_/errno.h" }
-	    "$sysroot/usr/include", "$sysroot/usr/local/include",
-	    split / / => $Config{locincpth} or
-		die "Cannot find errno.h";
 	$file{$linux_errno_h} = 1;
     } elsif ($^O eq 'haiku') {
 	# hidden in a special place
