Re: AC_PROG_CC_C99

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dan Manthey <Dan_Manthey@xxxxxxxxxxx> writes:

> I'm using autoconf 2.59, so I copied the relevant parts of the new
> AC_PROG_CC_C99 macro to my aclocal.m4 to use it.  I used the version Roger
> Leigh posted as a diff on December 2nd.
>
> I noticed two issues:
>
> I had to change the order in which flags were tried in order to test for
> "C99-plus-extensions" before "strict-C99" as discussed.  For instance,
> although -std=c99 was tried after -std=gnu99, it should also be tried after
> -qlanglvl=extc99.  This probably doesn't practically matter for any current
> compilers, but putting all extended flags before all strict flags increases
> the chances that the right thing will happen with future tools.

OK, I've rearranged the order to suit.

> Much more importantly, $ac_cv_prog_cc_c99 is set to 'no' if C99 cannot be
> supported (That's all well and good.), but the string ' no' is appended to
> $CC in this case, which makes pretty much all future attempts to compile
> gratuitiously fail.

That shouldn't happen.  Please could you try again with the attached
patch.  Changes in this patch from the previous one:

- - changed order of C99-enabling options
- - don't set $CC on failure
- - AC_PROG_CC_STDC assigns and caches ac_cv_prog_cc_stdc (for backwards
  compatibility)
- - some documentation fixes


Paul, the FSF have received the copyright assignment (Ted Teah said it
would be processed after the new year).  Unless there are any other
requests for changes, this is what I'd like to propose for inclusion.


Happy Christmas!
Roger

- -- 
Roger Leigh
                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                Debian GNU/Linux        http://www.debian.org/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFB0uSWVcFcaSW/uEgRArBKAJ9UQU46XAv2Mxsiu91KDGCGVVBUkwCfZY6L
bx2eqYtvMAXAHjD9C8BvpcQ=
=4GWF
-----END PGP SIGNATURE-----
Index: NEWS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.333
diff -u -r1.333 NEWS
--- NEWS	17 Dec 2004 16:17:18 -0000	1.333
+++ NEWS	29 Dec 2004 17:05:51 -0000
@@ -1,5 +1,17 @@
 * Major changes in Autoconf 2.59c
 
+** AC_PROG_CC_C89, AC_PROG_CC_C99
+  New macros for ISO C99 support.  _AC_PROG_CC_STDC has been renamed
+  to AC_PROG_CC_C89.  The shell variable ac_cv_prog_cc_stdc has been
+  renamed to ac_cv_prog_cc_c89 to reflect its more precise role.
+
+** AC_PROG_CC_STDC
+  Has been unobsoleted, and will check if the compiler supports ISO
+  C99, falling back to ANSI C89 if not.  ac_cv_prog_cc_stdc is
+  retained for backwards compatibility, assuming the value of
+  ac_cv_prog_cc_c99 or ac_cv_prog_cc_c89 (whichever is valid, in
+  that order).
+
 * Major changes in Autoconf 2.59b
 
   Released 2004-08-20, by Paul Eggert.
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.857
diff -u -r1.857 autoconf.texi
--- doc/autoconf.texi	22 Dec 2004 21:50:08 -0000	1.857
+++ doc/autoconf.texi	29 Dec 2004 17:06:09 -0000
@@ -4594,8 +4594,8 @@
 @item @file{inttypes.h} vs.@: @file{stdint.h}
 @hdrindex{inttypes.h}
 @hdrindex{stdint.h}
-Paul Eggert notes that: ISO C 1999 says that @file{inttypes.h} includes
-@file{stdint.h}, so there's no need to include @file{stdint.h}
+Paul Eggert notes that: @acronym{ISO} C 1999 says that @file{inttypes.h}
+includes @file{stdint.h}, so there's no need to include @file{stdint.h}
 separately in a standard environment.  Many implementations have
 @file{inttypes.h} but not @file{stdint.h} (e.g., Solaris 7), but I don't
 know of any implementation that has @file{stdint.h} but not
@@ -5605,7 +5605,7 @@
 
 After calling this macro you can check whether the C compiler has been
 set to accept @acronym{ANSI} C; if not, the shell variable
-@code{ac_cv_prog_cc_stdc} is set to @samp{no}.  If you wrote your source
+@code{ac_cv_prog_cc_c89} is set to @samp{no}.  If you wrote your source
 code in @acronym{ANSI} C, you can make an un-@acronym{ANSI}fied copy of it by
 using the program @code{ansi2knr}, which comes with Automake.  See also
 under @code{AC_C_PROTOTYPES} below.
@@ -5659,6 +5659,49 @@
 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
 @code{AC_RUN_IFELSE} (@pxref{Run Time}).
 
+@defmac AC_PROG_CC_STDC
+@acindex{PROG_CC_STDC}
+If the C compiler is not able to compile @acronym{ISO} Standard C
+(currently @acronym{ISO} C99), try to add an option to output variable
+@code{CC} to make it so.  If the compiler does not support
+@acronym{ISO} C99, fall back to supporting @acronym{ANSI} C89
+(@acronym{ISO} C90).
+
+After calling this macro you can check whether the C compiler has been
+set to accept @acronym{ISO} Standard C; if not, the shell variable
+@code{ac_cv_prog_cc_stdc} is set to @samp{no}.
+@end defmac
+
+@defmac AC_PROG_CC_C89
+@acindex{PROG_CC_C89}
+If the C compiler is not in @acronym{ANSI} C89 (@acronym{ISO} C90) mode
+by default, try to add an option to output variable @code{CC} to make
+it so.  This macro tries various options that select @acronym{ANSI} C89
+on some system or another.  It considers the compiler to be in
+@acronym{ANSI} C89 mode if it handles function prototypes correctly.
+
+After calling this macro you can check whether the C compiler has been
+set to accept @acronym{ANSI} C89 C; if not, the shell variable
+@code{ac_cv_prog_cc_c89} is set to @samp{no}.
+
+This macro is called automatically by @code{AC_PROG_CC}.
+@end defmac
+
+@defmac AC_PROG_CC_C99
+@acindex{PROG_CC_C99}
+If the C compiler is not in @acronym{ISO} C99 C mode by default, try to
+add an option to output variable @code{CC} to make it so.  This macro
+tries various options that select @acronym{ISO} C99 C on some system or
+another.  It considers the compiler to be in @acronym{ISO} C99 C mode
+if it handles _Bool, flexible arrays, inline, long long, mixed code and
+declarations, named initialization of structs, restrict, varargs macros,
+variable declarations in for loops and variable length arrays.
+
+After calling this macro you can check whether the C compiler has been
+set to accept @acronym{ISO} C99 C; if not, the shell variable
+@code{ac_cv_prog_cc_c99} is set to @samp{no}.
+@end defmac
+
 @defmac AC_C_BACKSLASH_A
 @acindex{HAVE_C_BACKSLASH_A}
 Define @samp{HAVE_C_BACKSLASH_A} to 1 if the C compiler understands
@@ -14268,11 +14311,6 @@
 @code{AC_PREFIX_PROGRAM}
 @end defmac
 
-@defmac AC_PROG_CC_STDC
-@acindex{PROG_CC_STDC}
-This macro has been integrated into @code{AC_PROG_CC}.
-@end defmac
-
 @defmac AC_PROGRAMS_CHECK
 @acindex{PROGRAMS_CHECK}
 @code{AC_CHECK_PROGS}
Index: lib/autoconf/c.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/c.m4,v
retrieving revision 1.191
diff -u -r1.191 c.m4
--- lib/autoconf/c.m4	2 Dec 2004 20:09:03 -0000	1.191
+++ lib/autoconf/c.m4	29 Dec 2004 17:06:10 -0000
@@ -485,7 +485,7 @@
 _AC_LANG_COMPILER_GNU
 GCC=`test $ac_compiler_gnu = yes && echo yes`
 _AC_PROG_CC_G
-_AC_PROG_CC_STDC
+_AC_PROG_CC_C89
 # Some people use a C++ compiler to compile C.  Since we use `exit',
 # in C++ we need to declare it.  In case someone uses the same compiler
 # for both compiling C and C++ we need to have the C++ compiler decide
@@ -810,17 +810,17 @@
 # 4b. C compiler characteristics.  #
 # -------------------------------- #
 
-# _AC_PROG_CC_STDC
-# ----------------
-# If the C compiler in not in ANSI C mode by default, try to add an
-# option to output variable @code{CC} to make it so.  This macro tries
-# various options that select ANSI C on some system or another.  It
-# considers the compiler to be in ANSI C mode if it handles function
-# prototypes correctly.
-AC_DEFUN([_AC_PROG_CC_STDC],
-[AC_MSG_CHECKING([for $CC option to accept ANSI C])
-AC_CACHE_VAL(ac_cv_prog_cc_stdc,
-[ac_cv_prog_cc_stdc=no
+# _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
+# ----------------------------------------------------------------
+# If the C compiler in not in ANSI C89 (ISO C90) mode by default, try
+# to add an option to output variable @code{CC} to make it so.  This
+# macro tries various options that select ANSI C89 on some system or
+# another.  It considers the compiler to be in ANSI C89 mode if it
+# handles function prototypes correctly.
+AC_DEFUN([_AC_PROG_CC_C89],
+[AC_MSG_CHECKING([for $CC option to accept ANSI C89 C])
+AC_CACHE_VAL(ac_cv_prog_cc_c89,
+[ac_cv_prog_cc_c89=no
 ac_save_CC=$CC
 AC_LANG_CONFTEST([AC_LANG_PROGRAM(
 [[#include <stdarg.h>
@@ -875,26 +875,215 @@
 do
   CC="$ac_save_CC $ac_arg"
   _AC_COMPILE_IFELSE([],
-		     [ac_cv_prog_cc_stdc=$ac_arg
+		     [ac_cv_prog_cc_c89=$ac_arg
 break])
 done
 rm -f conftest.$ac_ext conftest.$ac_objext
-CC=$ac_save_CC
+case "x$ac_cv_prog_cc_c89" in
+  x|xno)
+    CC="$ac_save_CC" ;;
+  *)
+    CC="$ac_save_CC $ac_cv_prog_cc_c89" ;;
+esac
 ])
-case "x$ac_cv_prog_cc_stdc" in
+case "x$ac_cv_prog_cc_c89" in
+  xno)
+    AC_MSG_RESULT([unsupported])
+    $2 ;;
+  *)
+    if test "x$ac_cv_prog_cc_c89" = x; then
+      AC_MSG_RESULT([none needed])
+    else
+      AC_MSG_RESULT([$ac_cv_prog_cc_c89])
+    fi
+    $1 ;;
+esac
+])# _AC_PROG_CC_C89
+
+
+# _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
+# ----------------------------------------------------------------
+# If the C compiler in not in ISO C99 C mode by default, try to add an
+# option to output variable @code{CC} to make it so.  This macro tries
+# various options that select ISO C99 C on some system or another.  It
+# considers the compiler to be in ISO C99 C mode if it handles mixed
+# code and declarations, _Bool, inline and restrict.
+AC_DEFUN([_AC_PROG_CC_C99],
+[AC_MSG_CHECKING([for $CC option to accept ISO C99 C])
+AC_CACHE_VAL(ac_cv_prog_cc_c99,
+[ac_cv_prog_cc_c99=no
+ac_save_CC=$CC
+AC_LANG_CONFTEST([AC_LANG_PROGRAM(
+[[#include <stdarg.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <stdio.h>
+
+struct incomplete_array
+{
+  int datasize;
+  double data[];
+};
+
+struct named_init {
+  int number;
+  const wchar_t *name;
+  double average;
+};
+
+static inline int
+test_restrict(const char *restrict text)
+{
+  // See if C++-style comments work.
+  // Iterate through items via the restricted pointer.
+  // Also check for declarations in for loops.
+  for (unsigned int i = 0; *(text+i) != '\0'; ++i);
+  return 0;
+}
+
+// Check varargs and va_copy work.
+static void
+test_varargs(const char *format, ...)
+{
+  va_list args;
+  va_start(args, format);
+  va_list args_copy;
+  va_copy(args_copy, args);
+
+  const char *str;
+  int number;
+  float fnumber;
+
+  while (*format)
+    {
+      switch (*format++)
+	{
+	case 's': // string
+	  str = va_arg(args_copy, const char *);
+	  break;
+	case 'd': // int
+	  number = va_arg(args_copy, int);
+	  break;
+	case 'f': // float
+	  fnumber = (float) va_arg(args_copy, double);
+	  break;
+	default:
+	  break;
+	}
+    }
+  va_end(args_copy);
+  va_end(args);
+}
+]],
+[[
+  // Check bool and long long datatypes.
+  _Bool success = false;
+  long long int bignum = -1234567890LL;
+  unsigned long long int ubignum = 1234567890uLL;
+
+  // Check restrict.
+  if (test_restrict("String literal") != 0)
+    success = true;
+  char *restrict newvar = "Another string";
+
+  // Check varargs.
+  test_varargs("s, d' f .", "string", 65, 34.234);
+
+  // Check incomplete arrays work.
+  struct incomplete_array *ia =
+    malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10));
+  ia->datasize = 10;
+  for (int i = 0; i < ia->datasize; ++i)
+    ia->data[i] = (double) i * 1.234;
+
+  // Check named initialisers.
+  struct named_init ni = {
+    .number = 34,
+    .name = L"Test wide string",
+    .average = 543.34343,
+  };
+
+  ni.number = 58;
+
+  int dynamic_array[ni.number];
+  dynamic_array[43] = 543;
+]])])
+# Try
+# GCC		-std=gnu99 -std=c99 -std=iso9899:1999
+# AIX		-qlanglvl=extc99 -qlanglvl=stdc99
+# Intel ICC	-c99
+# IRIX		-c99
+# Solaris	-xc99
+# Tru64		-c99
+# with extended modes being tried first.
+for ac_arg in "" -std=gnu99 -qlanglvl=extc99 -std=c99 -std=iso9899:1999 -c99 -xc99 -qlanglvl=stdc99 
+do
+  CC="$ac_save_CC $ac_arg"
+  _AC_COMPILE_IFELSE([],
+		     [ac_cv_prog_cc_c99=$ac_arg
+break])
+done
+rm -f conftest.$ac_ext conftest.$ac_objext
+case "x$ac_cv_prog_cc_c99" in
   x|xno)
-    AC_MSG_RESULT([none needed]) ;;
+    CC="$ac_save_CC" ;;
   *)
-    AC_MSG_RESULT([$ac_cv_prog_cc_stdc])
-    CC="$CC $ac_cv_prog_cc_stdc" ;;
+    CC="$ac_save_CC $ac_cv_prog_cc_c99" ;;
 esac
-])# _AC_PROG_CC_STDC
+])
+case "x$ac_cv_prog_cc_c99" in
+  xno)
+    AC_MSG_RESULT([unsupported])
+    $2 ;;
+  *)
+    if test "x$ac_cv_prog_cc_c99" = x; then
+      AC_MSG_RESULT([none needed])
+    else
+      AC_MSG_RESULT([$ac_cv_prog_cc_c99])
+    fi
+    $1 ;;
+esac
+])# _AC_PROG_CC_C99
+
+
+# AC_PROG_CC_C89
+# --------------
+AC_DEFUN([AC_PROG_CC_C89],
+[ AC_REQUIRE([AC_PROG_CC])dnl
+  _AC_PROG_CC_C89
+])
+
+
+# AC_PROG_CC_C99
+# --------------
+AC_DEFUN([AC_PROG_CC_C99],
+[ AC_REQUIRE([AC_PROG_CC])dnl
+  _AC_PROG_CC_C99
+])
 
 
 # AC_PROG_CC_STDC
 # ---------------
