1dnl @synopsis VL_PROG_CC_WARNINGS([ANSI])
2dnl
3dnl Enables a high level of warnings for the C compiler.  Optionally,
4dnl if the first argument is nonempty, turns on flags which enforce and/or
5dnl enable proper ANSI C if such are known with the compiler used.
6dnl
7dnl Currently this macro knows about GCC, Solaris C compiler,
8dnl Digital Unix C compiler, C for AIX Compiler, HP-UX C compiler,
9dnl IRIX C compiler, NEC SX-5 (Super-UX 10) C compiler, and Cray J90
10dnl (Unicos 10.0.0.8) C compiler.
11dnl
12dnl @version 1.2
13dnl @author Ville Laurikari <vl@iki.fi>
14dnl
15AC_DEFUN([VL_PROG_CC_WARNINGS], [
16  # Don't override if CFLAGS was already set.
17  if test -z "$ac_env_CFLAGS_set"; then
18    ansi=$1
19    if test -z "$ansi"; then
20      msg="for C compiler warning flags"
21    else
22      msg="for C compiler warning and ANSI conformance flags"
23    fi
24    AC_CACHE_CHECK($msg, vl_cv_prog_cc_warnings, [
25      if test -n "$CC"; then
26        cat > conftest.c <<EOF
27int main(int argc, char **argv) { return 0; }
28EOF
29
30        dnl GCC
31        if test "$GCC" = "yes"; then
32          if test -z "$ansi"; then
33            vl_cv_prog_cc_warnings="-Wall"
34          else
35            vl_cv_prog_cc_warnings="-Wall -ansi -pedantic"
36          fi
37
38        dnl Most compilers print some kind of a version string with some command
39        dnl line options (often "-V").  The version string should be checked
40        dnl before doing a test compilation run with compiler-specific flags.
41        dnl This is because some compilers (like the Cray compiler) only
42        dnl produce a warning message for unknown flags instead of returning
43        dnl an error, resulting in a false positive.  Also, compilers may do
44        dnl erratic things when invoked with flags meant for a different
45        dnl compiler.
46
47        dnl Solaris C compiler
48        elif $CC -V 2>&1 | grep -i "WorkShop" > /dev/null 2>&1 &&
49             $CC -c -v -Xc conftest.c > /dev/null 2>&1 &&
50             test -f conftest.o; then
51          if test -z "$ansi"; then
52            vl_cv_prog_cc_warnings="-v"
53          else
54            vl_cv_prog_cc_warnings="-v -Xc"
55          fi
56
57        dnl Compaq (formerly Digital Unix) C compiler
58        elif ($CC -V 2>&1 | grep -i "Digital UNIX Compiler" > /dev/null 2>&1 ||
59              $CC -V 2>&1 | grep -i "Compaq C" > /dev/null 2>&1) &&
60             $CC -c -verbose -w0 -warnprotos -std1 conftest.c > /dev/null 2>&1 &&
61             test -f conftest.o; then
62          if test -z "$ansi"; then
63            vl_cv_prog_cc_warnings="-verbose -w0 -warnprotos"
64          else
65            vl_cv_prog_cc_warnings="-verbose -w0 -warnprotos -std1"
66          fi
67
68        dnl C for AIX Compiler
69        elif $CC 2>&1 | grep -i "C for AIX Compiler" > /dev/null 2>&1 &&
70	     $CC -c -qlanglvl=ansi -qinfo=all conftest.c > /dev/null 2>&1 &&
71             test -f conftest.o; then
72          if test -z "$ansi"; then
73            vl_cv_prog_cc_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd:nouni:nocnv"
74          else
75            vl_cv_prog_cc_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd:nouni:nocnv -qlanglvl=ansi"
76          fi
77
78        dnl IRIX C compiler
79        elif $CC -version 2>&1 | grep -i "MIPSpro Compilers" > /dev/null 2>&1 &&
80             $CC -c -fullwarn -ansi -ansiE conftest.c > /dev/null 2>&1 &&
81             test -f conftest.o; then
82          if test -z "$ansi"; then
83            vl_cv_prog_cc_warnings="-fullwarn"
84          else
85            vl_cv_prog_cc_warnings="-fullwarn -ansi -ansiE"
86          fi
87
88        dnl HP-UX C compiler
89        elif what $CC 2>&1 | grep -i "HP C Compiler" > /dev/null 2>&1 &&
90             $CC -c -Aa +w1 conftest.c > /dev/null 2>&1 &&
91             test -f conftest.o; then
92          if test -z "$ansi"; then
93            vl_cv_prog_cc_warnings="+w1"
94          else
95            vl_cv_prog_cc_warnings="+w1 -Aa"
96          fi
97
98        dnl The NEC SX-5 (Super-UX 10) C compiler
99        elif $CC -V 2>&1 | grep "/SX" > /dev/null 2>&1 &&
100             $CC -c -pvctl[,]fullmsg -Xc conftest.c > /dev/null 2>&1 &&
101             test -f conftest.o; then
102          if test -z "$ansi"; then
103            vl_cv_prog_cc_warnings="-pvctl[,]fullmsg"
104          else
105            vl_cv_prog_cc_warnings="-pvctl[,]fullmsg -Xc"
106          fi
107
108        dnl The Cray C compiler (Unicos)
109        elif $CC -V 2>&1 | grep -i "Cray" > /dev/null 2>&1 &&
110             $CC -c -h msglevel 2 conftest.c > /dev/null 2>&1 &&
111             test -f conftest.o; then
112          if test -z "$ansi"; then
113            vl_cv_prog_cc_warnings="-h msglevel 2"
114          else
115            vl_cv_prog_cc_warnings="-h msglevel 2 -h conform"
116          fi
117
118        fi
119        rm -f conftest.*
120      fi
121      if test -n "$vl_cv_prog_cc_warnings"; then
122        CFLAGS="$CFLAGS $vl_cv_prog_cc_warnings"
123      else
124        vl_cv_prog_cc_warnings="unknown"
125      fi
126    ])
127  fi
128])dnl
129