This commit was generated by cvs2svn to compensate for changes in r120,
[util-vserver.git] / m4 / ensc_cflags.m4
1 dnl $Id: ensc_cflags.m4,v 1.1.4.1 2004/01/26 18:21:28 ensc Exp $
2
3 dnl Copyright (C) 2002 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 dnl  
5 dnl This program is free software; you can redistribute it and/or modify
6 dnl it under the terms of the GNU General Public License as published by
7 dnl the Free Software Foundation; version 2 of the License.
8 dnl  
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl  
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program; if not, write to the Free Software
16 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 AC_DEFUN([__ENSC_CHECK_WARNFLAGS],
19 [
20         warn_flags="-Werror -W"
21         AC_MSG_CHECKING([whether the $1-compiler accepts ${warn_flags}])
22         AC_LANG_PUSH($1)
23         old_CFLAGS="${$3}"
24         $3="$warn_flags"
25         AC_TRY_COMPILE([inline static void f(){}],
26                        [],
27                        [ensc_sys_compilerwarnflags_$2=${warn_flags}],
28                        [ensc_sys_compilerwarnflags_$2=])
29         AC_LANG_POP($1)
30         $3="$old_CFLAGS"
31
32         if test x"${ensc_sys_compilerwarnflags_$2}" = x; then
33                 AC_MSG_RESULT([no])
34         else
35                 AC_MSG_RESULT([yes])
36         fi
37 ])
38
39 AC_DEFUN([__ENSC_CHECK_WARNFLAGS_C],
40 [
41         __ENSC_CHECK_WARNFLAGS(C, C, CFLAGS)
42 ])
43
44 AC_DEFUN([__ENSC_CHECK_WARNFLAGS_CXX],
45 [
46         __ENSC_CHECK_WARNFLAGS(C++, CXX, CXXFLAGS)
47 ])
48
49
50 # --------------------------------------------------------------------------
51 # Check whether the C++ compiler accepts a certain flag
52 # If it does it adds the flag to CXXFLAGS
53 # If it does not then it returns an error to lf_ok
54 # Usage:
55 #   ENSC_CHECK_CXX_FLAG(-flag1 -flag2 -flag3 ...)
56 # -------------------------------------------------------------------------
57
58 AC_DEFUN([ENSC_CHECK_CXX_FLAG],
59 [
60         AC_REQUIRE([__ENSC_CHECK_WARNFLAGS_CXX])
61
62   echo 'void f(){}' > conftest.cc
63   for i in $1
64   do
65     AC_MSG_CHECKING([whether $CXX accepts $i])
66     if test -z "`${CXX} ${ensc_sys_compilerwarnflags_CXX} $i -c conftest.cc 2>&1`"
67     then
68       CXXFLAGS="${CXXFLAGS} $i"
69       AC_MSG_RESULT(yes)
70     else
71       AC_MSG_RESULT(no)
72     fi
73   done
74   rm -f conftest.cc conftest.o
75 ])
76
77 # --------------------------------------------------------------------------
78 # Check whether the C compiler accepts a certain flag
79 # If it does it adds the flag to CFLAGS
80 # If it does not then it returns an error to lf_ok
81 # Usage:
82 #  ENSC_CHECK_CC_FLAG(-flag1 -flag2 -flag3 ...)
83 # -------------------------------------------------------------------------
84
85 AC_DEFUN([ENSC_CHECK_CC_FLAG],[
86         AC_REQUIRE([__ENSC_CHECK_WARNFLAGS_C])
87
88 echo 'void f(){}' > conftest.c
89   for i in $1
90   do
91     AC_MSG_CHECKING([whether $CC accepts $i])
92     if test -z "`${CC} ${ensc_sys_compilerwarnflags_C} $i -c conftest.c 2>&1`"
93     then
94       CFLAGS="${CFLAGS} $i"
95       AC_MSG_RESULT(yes)
96     else
97       AC_MSG_RESULT(no)
98     fi
99   done
100   rm -f conftest.c conftest.o
101 ])
102
103 AC_DEFUN([ENSC_CHECK_DEFAULT_FLAG],
104 [
105         if test x"${ensc_sys_default_flag}" = x; then
106                 ENSC_CHECK_CC_FLAG([-fmessage-length=0])
107                 ENSC_CHECK_CXX_FLAG([-fmessage-length=0])
108
109                 ensc_sys_default_flag=set
110         fi
111 ])