Patchwork Properly find getopt system declaration

login
register
mail settings
Submitter Romain GEISSLER
Date Aug. 10, 2011, 7:38 a.m.
Message ID <4E42355F.5020904@st.com>
Download mbox | patch
Permalink /patch/109345/
State New
Headers show

Comments

Romain GEISSLER - Aug. 10, 2011, 7:38 a.m.
Hi

Thanks to the recent changes made to stage 2 and 3 (now built with g++), 
i noticed a little error in the configure script that tries the
system getopt declaration. Indeed, if your system defines it in a system
header file named "getopt.h" (for example /usr/include/getopt.h on a Red 
Hat 4 configuration), the configure script will incorrectly load
/path/to/gcc/src/include/getopt.h instead, and thus find no getopt 
declaration.

This can be solved by changing the appropriate -I${srcdir}/../include by
-iquote ${srcdir}/../include. I added a configure check to verify that 
the compiler accepts the -iquote switch (and fallback to -I otherwise).
Note that this only solve the getopt case, but -I is certainly often 
misused (instead of -iquote that would prevent error with system header 
having the same name than gcc header).

The attached patch has been tested for regression with a native x86_64 
bootstrap.

config/

2011-08-10  Romain Geissler  <romain.geissler@gmail.com>

	* acx.m4 (ACX_CHECK_CC_ACCEPTS_IQUOTE) : Define.


gcc/

2011-08-10  Romain Geissler  <romain.geissler@gmail.com>

	* configure.ac (acx_cv_cc_accepts_iquote): Define through a call
	to ACX_CHECK_CC_ACCEPTS_IQUOTE.
	(CFLAGS for gcc_AC_CHECK_DECLS): Use $acx_cv_cc_accepts_iquote
	instead of "-I".
	* configure: Regenerate.


Romain Geissler
Romain Geissler - Aug. 23, 2011, 2:53 p.m.
2011/8/10 Romain GEISSLER <romain.geissler@st.com>:
> Hi
>
> Thanks to the recent changes made to stage 2 and 3 (now built with g++), i
> noticed a little error in the configure script that tries the
> system getopt declaration. Indeed, if your system defines it in a system
> header file named "getopt.h" (for example /usr/include/getopt.h on a Red Hat
> 4 configuration), the configure script will incorrectly load
> /path/to/gcc/src/include/getopt.h instead, and thus find no getopt
> declaration.
>
> This can be solved by changing the appropriate -I${srcdir}/../include by
> -iquote ${srcdir}/../include. I added a configure check to verify that the
> compiler accepts the -iquote switch (and fallback to -I otherwise).
> Note that this only solve the getopt case, but -I is certainly often misused
> (instead of -iquote that would prevent error with system header having the
> same name than gcc header).
>
> The attached patch has been tested for regression with a native x86_64
> bootstrap.
>
> config/
>
> 2011-08-10  Romain Geissler  <romain.geissler@gmail.com>
>
>        * acx.m4 (ACX_CHECK_CC_ACCEPTS_IQUOTE) : Define.
>
>
> gcc/
>
> 2011-08-10  Romain Geissler  <romain.geissler@gmail.com>
>
>        * configure.ac (acx_cv_cc_accepts_iquote): Define through a call
>        to ACX_CHECK_CC_ACCEPTS_IQUOTE.
>        (CFLAGS for gcc_AC_CHECK_DECLS): Use $acx_cv_cc_accepts_iquote
>        instead of "-I".
>        * configure: Regenerate.
>
>
> Romain Geissler
>

Ping

Patch

Index: config/acx.m4
===================================================================
--- config/acx.m4	(revision 177557)
+++ config/acx.m4	(working copy)
@@ -355,6 +355,21 @@  AC_DEFUN([AC_PROG_CPP_WERROR],
 m4_define([AC_CHECK_HEADER],m4_defn([_AC_CHECK_HEADER_OLD]))
 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
 
+# Check whether the CC accepts the -iquote switch.
+AC_DEFUN([ACX_CHECK_CC_ACCEPTS_IQUOTE], [
+	AC_CACHE_CHECK([wether $CC accepts -iquote], acx_cv_cc_accepts_iquote, [
+		save_CFLAGS=$CFLAGS
+		CFLAGS="-iquote ."
+		AC_COMPILE_IFELSE([int main() { return 0; }],
+			[acx_cv_cc_accepts_iquote=yes], [acx_cv_cc_accepts_iquote=no])
+		CFLAGS=$save_CFLAGS])
+
+	if test x$acx_cv_cc_accepts_iquote = xyes; then
+		cc_quote_include="-iquote "
+	else
+		cc_quote_include="-I"
+	fi])
+
 # Test for GNAT.
 # We require the gnatbind program, and a compiler driver that
 # understands Ada.  We use the user's CC setting, already found,
Index: gcc/configure
===================================================================
--- gcc/configure	(revision 177557)
+++ gcc/configure	(working copy)
@@ -5336,6 +5336,35 @@  $as_echo "$ac_cv_safe_to_define___extens
   $as_echo "#define _TANDEM_SOURCE 1" >>confdefs.h
 
 
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking wether $CC accepts -iquote" >&5
+$as_echo_n "checking wether $CC accepts -iquote... " >&6; }
+if test "${acx_cv_cc_accepts_iquote+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+		save_CFLAGS=$CFLAGS
+		CFLAGS="-iquote ."
+		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main() { return 0; }
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  acx_cv_cc_accepts_iquote=yes
+else
+  acx_cv_cc_accepts_iquote=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+		CFLAGS=$save_CFLAGS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_cv_cc_accepts_iquote" >&5
+$as_echo "$acx_cv_cc_accepts_iquote" >&6; }
+
+	if test x$acx_cv_cc_accepts_iquote = xyes; then
+		cc_quote_include="-iquote "
+	else
+		cc_quote_include="-I"
+	fi
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -10240,7 +10269,7 @@  $as_echo "#define HAVE_LANGINFO_CODESET
 
 # We will need to find libiberty.h and ansidecl.h
 saved_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS -I${srcdir} -I${srcdir}/../include"
+CFLAGS="$CFLAGS ${cc_quote_include}${srcdir} ${cc_quote_include}${srcdir}/../include"
 for ac_func in getenv atol asprintf sbrk abort atof getcwd getwd \
 	strsignal strstr strverscmp \
 	errno snprintf vsnprintf vasprintf malloc realloc calloc \
@@ -17763,7 +17792,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17766 "configure"
+#line 17795 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -17869,7 +17898,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17872 "configure"
+#line 17901 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac	(revision 177557)
+++ gcc/configure.ac	(working copy)
@@ -302,6 +302,7 @@  AC_SUBST(CFLAGS)
 # -------------------------
 
 AC_USE_SYSTEM_EXTENSIONS
+ACX_CHECK_CC_ACCEPTS_IQUOTE
 AC_PROG_CPP
 AC_C_INLINE
 
@@ -1063,7 +1064,7 @@  AM_LANGINFO_CODESET
 
 # We will need to find libiberty.h and ansidecl.h
 saved_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS -I${srcdir} -I${srcdir}/../include"
+CFLAGS="$CFLAGS ${cc_quote_include}${srcdir} ${cc_quote_include}${srcdir}/../include"
 gcc_AC_CHECK_DECLS(getenv atol asprintf sbrk abort atof getcwd getwd \
 	strsignal strstr strverscmp \
 	errno snprintf vsnprintf vasprintf malloc realloc calloc \