monotone

monotone Mtn Source Tree

Root/m4/prog_cxx_warnings.m4

1dnl @synopsis AC_PROG_CXX_WARNINGS([ANSI])
2dnl
3dnl Enables a reasonable set of warnings for the C compiler.
4dnl Optionally, if the first argument is nonempty, turns on flags which
5dnl enforce and/or enable proper ANSI C if such are known with the
6dnl compiler used.
7dnl
8dnl Currently this macro knows about GCC, Solaris C compiler, Digital
9dnl Unix C compiler, C for AIX Compiler, HP-UX C compiler, IRIX C
10dnl compiler, NEC SX-5 (Super-UX 10) C compiler, and Cray J90 (Unicos
11dnl 10.0.0.8) C compiler.
12dnl
13dnl for C++, some of them might not work, esp. because I didn't adapt
14dnl the strings to compare compiler type. known to work are:
15dnl GCC, Sun Studio
16dnl
17dnl based on VL_PROG_CC_WARNINGS by Ville Laurikari <vl@iki.fi>
18dnl
19dnl WORK IN PROGRESS: please don't release separately yet.
20dnl patches welcome!
21dnl
22dnl @category Cxx
23dnl @author Patrick Mauritz <oxygene@studentenbude.ath.cx>
24dnl @version 2005-08-15
25dnl @license AllPermissive
26
27AC_DEFUN([AC_PROG_CXX_WARNINGS], [
28 ansi=$1
29 if test -z "$ansi"; then
30 msg="for C++ compiler warning flags"
31 else
32 msg="for C++ compiler warning and ANSI conformance flags"
33 fi
34 AC_CACHE_CHECK($msg, ac_cv_prog_cxx_warnings, [
35 if test -n "$CXX"; then
36 cat > conftest.c <<EOF
37int main(int argc, char **argv) { return 0; }
38EOF
39
40 dnl GCC
41 if test "$GXX" = "yes"; then
42 if test -z "$ansi"; then
43 ac_cv_prog_cxx_warnings="-Wall -W -Wno-unused"
44 else
45 ac_cv_prog_cxx_warnings="-Wall -W -Wno-unused -ansi -pedantic"
46 fi
47
48 dnl Most compilers print some kind of a version string with some command
49 dnl line options (often "-V"). The version string should be checked
50 dnl before doing a test compilation run with compiler-specific flags.
51 dnl This is because some compilers (like the Cray compiler) only
52 dnl produce a warning message for unknown flags instead of returning
53 dnl an error, resulting in a false positive. Also, compilers may do
54 dnl erratic things when invoked with flags meant for a different
55 dnl compiler.
56
57 dnl Solaris C compiler (WorkShop)
58 elif $CXX -V 2>&1 | grep -i "WorkShop" > /dev/null 2>&1 &&
59 $CXX -c -v -Xc conftest.c > /dev/null 2>&1 &&
60 test -f conftest.o; then
61 if test -z "$ansi"; then
62 ac_cv_prog_cxx_warnings="-v"
63 else
64 ac_cv_prog_cxx_warnings="-v -Xc"
65 fi
66
67 dnl Solaris C compiler (Studio)
68 dnl has warnings by default. not sure if additional warnings (+w)
69 dnl are really useful
70 elif $CXX -V 2>&1 | grep -i "SUN C++ 5" > /dev/null 2>&1 &&
71 $CXX -c -v -Xc conftest.c > /dev/null 2>&1 &&
72 test -f conftest.o; then
73 if test -z "$ansi"; then
74 ac_cv_prog_cxx_warnings=""
75 else
76 ac_cv_prog_cxx_warnings=""
77 fi
78
79 dnl Digital Unix C compiler
80 elif $CXX -V 2>&1 | grep -i "Digital UNIX Compiler" > /dev/null 2>&1 &&
81 $CXX -c -verbose -w0 -warnprotos -std1 conftest.c > /dev/null 2>&1 &&
82 test -f conftest.o; then
83 if test -z "$ansi"; then
84 ac_cv_prog_cxx_warnings="-verbose -w0 -warnprotos"
85 else
86 ac_cv_prog_cxx_warnings="-verbose -w0 -warnprotos -std1"
87 fi
88
89 dnl C for AIX Compiler
90 elif $CXX 2>&1 | grep -i "C for AIX Compiler" > /dev/null 2>&1 &&
91 $CXX -c -qlanglvl=ansi -qinfo=all conftest.c > /dev/null 2>&1 &&
92 test -f conftest.o; then
93 if test -z "$ansi"; then
94 ac_cv_prog_cxx_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd"
95 else
96 ac_cv_prog_cxx_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd -qlanglvl=ansi"
97 fi
98
99 dnl IRIX C compiler
100 elif $CXX -version 2>&1 | grep -i "MIPSpro Compilers" > /dev/null 2>&1 &&
101 $CXX -c -fullwarn -ansi -ansiE conftest.c > /dev/null 2>&1 &&
102 test -f conftest.o; then
103 if test -z "$ansi"; then
104 ac_cv_prog_cxx_warnings="-fullwarn"
105 else
106 ac_cv_prog_cxx_warnings="-fullwarn -ansi -ansiE"
107 fi
108
109 dnl HP-UX C compiler
110 elif what $CXX 2>&1 | grep -i "HP C Compiler" > /dev/null 2>&1 &&
111 $CXX -c -Aa +w1 conftest.c > /dev/null 2>&1 &&
112 test -f conftest.o; then
113 if test -z "$ansi"; then
114 ac_cv_prog_cxx_warnings="+w1"
115 else
116 ac_cv_prog_cxx_warnings="+w1 -Aa"
117 fi
118
119 dnl The NEC SX-5 (Super-UX 10) C compiler
120 elif $CXX -V 2>&1 | grep "/SX" > /dev/null 2>&1 &&
121 $CXX -c -pvctl[,]fullmsg -Xc conftest.c > /dev/null 2>&1 &&
122 test -f conftest.o; then
123 if test -z "$ansi"; then
124 ac_cv_prog_cxx_warnings="-pvctl[,]fullmsg"
125 else
126 ac_cv_prog_cxx_warnings="-pvctl[,]fullmsg -Xc"
127 fi
128
129 dnl The Cray C compiler (Unicos)
130 elif $CXX -V 2>&1 | grep -i "Cray" > /dev/null 2>&1 &&
131 $CXX -c -h msglevel 2 conftest.c > /dev/null 2>&1 &&
132 test -f conftest.o; then
133 if test -z "$ansi"; then
134 ac_cv_prog_cxx_warnings="-h msglevel 2"
135 else
136 ac_cv_prog_cxx_warnings="-h msglevel 2 -h conform"
137 fi
138
139 fi
140 rm -f conftest.*
141 fi
142 if test -z "$ac_cv_prog_cxx_warnings"; then
143 ac_cv_prog_cxx_warnings="unknown"
144 fi
145 ])
146 if test x"$ac_cv_prog_cxx_warnings" != xunknown; then
147 CXXFLAGS="$CXXFLAGS $ac_cv_prog_cxx_warnings"
148 fi
149])

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status