another cc-stdc bug fix
[platform/upstream/automake.git] / m4 / ccstdc.m4
1 ## ----------------------------------------- ##
2 ## ANSIfy the C compiler whenever possible.  ##
3 ## From Franc,ois Pinard                     ##
4 ## ----------------------------------------- ##
5
6 # serial 1
7
8 # @defmac AC_PROG_CC_STDC
9 # @maindex PROG_CC_STDC
10 # @ovindex CC
11 # If the C compiler in not in ANSI C mode by default, try to add an option
12 # to output variable @code{CC} to make it so.  This macro tries various
13 # options that select ANSI C on some system or another.  It considers the
14 # compiler to be in ANSI C mode if it handles function prototypes correctly.
15 #
16 # If you use this macro, you should check after calling it whether the C
17 # compiler has been set to accept ANSI C; if not, the shell variable
18 # @code{am_cv_prog_cc_stdc} is set to @samp{no}.  If you wrote your source
19 # code in ANSI C, you can make an un-ANSIfied copy of it by using the
20 # program @code{ansi2knr}, which comes with Ghostscript.
21 # @end defmac
22
23 AC_DEFUN(AM_PROG_CC_STDC,
24 [AC_REQUIRE([AC_PROG_CC])
25 AC_BEFORE([$0], [AC_C_INLINE])
26 AC_BEFORE([$0], [AC_C_CONST])
27 dnl Force this before AC_PROG_CPP.  Some cpp's, eg on HPUX, require
28 dnl a magic option to avoid problems with ANSI preprocessor commands
29 dnl like #elif.
30 AC_BEFORE([$0], [AC_PROG_CPP])
31 AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C)
32 AC_CACHE_VAL(am_cv_prog_cc_stdc,
33 [am_cv_prog_cc_stdc=no
34 ac_save_CC="$CC"
35 # Don't try gcc -ansi; that turns off useful extensions and
36 # breaks some systems' header files.
37 # AIX                   -qlanglvl=ansi
38 # Ultrix and OSF/1      -std1
39 # HP-UX                 -Aa -D_HPUX_SOURCE
40 # SVR4                  -Xc -D__EXTENSIONS__
41 for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
42 do
43   CC="$ac_save_CC $ac_arg"
44   AC_TRY_COMPILE(
45 [#include <stdarg.h>
46 #include <stdio.h>
47 #include <sys/types.h>
48 #include <sys/stat.h>
49 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
50 struct buf { int x; };
51 FILE * (*rcsopen) (struct buf *, struct stat *, int);
52 static char *e (p, i)
53      char **p;
54      int i;
55 {
56   return p[i];
57 }
58 static char *f (char * (*g) (char **, int), char **p, ...)
59 {
60   char *s;
61   va_list v;
62   va_start (v,p);
63   s = g (p, va_arg (v,int));
64   va_end (v);
65   return s;
66 }
67 int test (int i, double x);
68 struct s1 {int (*f) (int a);};
69 struct s2 {int (*f) (double a);};
70 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
71 int argc;
72 char **argv;
73 ], [
74 return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
75 ],
76 [am_cv_prog_cc_stdc="$ac_arg"; break])
77 done
78 CC="$ac_save_CC"
79 ])
80 if test -z "$am_cv_prog_cc_stdc"; then
81   AC_MSG_RESULT([none needed])
82 else
83   AC_MSG_RESULT($am_cv_prog_cc_stdc)
84 fi
85 case "x$am_cv_prog_cc_stdc" in
86   x|xno) ;;
87   *) CC="$CC $am_cv_prog_cc_stdc" ;;
88 esac
89 ])