http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=84416
[m4/ericb.git] / acm4 / debug.m4
blob83d2ae558cc7efba2b84f73bc41870298ccecd81
1 ##                                                           -*- Autoconf -*-
2 ## debug.m4 -- massage compiler flags for debugging/optimisation
3 ##
4 ## Copyright (C) 1999-2000 Ralf S. Engelschall
5 ## Written by <rse@engelschall.com>
6 ## Modified for M4 by Gary V. Vaughan <gary@gnu.org>
7 ##
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 2 of the License, or
11 ## (at your option) any later version.
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ## GNU General Public License for more details.
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; see the file COPYING.  If not, write to
20 ## the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ## Boston, MA 02110-1301, USA.
23 # serial 7
25 # m4_CHECK_DEBUGGING
26 # ------------------
27 # Debugging Support
28 AC_DEFUN([m4_CHECK_DEBUGGING],
29 [AC_REQUIRE([AC_PROG_CC])
30 AC_ARG_ENABLE([debug], [AC_HELP_STRING([--enable-debug],
31                            [build for debugging [default=no]])])
32 AC_MSG_CHECKING(for compilation debug mode)
33 AC_MSG_RESULT([${enable_debug-no}])
35 set dummy $CC
36 compiler="${compiler-[$]2}"
37 test -n "$rm" || rm="rm -f"
39 if test "X$enable_debug" = Xyes; then
40   AC_DISABLE_SHARED
41   AC_DEFINE([DEBUG], 1,
42       [Define this to enable additional runtime debugging])
43   if test "$GCC" = yes; then
44     case "$CFLAGS" in
45       *-O* ) CFLAGS=`echo $CFLAGS | $SED 's/-O[[^ ]]* / /;s/-O[[^ ]]*$//'` ;;
46     esac
47     case "$CFLAGS" in
48         *-g* ) ;;
49          * ) AC_LIBTOOL_COMPILER_OPTION([if $compiler accepts -ggdb3],
50                  [m4_cv_prog_compiler_ggdb3],
51                  [-ggdb3 -c conftest.$ac_ext], [],
52                  [CFLAGS="$CFLAGS -ggdb3"],
53                [CFLAGS="$CFLAGS -g"])
54              ;;
55     esac
56     CFLAGS="$CFLAGS -Wall"
57     WMORE="-Wshadow -Wpointer-arith -Wcast-align -Wnested-externs"
58     WMORE="$WMORE -Wmissing-prototypes -Wmissing-declarations -Winline"
59     AC_LIBTOOL_COMPILER_OPTION([if $compiler accepts $WMORE],
60         [m4_cv_prog_compiler_warning_flags],
61         [$WMORE -c conftest.$ac_ext], [],
62         [CFLAGS="$CFLAGS $WMORE"])
64     AC_LIBTOOL_COMPILER_OPTION([if $compiler accepts -Wno-long-long],
65         [m4_cv_prog_compiler_wnolonglong],
66         [-Wno-long-long -c conftest.$ac_ext], [],
67         [CFLAGS="$CFLAGS -Wno-long-long"])
68   else
69     case "$CFLAGS" in
70         *-g* ) ;;
71            * ) CFLAGS="$CFLAGS -g" ;;
72     esac
73   fi
74 else
75   AC_ENABLE_SHARED
76   case "$CFLAGS" in
77     *-g* ) CFLAGS=`echo "$CFLAGS" |\
78                $SED -e 's/ -g / /g;s/ -g$//;s/^-g //g;s/^-g$//'`
79            ;;
80   esac
81   case "$CXXFLAGS" in
82     *-g* ) CXXFLAGS=`echo "$CXXFLAGS" |\
83                $SED -e 's/ -g / /g;s/ -g$//;s/^-g //g;s/^-g$//'`
84            ;;
85   esac
87 ])# m4_CHECK_DEBUGGING