fix for fixinc problem when building crosscompiler into clean PREFIX

Dan Kegel
Mon Jul 11 16:45:00 GMT 2005

When building gcc-3.4.3 or gcc-4.x into a clean $PREFIX,
the configure script happily copies the glibc include files from include to sys-include;
here's the line from the log file (with $PREFIX instead of the real prefix):

Copying $PREFIX/i686-unknown-linux-gnu/include to $PREFIX/i686-unknown-linux-gnu/sys-include

But later, when running fixincludes, it gives the error message
  The directory that should contain system headers does not exist:

Nevertheless, it continues building; the header files it installs in
do not include the boilerplate that would cause it to #include_next the
glibc headers in the system header directory.
Thus the resulting toolchain can't compile the following program:
#include <limits.h>
int x = PATH_MAX;
because its limits.h doesn't include the glibc header.

The problem is that gcc/ assumes that
it can refer to $PREFIX/i686-unknown-linux-gnu  with the path
                 $PREFIX/lib/../i686-unknown-linux-gnu, but
that fails because the directory $PREFIX/lib doesn't exist during 'make all';
it is only created later, during 'make install'.  (Which makes this problem
confusing, since one only notices the breakage well after 'make install',
at which point the path configure complained about does exist, and has the
right stuff in it.)

A fix that I've been using for a while is to use sed to canonicalize
the path.  The sed syntax is a bit obtuse, but it works.
A patch against gcc-4.0.0 is at
I've been using it happily for about a month.
Here's the same patch rediffed against gcc-4.1-20050709.
I don't have a fsf copyright assignment, but this
should fall under the "trivial and obvious" rule:

--- gcc-4.1-20050709/gcc/	2005-07-11 09:25:37.171541744 -0700
+++ gcc-4.1-20050709/gcc/	2005-07-11 09:30:27.203450192 -0700
@@ -377,7 +377,10 @@

  # autoconf sets SYSTEM_HEADER_DIR to one of the above.
+# Purge it of unneccessary internal relative paths
+# to directories that might not exist yet.
+# The sed idiom for this is to repeat the search-and-replace until it doesn't match, using :a ... ta.
+SYSTEM_HEADER_DIR = `echo @SYSTEM_HEADER_DIR@ | sed -e :a -e "s,[^/]*/\.\.\/,," -e ta`

  # Control whether to run fixproto and fixincludes.
@@ -3109,13 +3112,15 @@
  ../$(build_subdir)/fixincludes/fixincl: ; @ :

  # Build fixed copies of system files.
+# Abort if no system headers available, unless building a crosscompiler.
+# Canonicalize path so directory/that/doesnt/exist/yet/../../../.. doesn't fail
  stmp-fixinc: gsyslimits.h macro_list \
    $(build_objdir)/fixincludes/fixincl \
  	@if test ! -d ${SYSTEM_HEADER_DIR}; then \
  	  echo The directory that should contain system headers does not exist: >&2 ; \
  	  echo "  ${SYSTEM_HEADER_DIR}" >&2 ; \
-	  if test "x${SYSTEM_HEADER_DIR}" = "x${gcc_tooldir}/sys-include"; \
+ 	  if test "x${SYSTEM_HEADER_DIR}" = "x`echo "${gcc_tooldir}/sys-include" | sed -e :a -e "s,[^/]*/\.\.\/,," -e ta`"; \
  	  then sleep 1; else exit 1; fi; \
  	rm -rf include; mkdir include

Trying to get a job as a c++ developer?  See

More information about the Gcc-patches mailing list