* ChangeLog, ChangeLog.1996, ChangeLog.1998, ChangeLog.2000,
[platform/upstream/automake.git] / m4 / ccstdc.m4
1 ## ----------------------------------------- ##
2 ## ANSIfy the C compiler whenever possible.  ##
3 ## From Franc,ois Pinard                     ##
4 ## ----------------------------------------- ##
5
6 # Copyright 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # 02111-1307, USA.
22
23 # serial 1
24
25 # @defmac AC_PROG_CC_STDC
26 # @maindex PROG_CC_STDC
27 # @ovindex CC
28 # If the C compiler in not in ANSI C mode by default, try to add an option
29 # to output variable @code{CC} to make it so.  This macro tries various
30 # options that select ANSI C on some system or another.  It considers the
31 # compiler to be in ANSI C mode if it handles function prototypes correctly.
32 #
33 # If you use this macro, you should check after calling it whether the C
34 # compiler has been set to accept ANSI C; if not, the shell variable
35 # @code{am_cv_prog_cc_stdc} is set to @samp{no}.  If you wrote your source
36 # code in ANSI C, you can make an un-ANSIfied copy of it by using the
37 # program @code{ansi2knr}, which comes with Ghostscript.
38 # @end defmac
39
40 AC_DEFUN([AM_PROG_CC_STDC],
41 [AC_REQUIRE([AC_PROG_CC])
42 AC_BEFORE([$0], [AC_C_INLINE])
43 AC_BEFORE([$0], [AC_C_CONST])
44 dnl Force this before AC_PROG_CPP.  Some cpp's, eg on HPUX, require
45 dnl a magic option to avoid problems with ANSI preprocessor commands
46 dnl like #elif.
47 dnl FIXME: can't do this because then AC_AIX won't work due to a
48 dnl circular dependency.
49 dnl AC_BEFORE([$0], [AC_PROG_CPP])
50 AC_MSG_CHECKING([for ${CC-cc} option to accept ANSI C])
51 AC_CACHE_VAL(am_cv_prog_cc_stdc,
52 [am_cv_prog_cc_stdc=no
53 ac_save_CC="$CC"
54 # Don't try gcc -ansi; that turns off useful extensions and
55 # breaks some systems' header files.
56 # AIX                   -qlanglvl=ansi
57 # Ultrix and OSF/1      -std1
58 # HP-UX 10.20 and later -Ae
59 # HP-UX older versions  -Aa -D_HPUX_SOURCE
60 # SVR4                  -Xc -D__EXTENSIONS__
61 for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
62 do
63   CC="$ac_save_CC $ac_arg"
64   AC_TRY_COMPILE(
65 [#include <stdarg.h>
66 #include <stdio.h>
67 #include <sys/types.h>
68 #include <sys/stat.h>
69 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
70 struct buf { int x; };
71 FILE * (*rcsopen) (struct buf *, struct stat *, int);
72 static char *e (p, i)
73      char **p;
74      int i;
75 {
76   return p[i];
77 }
78 static char *f (char * (*g) (char **, int), char **p, ...)
79 {
80   char *s;
81   va_list v;
82   va_start (v,p);
83   s = g (p, va_arg (v,int));
84   va_end (v);
85   return s;
86 }
87 int test (int i, double x);
88 struct s1 {int (*f) (int a);};
89 struct s2 {int (*f) (double a);};
90 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
91 int argc;
92 char **argv;
93 ], [
94 return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
95 ],
96 [am_cv_prog_cc_stdc="$ac_arg"; break])
97 done
98 CC="$ac_save_CC"
99 ])
100 if test -z "$am_cv_prog_cc_stdc"; then
101   AC_MSG_RESULT([none needed])
102 else
103   AC_MSG_RESULT([$am_cv_prog_cc_stdc])
104 fi
105 case "x$am_cv_prog_cc_stdc" in
106   x|xno) ;;
107   *) CC="$CC $am_cv_prog_cc_stdc" ;;
108 esac
109 ])