patches/gcc/3.4.4/fix-fixincl.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Feb 24 11:00:05 2007 +0000 (2007-02-24)
changeset 1 eeea35fbf182
permissions -rw-r--r--
Add the full crosstool-NG sources to the new repository of its own.
You might just say: 'Yeah! crosstool-NG's got its own repo!".
Unfortunately, that's because the previous repo got damaged beyond repair and I had no backup.
That means I'm putting backups in place in the afternoon.
That also means we've lost history... :-(
yann@1
     1
See http://gcc.gnu.org/PR22541
yann@1
     2
yann@1
     3
From: Dan Kegel
yann@1
     4
yann@1
     5
When building gcc-3.4.3 or gcc-4.0.0 as a cross into a clean $PREFIX
yann@1
     6
(the only two I've tried like this), the configure script happily copies
yann@1
     7
the glibc include files from include to sys-include; here's the line
yann@1
     8
from the log file (with $PREFIX instead of the real prefix):
yann@1
     9
yann@1
    10
Copying $PREFIX/i686-unknown-linux-gnu/include to $PREFIX/i686-unknown-linux-gnu/sys-include
yann@1
    11
yann@1
    12
But later, when running fixincludes, it gives the error message
yann@1
    13
 The directory that should contain system headers does not exist:
yann@1
    14
  $PREFIX/lib/gcc/i686-unknown-linux-gnu/3.4.3/../../../../i686-unknown-linux-gnu/sys-include
yann@1
    15
yann@1
    16
Nevertheless, it continues building; the header files it installs in
yann@1
    17
 $PREFIX/lib/gcc/i686-unknown-linux-gnu/3.4.3/include
yann@1
    18
do not include the boilerplate that would cause it to #include_next the
yann@1
    19
glibc headers in the system header directory.
yann@1
    20
Thus the resulting toolchain can't compile the following program:
yann@1
    21
#include <limits.h>
yann@1
    22
int x = PATH_MAX;
yann@1
    23
because its limits.h doesn't include the glibc header.
yann@1
    24
yann@1
    25
That's not nice.  I suspect the problem is that gcc/Makefile.in assumes that
yann@1
    26
it can refer to $PREFIX/i686-unknown-linux-gnu  with the path 
yann@1
    27
                $PREFIX/lib/../i686-unknown-linux-gnu, but
yann@1
    28
that fails because the directory $PREFIX/lib doesn't exist during 'make all';
yann@1
    29
it is only created later, during 'make install'.  (Which makes this problem
yann@1
    30
confusing, since one only notices the breakage well after 'make install',
yann@1
    31
at which point the path configure complained about does exist, and has the
yann@1
    32
right stuff in it.)
yann@1
    33
yann@1
    34
A possible fix is to replace the line in gcc/Makefile.in that says
yann@1
    35
    SYSTEM_HEADER_DIR = @SYSTEM_HEADER_DIR@
yann@1
    36
with a version that gets rid of extra ..'s, e.g.
yann@1
    37
    SYSTEM_HEADER_DIR = `echo @SYSTEM_HEADER_DIR@ | sed -e :a -e "s,[^/]*/\.\.\/,,;ta"`
yann@1
    38
(hey, that's the first time I've ever used a label in a sed script; thanks to the sed faq
yann@1
    39
for explaining the :a ... ta method of looping to repeat a search-and-replace until it doesn't match.)
yann@1
    40
yann@1
    41
yann@1
    42
--- gcc-3.4.3/gcc/Makefile.in.foo	2005-05-20 11:41:39.000000000 -0700
yann@1
    43
+++ gcc-3.4.3/gcc/Makefile.in	2005-05-20 12:08:46.000000000 -0700
yann@1
    44
@@ -350,7 +350,10 @@
yann@1
    45
 CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@
yann@1
    46
 
yann@1
    47
 # autoconf sets SYSTEM_HEADER_DIR to one of the above.
yann@1
    48
-SYSTEM_HEADER_DIR = @SYSTEM_HEADER_DIR@
yann@1
    49
+# Purge it of unneccessary internal relative paths
yann@1
    50
+# to directories that might not exist yet.
yann@1
    51
+# The sed idiom for this is to repeat the search-and-replace until it doesn't match, using :a ... ta.
yann@1
    52
+SYSTEM_HEADER_DIR = `echo @SYSTEM_HEADER_DIR@ | sed -e :a -e "s,[^/]*/\.\.\/,," -e ta`
yann@1
    53
 
yann@1
    54
 # Control whether to run fixproto and fixincludes.
yann@1
    55
 STMP_FIXPROTO = @STMP_FIXPROTO@
yann@1
    56
@@ -2532,11 +2535,13 @@
yann@1
    57
 	$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(gcc_tooldir)
yann@1
    58
 
yann@1
    59
 # Build fixed copies of system files.
yann@1
    60
+# Abort if no system headers available, unless building a crosscompiler.
yann@1
    61
+# FIXME: abort unless building --without-headers would be more accurate and less ugly
yann@1
    62
 stmp-fixinc: fixinc.sh gsyslimits.h
yann@1
    63
 	@if test ! -d ${SYSTEM_HEADER_DIR}; then \
yann@1
    64
 	  echo The directory that should contain system headers does not exist: >&2 ; \
yann@1
    65
 	  echo "  ${SYSTEM_HEADER_DIR}" >&2 ; \
yann@1
    66
-	  if test "x${SYSTEM_HEADER_DIR}" = "x${gcc_tooldir}/sys-include"; \
yann@1
    67
+	  if test "x${SYSTEM_HEADER_DIR}" = "x`echo "${gcc_tooldir}/sys-include" | sed -e :a -e "s,[^/]*/\.\.\/,," -e ta`"; \
yann@1
    68
 	  then sleep 1; else exit 1; fi; \
yann@1
    69
 	fi
yann@1
    70
 	rm -rf include; mkdir include