added the better debug option logic from curl by adding acinclude.m4 to the
[platform/upstream/c-ares.git] / acinclude.m4
1
2 dnl We create a function for detecting which compiler we use and then set as
3 dnl pendantic compiler options as possible for that particular compiler. The
4 dnl options are only used for debug-builds.
5
6 dnl This is a copy of the original found in curl's configure script. Don't
7 dnl modify this one, edit the one in curl and copy it back here when that one
8 dnl is changed.
9
10 AC_DEFUN([CURL_CC_DEBUG_OPTS],
11 [
12     if test "$GCC" = "yes"; then
13
14        dnl figure out gcc version!
15        AC_MSG_CHECKING([gcc version])
16        gccver=`$CC -dumpversion`
17        num1=`echo $gccver | cut -d . -f1`
18        num2=`echo $gccver | cut -d . -f2`
19        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
20        AC_MSG_RESULT($gccver)
21
22        AC_MSG_CHECKING([if this is icc in disguise])
23        AC_EGREP_CPP([^__ICC], [__ICC],
24          dnl action if the text is found, this it has not been replaced by the
25          dnl cpp
26          [ICC="no"]
27          AC_MSG_RESULT([no]),
28          dnl the text was not found, it was replaced by the cpp
29          [ICC="yes"]
30          AC_MSG_RESULT([yes])
31        )
32
33        if test "$ICC" = "yes"; then
34          dnl this is icc, not gcc.
35
36          dnl Warning 279 warns on static conditions in while expressions,
37          dnl ignore that.
38
39          WARN="-wd279"
40
41          if test "$gccnum" -gt "600"; then
42             dnl icc 6.0 and older doesn't have the -Wall flag, although it does
43             dnl have -wd<n>
44             WARN="-Wall $WARN"
45          fi
46        else dnl $ICC = yes
47          dnl 
48          WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
49
50          dnl -Wcast-align is a bit too annoying ;-)
51
52          if test "$gccnum" -ge "296"; then
53            dnl gcc 2.96 or later
54            WARN="$WARN -Wfloat-equal"
55
56            if test "$gccnum" -gt "296"; then
57              dnl this option does not exist in 2.96
58              WARN="$WARN -Wno-format-nonliteral"
59            fi
60
61            dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
62            dnl on i686-Linux as it gives us heaps with false positives
63            if test "$gccnum" -ge "303"; then
64              dnl gcc 3.3 and later
65              WARN="$WARN -Wendif-labels -Wstrict-prototypes"
66            fi
67          fi
68
69          for flag in $CPPFLAGS; do
70            case "$flag" in
71             -I*)
72               dnl include path
73               add=`echo $flag | sed 's/^-I/-isystem /g'`
74               WARN="$WARN $add"
75               ;;
76            esac
77          done
78
79        fi dnl $ICC = no
80
81        CFLAGS="$CFLAGS $WARN"
82
83     fi dnl $GCC = yes
84
85     dnl strip off optimizer flags
86     NEWFLAGS=""
87     for flag in $CFLAGS; do
88       case "$flag" in
89       -O*)
90         dnl echo "cut off $flag"
91         ;;
92       *)
93         NEWFLAGS="$NEWFLAGS $flag"
94         ;;
95       esac
96     done
97     CFLAGS=$NEWFLAGS
98
99 ]) dnl end of AC_DEFUN()
100