-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 "Steven G. Johnson" <stevenj@xxxxxxxxxxxx> writes: > Roger Leigh wrote: >> # Try >> # GCC -std=gnu99 -std=c99 -std=iso9899:1999 >> # AIX -qlanglvl=extc99 -qlanglvl=stdc99 > > Here are a few more, gleaned from Google (not tested): Thanks. I've implemented these, as well as Paul and Ralf's other suggestions. I've added all these to c.m4, and the diff against the c.m4 in 2.59a is attached. One change I've made is added arguments to AC_PROG_CC_C89, AC_PROG_CC_C89 and AC_PROG_CC_STDC to allow custom code to run on success or failure, to e.g. abort configure if there isn't a C99 compiler available. It should be completely backward-compatible with existing code. Is this OK? Any comments will be gladly received. (Apologies if the formatting is a little weird--it's over two years since I last wrote any m4 other than basic configure scripts.) I can re-do the diff against autoconf CVS if required--I just don't have a copy right now. Regards, 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/> iD8DBQFBrkWNVcFcaSW/uEgRAhqIAKCPfZcOoHIKG4mhNCkXLMaZEMcMKQCgzCkk ZfFi03UQGGVUOhDjOTJ4eug= =Ck+w -----END PGP SIGNATURE-----
--- c.m4.old 2004-12-01 21:51:25.000000000 +0000 +++ c.m4 2004-12-01 22:18:59.000000000 +0000 @@ -483,7 +483,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 @@ -785,17 +785,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> @@ -848,26 +848,109 @@ 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_stdc" in - x|xno) - AC_MSG_RESULT([none needed]) ;; +case "x$ac_cv_prog_cc_c89" in + xno) + AC_MSG_RESULT([unsupported]) + $2 ;; *) - AC_MSG_RESULT([$ac_cv_prog_cc_stdc]) - CC="$CC $ac_cv_prog_cc_stdc" ;; + if test "x$ac_cv_prog_cc_c89" = x; then + AC_MSG_RESULT([none needed]) + else + AC_MSG_RESULT([$ac_cv_prog_cc_c89]) + CC="$CC $ac_cv_prog_cc_c89" + fi + $1 ;; esac -])# _AC_PROG_CC_STDC +])# _AC_PROG_CC_C89 -# AC_PROG_CC_STDC -# --------------- -# Has been merged into AC_PROG_CC. -AU_DEFUN([AC_PROG_CC_STDC], []) +# _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 <stdbool.h> +static inline int +test(const char *restrict text) +{ + int i = 0; + // Iterate through items via the restricted pointer + // and see if C++-style comments work. + while (*(text+i) != '\0') + ++i; + return 0; +}]], +[[_Bool success = false; + if (test("String literal") != 0) + success = true; + char *restrict newvar = "Another string";]])]) +# Try +# GCC -std=gnu99 -std=c99 -std=iso9899:1999 +# AIX -qlanglvl=extc99 -qlanglvl=stdc99 +# Intel ICC -c99 +# IRIX -c99 +# Solaris -xc99 +# Tru64 -c99 +for ac_arg in "" -std=gnu99 -std=c99 -std=iso9899:1999 -c99 -xc99 -qlanglvl=extc99 -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 +CC=$ac_save_CC +]) +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]) + CC="$CC $ac_cv_prog_cc_c99" + fi + $1 ;; +esac +])# _AC_PROG_CC_C99 + + +# AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE]) +# --------------------------------------------------------------- +AC_DEFUN([AC_PROG_CC_C89], +[ AC_REQUIRE([AC_PROG_CC])dnl + _AC_PROG_CC_C89([$1], [$2]) +]) + + +# AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE]) +# --------------------------------------------------------------- +AC_DEFUN([AC_PROG_CC_C99], +[ AC_REQUIRE([AC_PROG_CC])dnl + _AC_PROG_CC_C99([$1], [$2])dnl +]) + + +# AC_PROG_CC_STDC ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE]) +# ---------------------------------------------------------------- +AC_DEFUN([AC_PROG_CC_STDC], +[AC_PROG_CC_C99([$1], [$2])]) # AC_C_BACKSLASH_A @@ -1207,7 +1290,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