summaryrefslogtreecommitdiff
path: root/build-aux/m4/debug.m4
blob: 38f4fc6c208bcba732807d845ac830188d666826 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
##                                                           -*- Autoconf -*-
## debug.m4 -- massage compiler flags for debugging/optimisation
##
## Copyright (C) 2000-2001, 2003, 2005-2007, 2010, 2013-2014 Free
## Software Foundation, Inc.
## Copyright (C) 1999-2000 Ralf S. Engelschall
## Written by <rse@engelschall.com>
## Modified for M4 by Gary V. Vaughan <gary@gnu.org>
##
## This file is part of GNU M4.
##
## GNU M4 is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## GNU M4 is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.

# serial 9

# M4_CHECK_DEBUGGING
# ------------------
# Debugging Support
AC_DEFUN([M4_CHECK_DEBUGGING],
[AC_REQUIRE([AC_PROG_CC])
AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug],
                           [build for debugging [default=no]])])
AC_MSG_CHECKING([for compilation debug mode])
AC_MSG_RESULT([${enable_debug-no}])

: ${rm=rm -f}
: ${RM=rm -f}

set dummy $CC
compiler="${compiler-[$]2}"
test -n "$rm" || rm="rm -f"

if test "X$enable_debug" = Xyes; then
  AC_DISABLE_SHARED
  AC_DEFINE([DEBUG], [1],
      [Define this to enable additional runtime debugging])
  M4_default_preload="m4 traditional gnu load \
import modtest mpeval shadow stdlib time"
  if test "$GCC" = yes; then
    case "$CFLAGS" in
      *-O* ) CFLAGS=`echo $CFLAGS | $SED 's/-O[[^ ]]* / /;s/-O[[^ ]]*$//'` ;;
    esac
    case "$CFLAGS" in
        *-g* ) ;;
         * ) AC_LIBTOOL_COMPILER_OPTION([if $compiler accepts -ggdb3],
                 [M4_cv_prog_compiler_ggdb3],
                 [-ggdb3 -c conftest.$ac_ext], [],
                 [CFLAGS="$CFLAGS -ggdb3"],
               [CFLAGS="$CFLAGS -g"])
             ;;
    esac
    CFLAGS="$CFLAGS -Wall"
    WMORE="-Wshadow -Wpointer-arith -Wcast-align -Wnested-externs"
    WMORE="$WMORE -Wmissing-prototypes -Wmissing-declarations -Winline"
    AC_LIBTOOL_COMPILER_OPTION([if $compiler accepts $WMORE],
        [M4_cv_prog_compiler_warning_flags],
        [$WMORE -c conftest.$ac_ext], [],
        [CFLAGS="$CFLAGS $WMORE"])

    AC_LIBTOOL_COMPILER_OPTION([if $compiler accepts -Wno-long-long],
        [M4_cv_prog_compiler_wnolonglong],
        [-Wno-long-long -c conftest.$ac_ext], [],
        [CFLAGS="$CFLAGS -Wno-long-long"])
  else
    case "$CFLAGS" in
        *-g* ) ;;
           * ) CFLAGS="$CFLAGS -g" ;;
    esac
  fi
else
  AC_ENABLE_SHARED
  case "$CFLAGS" in
    *-g* ) CFLAGS=`echo "$CFLAGS" |\
               $SED -e 's/ -g / /g;s/ -g$//;s/^-g //g;s/^-g$//'`
           ;;
  esac
  case "$CXXFLAGS" in
    *-g* ) CXXFLAGS=`echo "$CXXFLAGS" |\
               $SED -e 's/ -g / /g;s/ -g$//;s/^-g //g;s/^-g$//'`
           ;;
  esac
fi
])# M4_CHECK_DEBUGGING