-# Has been merged into AC_PROG_CC.
-AU_DEFUN([AC_PROG_CC_STDC], [])
+AC_DEFUN([AC_PROG_CC_STDC],
+[ AC_REQUIRE([AC_PROG_CC])dnl
+  _AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
+                  [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89], [no])])dnl
+  AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
+  AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
+  case "x$ac_cv_prog_cc_stdc" in
+    xno)
+      AC_MSG_RESULT([unsupported])
+      ;;
+    *)
+      if test "x$ac_cv_prog_cc_stdc" = x; then
+        AC_MSG_RESULT([none needed])
+      else
+        AC_MSG_RESULT([$ac_cv_prog_cc_stdc])
+      fi
+      ;;
+  esac					  
+])
 
 
 # AC_C_BACKSLASH_A
@@ -1246,7 +1435,7 @@
 AC_DEFUN([AC_C_PROTOTYPES],
 [AC_REQUIRE([AC_PROG_CC])dnl
 AC_MSG_CHECKING([for function prototypes])
-if test "$ac_cv_prog_cc_stdc" != no; then
+if test "$ac_cv_prog_cc_c89" != no; then
   AC_MSG_RESULT([yes])
   AC_DEFINE(PROTOTYPES, 1,
 	    [Define to 1 if the C compiler supports function prototypes.])
_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux