+###############################################################################
+#
+# Functions to figure out how to disable // comments in ANSI C code.
+#
+# (With recent gcc, this is done with "-std=c89". With older gcc, this
+# is done by passing "-lang-c89" to cpp, by passing "-Wp,-lang-c89" to
+# gcc. Old gcc doesn't support -std, and new gcc doesn't support -lang.
+# so much for compatibility!)
+#
+###############################################################################
+
+AC_DEFUN(AC_GCC_ACCEPTS_STD,
+ [if test -n "$GCC"; then
+ AC_CACHE_CHECK([whether gcc accepts -std],
+ ac_cv_gcc_accepts_std,
+ [if ( gcc -E -std=c89 - </dev/null 2>&1 >/dev/null | \
+ grep unrecognized >/dev/null ); then
+ ac_cv_gcc_accepts_std=no
+ else
+ ac_cv_gcc_accepts_std=yes
+ fi])
+ ac_gcc_accepts_std="$ac_cv_gcc_accepts_std"
+ fi
+])
+
+AC_DEFUN(AC_NO_CPLUSPLUS_COMMENTS_IN_C_CODE,
+ [if test -n "$GCC"; then
+ AC_GCC_ACCEPTS_STD
+ AC_MSG_RESULT(Disabling C++ comments in ANSI C code.)
+ #
+ # The reason that // comments are banned from xscreensaver is that gcc is
+ # basically the only compiler in the world that supports them in C code.
+ # All other vendors support them only in their C++ compilers, not in their
+ # ANSI C compilers. This means that it's a portability problem: every time
+ # these comments have snuck into the xscreensaver source code, I've gotten
+ # complaints about it the next day. So we turn off support for them in gcc
+ # as well to prevent them from accidentially slipping in.
+ #
+ if test "$ac_gcc_accepts_std" = yes ; then
+ #
+ # -std=c89 defines __STRICT_ANSI__, which we don't want.
+ # (That appears to be the only additional preprocessor symbol
+ # it defines, in addition to the syntax changes it makes.)
+ #
+ # -std=gnu89 is no good, because // comments were a GNU extension
+ # before they were in the ANSI C 99 spec... (gcc 2.96 permits //
+ # with -std=gnu89 but not with -std=c89.)
+ #
+ CC="$CC -std=c89 -U__STRICT_ANSI__"
+ else
+ # The old way:
+ CC="$CC -Wp,-lang-c89"
+ fi
+ fi
+])
+
+