Merged eb/gcell-wip2 rev 10130:10152 into trunk.
[debian/gnuradio] / config / lf_warnings.m4
1 dnl Copyright (C) 1988 Eleftherios Gkioulekas <lf@amath.washington.edu>
2 dnl  
3 dnl This program is free software; you can redistribute it and/or modify
4 dnl it under the terms of the GNU General Public License as published by
5 dnl the Free Software Foundation; either version 3 of the License, or
6 dnl (at your option) any later version.
7 dnl 
8 dnl This program is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 dnl GNU General Public License for more details.
12 dnl 
13 dnl You should have received a copy of the GNU General Public License
14 dnl along with this program; if not, write to the Free Software 
15 dnl Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301, USA.
16 dnl 
17 dnl As a special exception to the GNU General Public License, if you 
18 dnl distribute this file as part of a program that contains a configuration 
19 dnl script generated by Autoconf, you may include it under the same 
20 dnl distribution terms that you use for the rest of that program.
21
22 # --------------------------------------------------------------------------
23 # Check whether the C++ compiler accepts a certain flag
24 # If it does it adds the flag to CXXFLAGS
25 # If it does not then it returns an error to lf_ok
26 # Usage:
27 #   LF_CHECK_CXX_FLAG(-flag1 -flag2 -flag3 ...)
28 # -------------------------------------------------------------------------
29
30 AC_DEFUN([LF_CHECK_CXX_FLAG],[
31   echo 'void f(){}' > conftest.cc
32   for i in $1
33   do
34     AC_MSG_CHECKING([whether $CXX accepts $i])
35     if test -z "`${CXX} $i -c conftest.cc 2>&1`"
36     then
37       CXXFLAGS="${CXXFLAGS} $i"
38       AC_MSG_RESULT(yes)
39     else
40       AC_MSG_RESULT(no)
41     fi
42   done
43   rm -f conftest.cc conftest.o
44 ])
45
46 # --------------------------------------------------------------------------
47 # Check whether the C compiler accepts a certain flag
48 # If it does it adds the flag to CFLAGS
49 # If it does not then it returns an error to lf_ok
50 # Usage:
51 #  LF_CHECK_CC_FLAG(-flag1 -flag2 -flag3 ...)
52 # -------------------------------------------------------------------------
53
54 AC_DEFUN([LF_CHECK_CC_FLAG],[
55   echo 'void f(){}' > conftest.c
56   for i in $1
57   do
58     AC_MSG_CHECKING([whether $CC accepts $i])
59     if test -z "`${CC} $i -c conftest.c 2>&1`"
60     then
61       CFLAGS="${CFLAGS} $i"
62       AC_MSG_RESULT(yes)
63     else
64       AC_MSG_RESULT(no)
65     fi
66   done
67   rm -f conftest.c conftest.o
68 ])
69
70 # --------------------------------------------------------------------------
71 # Check whether the Fortran compiler accepts a certain flag
72 # If it does it adds the flag to FFLAGS
73 # If it does not then it returns an error to lf_ok
74 # Usage:
75 #  LF_CHECK_F77_FLAG(-flag1 -flag2 -flag3 ...)
76 # -------------------------------------------------------------------------
77
78 AC_DEFUN([LF_CHECK_F77_FLAG],[
79   cat << EOF > conftest.f
80 c....:++++++++++++++++++++++++
81       PROGRAM MAIN
82       PRINT*,'Hello World!'
83       END
84 EOF
85   for i in $1
86   do
87     AC_MSG_CHECKING([whether $F77 accepts $i])
88     if test -z "`${F77} $i -c conftest.f 2>&1`"
89     then
90       FFLAGS="${FFLAGS} $i"
91       AC_MSG_RESULT(yes)  
92     else
93       AC_MSG_RESULT(no)
94     fi
95   done
96   rm -f conftest.f conftest.o
97 ])
98
99 # ----------------------------------------------------------------------
100 # Enable compiler warnings.  Conditionally enable -Werror.
101 # Call this command AFTER you have configured ALL your
102 # compilers. 
103 # ----------------------------------------------------------------------
104
105 AC_DEFUN([LF_SET_WARNINGS],[
106   lf_warnings_as_errors=""
107   AC_ARG_ENABLE([warnings-as-errors],
108     AC_HELP_STRING([--enable-warnings-as-errors], [Treat compiler warnings as errors (no)]),
109     [case "$enableval" in 
110       (no) ;;
111       (yes) lf_warnings_as_errors="-Werror" ;;
112       (*) AC_MSG_ERROR([Invalid argument ($enableval) to --enable-warnings-as-errors]) ;;
113      esac],
114     [])
115      
116   dnl Warnings for the two main compilers
117   dnl add -Wextra when you're got time to fix a bunch of them ;-)
118   cc_warning_flags="-Wall -Werror-implicit-function-declaration $lf_warnings_as_errors"
119   cxx_warning_flags="-Wall -Woverloaded-virtual $lf_warnings_as_errors"
120   if test -n "${CC}"
121   then
122     LF_CHECK_CC_FLAG($cc_warning_flags)
123   fi
124   if test -n "${CXX}" 
125   then
126     LF_CHECK_CXX_FLAG($cxx_warning_flags)
127   fi
128 ])