From 98b12e44bdf730698c03a5a4d8fc93c41d931637 Mon Sep 17 00:00:00 2001 From: Jess Robinson Date: Fri, 19 Oct 2012 19:05:25 +0100 Subject: [PATCH] Introduce sysroot variable to Configure This is borrowed from gcc and allows us to indicate the logical root directory for headers and libraries, under which all -I and -L are searched for. This patch adjusts Configure to search under $sysroot (if supplied) for headers and libraries, instead of /. --sysroot is added to ccflags and friends so that make in ExtUtils::MakeMaker, and other extensions, will use it. Currently this is only done if compiling with some variant of gcc or g++. --- Configure | 93 ++++++++++++++++++++++++++++++++++++++++++++------- ext/Errno/Errno_pm.PL | 6 ++-- 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/Configure b/Configure index ffd2174..e679e50 100755 --- a/Configure +++ b/Configure @@ -209,6 +209,7 @@ from='' run='' targetarch='' to='' +sysroot='' usecrosscompile='' extern_C='' mistrustnm='' @@ -1952,6 +1953,29 @@ true) ;; esac +: Set 'sysroot' to change the logical root directory to your headers and libraries see man gcc +: This is primarily meant for cross-compile environments, and may fail to be useful in other cases + +if test "X$sysroot" != X; then + case "$cc" in + *gcc*|*g++*) + echo "Using $sysroot to find your headers and libraries, adding to ccflags" + case "$ccflags" in + *sysroot*) ;; + 'undef'|*) + ccflags="$ccflags --sysroot=$sysroot" + esac + case "$ldflags" in + *sysroot*) ;; + 'undef'|*) + ldflags="$ldflags --sysroot=$sysroot" + esac + # lddlflags updated below in lddlflags section; + # same with cccdlflags + ;; + esac +fi + : Eunice requires " " instead of "", can you believe it echo " " : Here we go... @@ -2389,7 +2413,7 @@ uname zip " pth=`echo $PATH | sed -e "s/$p_/ /g"` -pth="$pth /lib /usr/lib" +pth="$pth $sysroot/lib $sysroot/usr/lib" for file in $loclist; do eval xxx=\$$file case "$xxx" in @@ -4297,8 +4321,8 @@ echo exit 1 >xenix echo exit 1 >venix echo exit 1 >os2 d_bsd="$undef" -$cat /usr/include/signal.h /usr/include/sys/signal.h >foo 2>/dev/null -if test -f /osf_boot || $contains 'OSF/1' /usr/include/ctype.h >/dev/null 2>&1 +$cat $sysroot/usr/include/signal.h $sysroot/usr/include/sys/signal.h >foo 2>/dev/null +if test -f /osf_boot || $contains 'OSF/1' $sysroot/usr/include/ctype.h >/dev/null 2>&1 then echo "Looks kind of like an OSF/1 system, but we'll see..." echo exit 0 >osf1 @@ -4684,9 +4708,10 @@ case "$ccname" in esac : What should the include directory be ? +: Use sysroot if set, so findhdr looks in the right place. echo " " $echo $n "Hmm... $c" -dflt='/usr/include' +dflt="$sysroot/usr/include" incpath='' mips_type='' if $test -f /bin/mips && /bin/mips; then @@ -4732,7 +4757,7 @@ esac : Set private lib path case "$plibpth" in '') if ./mips; then - plibpth="$incpath/usr/lib /usr/local/lib /usr/ccs/lib" + plibpth="$incpath/usr/lib $sysroot/usr/local/lib $sysroot/usr/ccs/lib" fi;; esac case "$libpth" in @@ -4742,7 +4767,6 @@ case "$libpth" in esac : Now check and see which directories actually exist, avoiding duplicates -libpth='' for xxx in $dlist do if $test -d $xxx; then @@ -4760,6 +4784,14 @@ know not to be holding relevant libraries, and add any that are needed. Say "none" for none. EOM + +if test "X$sysroot" != X; then + $cat </dev/null >> libc.list + if test -f $sysroot/usr/lib/lib$net$_a; then + ( ($nm $nm_opt $sysroot/usr/lib/lib$net$_a | eval $nm_extract) || \ + $ar t $sysroot/usr/lib/lib$net$_a) 2>/dev/null >> libc.list if $contains socket libc.list >/dev/null 2>&1; then d_socket="$define" socketlib="-l$net" case "$net" in net) echo "...but the Wollongong group seems to have hacked it in." >&4 - sockethdr="-I/usr/netinclude" + sockethdr="-I$sysroot/usr/netinclude" ;; esac echo "Found Berkeley sockets interface in lib$net." >&4 @@ -20722,7 +20788,7 @@ esac : Trace out the files included by signal.h, then look for SIGxxx names. if [ "X$fieldn" = X ]; then : Just make some guesses. We check them later. - xxx='/usr/include/signal.h /usr/include/sys/signal.h' + xxx="$sysroot/usr/include/signal.h $sysroot/usr/include/sys/signal.h" else xxx=`echo '#include ' | $cppstdin $cppminus $cppflags 2>/dev/null | @@ -23631,6 +23697,7 @@ strings='$strings' submit='$submit' subversion='$subversion' sysman='$sysman' +sysroot='$sysroot' tail='$tail' tar='$tar' targetarch='$targetarch' diff --git a/ext/Errno/Errno_pm.PL b/ext/Errno/Errno_pm.PL index 5d6bee5..db8ada7 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.20_01"; +our $VERSION = "1.20_02"; my %err = (); @@ -131,10 +131,12 @@ sub get_files { $Config{gccversion} !~ /intel/i # might be using, say, Intel's icc ) { + # 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" } - "/usr/include", "/usr/local/include", + "$sysroot/usr/include", "$sysroot/usr/local/include", split / / => $Config{locincpth} or die "Cannot find errno.h"; $file{$linux_errno_h} = 1; -- 2.7.4