2 ## debug.m4 -- massage compiler flags for debugging/optimisation
4 ## Copyright (C) 2000-2001, 2003, 2005-2007, 2010, 2013 Free Software
6 ## Copyright (C) 1999-2000 Ralf S. Engelschall
7 ## Written by <rse@engelschall.com>
8 ## Modified for M4 by Gary V. Vaughan <gary@gnu.org>
10 ## This file is part of GNU M4.
12 ## GNU M4 is free software: you can redistribute it and/or modify
13 ## it under the terms of the GNU General Public License as published by
14 ## the Free Software Foundation, either version 3 of the License, or
15 ## (at your option) any later version.
17 ## GNU M4 is distributed in the hope that it will be useful,
18 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ## GNU General Public License for more details.
22 ## You should have received a copy of the GNU General Public License
23 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
30 AC_DEFUN([M4_CHECK_DEBUGGING],
31 [AC_REQUIRE([AC_PROG_CC])
32 AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug],
33 [build for debugging [default=no]])])
34 AC_MSG_CHECKING([for compilation debug mode])
35 AC_MSG_RESULT([${enable_debug-no}])
41 compiler="${compiler-[$]2}"
42 test -n "$rm" || rm="rm -f"
44 if test "X$enable_debug" = Xyes; then
46 AC_DEFINE([DEBUG], [1],
47 [Define this to enable additional runtime debugging])
48 M4_default_preload="m4 traditional gnu load \
49 import modtest mpeval shadow stdlib time"
50 if test "$GCC" = yes; then
52 *-O* ) CFLAGS=`echo $CFLAGS | $SED 's/-O[[^ ]]* / /;s/-O[[^ ]]*$//'` ;;
56 * ) AC_LIBTOOL_COMPILER_OPTION([if $compiler accepts -ggdb3],
57 [M4_cv_prog_compiler_ggdb3],
58 [-ggdb3 -c conftest.$ac_ext], [],
59 [CFLAGS="$CFLAGS -ggdb3"],
60 [CFLAGS="$CFLAGS -g"])
63 CFLAGS="$CFLAGS -Wall"
64 WMORE="-Wshadow -Wpointer-arith -Wcast-align -Wnested-externs"
65 WMORE="$WMORE -Wmissing-prototypes -Wmissing-declarations -Winline"
66 AC_LIBTOOL_COMPILER_OPTION([if $compiler accepts $WMORE],
67 [M4_cv_prog_compiler_warning_flags],
68 [$WMORE -c conftest.$ac_ext], [],
69 [CFLAGS="$CFLAGS $WMORE"])
71 AC_LIBTOOL_COMPILER_OPTION([if $compiler accepts -Wno-long-long],
72 [M4_cv_prog_compiler_wnolonglong],
73 [-Wno-long-long -c conftest.$ac_ext], [],
74 [CFLAGS="$CFLAGS -Wno-long-long"])
78 * ) CFLAGS="$CFLAGS -g" ;;
84 *-g* ) CFLAGS=`echo "$CFLAGS" |\
85 $SED -e 's/ -g / /g;s/ -g$//;s/^-g //g;s/^-g$//'`
89 *-g* ) CXXFLAGS=`echo "$CXXFLAGS" |\
90 $SED -e 's/ -g / /g;s/ -g$//;s/^-g //g;s/^-g$//'`
94 ])# M4_CHECK_DEBUGGING