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. By default, it
30 # uses the value of $ax_is_release, so if you are using the AX_IS_RELEASE
31 # macro, there is no need to pass this parameter.
33 # AX_IS_RELEASE([git-directory])
34 # AX_CHECK_ENABLE_DEBUG()
38 # Copyright (c) 2011 Rhys Ulerich <rhys.ulerich@gmail.com>
39 # Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
41 # Copying and distribution of this file, with or without modification, are
42 # permitted in any medium without royalty provided the copyright notice
43 # and this notice are preserved.
47 AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[
48 AC_BEFORE([$0],[AC_PROG_CC])dnl
49 AC_BEFORE([$0],[AC_PROG_CXX])dnl
50 AC_BEFORE([$0],[AC_PROG_F77])dnl
51 AC_BEFORE([$0],[AC_PROG_FC])dnl
53 AC_MSG_CHECKING(whether to enable debugging)
55 ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1])))
56 ax_enable_debug_is_release=m4_tolower(m4_normalize(ifelse([$4],,
60 # If this is a release, override the default.
61 AS_IF([test "$ax_enable_debug_is_release" = "yes"],
62 [ax_enable_debug_default="no"])
64 m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))])
65 m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))])
68 [AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])],
69 [],enable_debug=$ax_enable_debug_default)
71 # empty mean debug yes
72 AS_IF([test "x$enable_debug" = "x"],
76 AS_CASE([$enable_debug],
79 CFLAGS="${CFLAGS} -g -O0"
80 CXXFLAGS="${CXXFLAGS} -g -O0"
81 FFLAGS="${FFLAGS} -g -O0"
82 FCFLAGS="${FCFLAGS} -g -O0"
83 OBJCFLAGS="${OBJCFLAGS} -g -O0"
88 CXXFLAGS="${CXXFLAGS} -g"
90 FCFLAGS="${FCFLAGS} -g"
91 OBJCFLAGS="${OBJCFLAGS} -g"
94 AC_MSG_RESULT(profile)
95 CFLAGS="${CFLAGS} -g -pg"
96 CXXFLAGS="${CXXFLAGS} -g -pg"
97 FFLAGS="${FFLAGS} -g -pg"
98 FCFLAGS="${FCFLAGS} -g -pg"
99 OBJCFLAGS="${OBJCFLAGS} -g -pg"
100 LDFLAGS="${LDFLAGS} -pg"
104 dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags
105 dnl by setting any unset environment flag variables
106 AS_IF([test "x${CFLAGS+set}" != "xset"],
108 AS_IF([test "x${CXXFLAGS+set}" != "xset"],
110 AS_IF([test "x${FFLAGS+set}" != "xset"],
112 AS_IF([test "x${FCFLAGS+set}" != "xset"],
114 AS_IF([test "x${OBJCFLAGS+set}" != "xset"],
118 dnl Define various variables if debugging is disabled.
119 dnl assert.h is a NOP if NDEBUG is defined, so define it by default.
120 AS_IF([test "x$enable_debug" = "xyes"],
121 [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])],
122 [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])])
123 ax_enable_debug=$enable_debug