Imported Upstream version 3.0
[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 2 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 # Provide the configure script with an --with-warnings option that
101 # turns on warnings. Call this command AFTER you have configured ALL your
102 # compilers. 
103 # ----------------------------------------------------------------------
104
105 AC_DEFUN([LF_SET_WARNINGS],[
106   dnl Check for --with-warnings
107   AC_MSG_CHECKING([whether user wants warnings])
108   AC_ARG_WITH(warnings,
109               [  --with-warnings         Turn on warnings],
110               [ lf_warnings=yes ], [ lf_warnings=no ])
111   lf_warnings=yes # hard code for now -eb
112   AC_MSG_RESULT($lf_warnings)
113   
114   dnl Warnings for the two main compilers
115   cc_warning_flags="-Wall"
116   cxx_warning_flags="-Wall -Woverloaded-virtual"
117   if test $lf_warnings = yes
118   then
119     if test -n "${CC}"
120     then
121       LF_CHECK_CC_FLAG($cc_warning_flags)
122     fi
123     if test -n "${CXX}" 
124     then
125       LF_CHECK_CXX_FLAG($cxx_warning_flags)
126     fi
127   fi
128 ])