]> www.ginac.de Git - cln.git/blob - m4/cc.m4
Avoid compiler warning about ignored 'flatten' attribute directive.
[cln.git] / m4 / cc.m4
1 dnl The CLN manual says that without CFLAGS or CXXFLAGS being set compilation
2 dnl will happen with -O.  However, AC_PROG_CC and AC_PROG_CXX set CFLAGS and
3 dnl CXXFLAGS to "-g -O2", which produces way too large binaries.
4
5
6 dnl Wrapper around AC_PROG_CC setting CFLAGS to plain "-O" as opposed to
7 dnl "-g -O2" for the GNU compiler (unless CFLAGS was set before).
8 AC_DEFUN([CL_PROG_CC],
9 [cl_test_CFLAGS=${CFLAGS+set}
10 # Make sure this macro does not come after AC_PROG_CC.
11 # Otherwise CFLAGS would already be set.
12 AC_BEFORE([$0],[AC_PROG_CC])dnl
13 AC_PROG_CC([$1])
14 if test "$cl_test_CFLAGS" != set && test "$ac_compiler_gnu" = yes; then
15     CFLAGS="-O"
16 fi
17 ])
18
19
20 dnl Wrapper around AC_PROG_CXX setting CXXFLAGS to plain "-O" as opposed to
21 dnl "-g -O2" for the GNU compiler (unless CXXFLAGS was set before).  Also
22 dnl emits a warning if G++ is used and optimization turned off.
23 AC_DEFUN([CL_PROG_CXX],
24 [cl_test_CXXFLAGS=${CXXFLAGS+set}
25 # Make sure this macro does not come after AC_PROG_CXX.
26 # Otherwise CXXFLAGS would already be set.
27 AC_BEFORE([$0],[AC_PROG_CXX])dnl
28 AC_PROG_CXX([$1])
29 if test "$ac_compiler_gnu" = yes; then
30   if test "$cl_test_CXXFLAGS" != set; then
31     # User has not set CXXFLAGS.
32     CXXFLAGS="-O"
33   else
34     # Warn if optimization has been turned off with GCC.
35     # Optimization is used for module ordering.
36     case $CXXFLAGS in
37       [ *\ -O | -O | -O\ * | *\ -O\ * | -O[!0]* | *\ -O[!0]*) ;; ]
38       *) AC_MSG_WARN([Optimization turned off. I recommend you unset CXXFLAGS.]);;
39     esac
40   fi
41 fi
42 ])
43
44
45 dnl Checks whether the stack can be marked nonexecutable by passing an option
46 dnl to the C-compiler when acting on .s files. Appends that option to ASFLAGS.
47 dnl This macro is adapted from one found in GLIBC-2.3.5.
48 AC_DEFUN([CL_AS_NOEXECSTACK],[
49 AC_REQUIRE([AC_PROG_CC])
50 AC_CACHE_CHECK([whether --noexecstack is desirable for .s files], cl_cv_as_noexecstack, [dnl
51   cat > conftest.c <<EOF
52 void foo() {}
53 EOF
54   if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS
55                      -S -o conftest.s conftest.c >/dev/null]) \
56      && grep -q .note.GNU-stack conftest.s \
57      && AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -Wa,--noexecstack
58                        -c -o conftest.o conftest.s >/dev/null])
59   then
60     cl_cv_as_noexecstack=yes
61   else
62     cl_cv_as_noexecstack=no
63   fi
64   rm -f conftest*])
65   if test "$cl_cv_as_noexecstack" = yes; then
66     ASMFLAGS="$ASMFLAGS -Wa,--noexecstack"
67   fi
68   AC_SUBST(ASMFLAGS)
69 ])
70
71
72 dnl Checks whether the compiler supports __attribute__((flatten)).
73 AC_DEFUN([CL_ATTRIBUTE_FLATTEN],[
74 AC_REQUIRE([AC_PROG_CXX])
75 AC_CACHE_CHECK([whether the compiler supports __attribute__((flatten))], cl_cv_have_attr_flatten, [dnl
76   cat > conftest.cc <<EOF
77 void f() __attribute__((flatten));
78 EOF
79 AC_TRY_COMMAND(${CXX-g++} $CXXFLAGS -c conftest.cc >/dev/null 2>conftest.out)
80 if grep -i "warning" conftest.out > /dev/null; then
81   cl_cv_have_attr_flatten=no
82 else
83   cl_cv_have_attr_flatten=yes
84 fi
85 rm -f conftest*
86 ])
87 if test $cl_cv_have_attr_flatten = yes; then
88   AC_DEFINE(CL_HAVE_ATTRIBUTE_FLATTEN)
89 fi
90 ])