1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_check_enable_debug.html
3 # ===========================================================================
7 # AX_CHECK_ENABLE_DEBUG([enable by default=yes/info/profile/no], [ENABLE DEBUG VARIABLES ...], [DISABLE DEBUG VARIABLES NDEBUG ...], [IS-RELEASE])
11 # Check for the presence of an --enable-debug option to configure, with
12 # the specified default value used when the option is not present. Return
13 # the value in the variable $ax_enable_debug.
15 # Specifying 'yes' adds '-g -O0' to the compilation flags for all
16 # languages. Specifying 'info' adds '-g' to the compilation flags.
17 # Specifying 'profile' adds '-g -pg' to the compilation flags and '-pg' to
18 # the linking flags. Otherwise, nothing is added.
20 # Define the variables listed in the second argument if debug is enabled,
21 # defaulting to no variables. Defines the variables listed in the third
22 # argument if debug is disabled, defaulting to NDEBUG. All lists of
23 # variables should be space-separated.
25 # If debug is not enabled, ensure AC_PROG_* will not add debugging flags.
26 # Should be invoked prior to any AC_PROG_* compiler checks.
28 # IS-RELEASE can be used to change the default to 'no' when making a
29 # release. Set IS-RELEASE to 'yes' or 'no' as appropriate, for example by
30 # using the AX_IS_RELEASE macro:
32 # AX_IS_RELEASE([git-directory])
33 # AX_CHECK_ENABLE_DEBUG(,,,[$ax_is_release])
37 # Copyright (c) 2011 Rhys Ulerich <rhys.ulerich@gmail.com>
38 # Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
40 # Copying and distribution of this file, with or without modification, are
41 # permitted in any medium without royalty provided the copyright notice
42 # and this notice are preserved.
46 AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[
47 AC_BEFORE([$0],[AC_PROG_CC])dnl
48 AC_BEFORE([$0],[AC_PROG_CXX])dnl
49 AC_BEFORE([$0],[AC_PROG_F77])dnl
50 AC_BEFORE([$0],[AC_PROG_FC])dnl
52 AC_MSG_CHECKING(whether to enable debugging)
54 ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1])))
56 # If this is a release, override the default.
57 AS_IF([test "$4" = "yes"],
58 [ax_enable_debug_default="no"])
60 m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))])
61 m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))])
64 [AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])],
65 [],enable_debug=$ax_enable_debug_default)
67 # empty mean debug yes
68 AS_IF([test "x$enable_debug" = "x"],
72 AS_CASE([$enable_debug],
75 CFLAGS="${CFLAGS} -g -O0"
76 CXXFLAGS="${CXXFLAGS} -g -O0"
77 FFLAGS="${FFLAGS} -g -O0"
78 FCFLAGS="${FCFLAGS} -g -O0"
79 OBJCFLAGS="${OBJCFLAGS} -g -O0"
84 CXXFLAGS="${CXXFLAGS} -g"
86 FCFLAGS="${FCFLAGS} -g"
87 OBJCFLAGS="${OBJCFLAGS} -g"
90 AC_MSG_RESULT(profile)
91 CFLAGS="${CFLAGS} -g -pg"
92 CXXFLAGS="${CXXFLAGS} -g -pg"
93 FFLAGS="${FFLAGS} -g -pg"
94 FCFLAGS="${FCFLAGS} -g -pg"
95 OBJCFLAGS="${OBJCFLAGS} -g -pg"
96 LDFLAGS="${LDFLAGS} -pg"
100 dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags
101 dnl by setting any unset environment flag variables
102 AS_IF([test "x${CFLAGS+set}" != "xset"],
104 AS_IF([test "x${CXXFLAGS+set}" != "xset"],
106 AS_IF([test "x${FFLAGS+set}" != "xset"],
108 AS_IF([test "x${FCFLAGS+set}" != "xset"],
110 AS_IF([test "x${OBJCFLAGS+set}" != "xset"],
114 dnl Define various variables if debugging is disabled.
115 dnl assert.h is a NOP if NDEBUG is defined, so define it by default.
116 AS_IF([test "x$enable_debug" = "xyes"],
117 [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])],
118 [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])])
119 ax_enable_debug=$enable_debug