Blame m4/ax_check_enable_debug.m4

Packit 5e0819
# ===========================================================================
Packit 5e0819
#  https://www.gnu.org/software/autoconf-archive/ax_check_enable_debug.html
Packit 5e0819
# ===========================================================================
Packit 5e0819
#
Packit 5e0819
# SYNOPSIS
Packit 5e0819
#
Packit 5e0819
#   AX_CHECK_ENABLE_DEBUG([enable by default=yes/info/profile/no], [ENABLE DEBUG VARIABLES ...], [DISABLE DEBUG VARIABLES NDEBUG ...], [IS-RELEASE])
Packit 5e0819
#
Packit 5e0819
# DESCRIPTION
Packit 5e0819
#
Packit 5e0819
#   Check for the presence of an --enable-debug option to configure, with
Packit 5e0819
#   the specified default value used when the option is not present.  Return
Packit 5e0819
#   the value in the variable $ax_enable_debug.
Packit 5e0819
#
Packit 5e0819
#   Specifying 'yes' adds '-g -O0' to the compilation flags for all
Packit 5e0819
#   languages. Specifying 'info' adds '-g' to the compilation flags.
Packit 5e0819
#   Specifying 'profile' adds '-g -pg' to the compilation flags and '-pg' to
Packit 5e0819
#   the linking flags. Otherwise, nothing is added.
Packit 5e0819
#
Packit 5e0819
#   Define the variables listed in the second argument if debug is enabled,
Packit 5e0819
#   defaulting to no variables.  Defines the variables listed in the third
Packit 5e0819
#   argument if debug is disabled, defaulting to NDEBUG.  All lists of
Packit 5e0819
#   variables should be space-separated.
Packit 5e0819
#
Packit 5e0819
#   If debug is not enabled, ensure AC_PROG_* will not add debugging flags.
Packit 5e0819
#   Should be invoked prior to any AC_PROG_* compiler checks.
Packit 5e0819
#
Packit 5e0819
#   IS-RELEASE can be used to change the default to 'no' when making a
Packit 5e0819
#   release.  Set IS-RELEASE to 'yes' or 'no' as appropriate. By default, it
Packit 5e0819
#   uses the value of $ax_is_release, so if you are using the AX_IS_RELEASE
Packit 5e0819
#   macro, there is no need to pass this parameter.
Packit 5e0819
#
Packit 5e0819
#     AX_IS_RELEASE([git-directory])
Packit 5e0819
#     AX_CHECK_ENABLE_DEBUG()
Packit 5e0819
#
Packit 5e0819
# LICENSE
Packit 5e0819
#
Packit 5e0819
#   Copyright (c) 2011 Rhys Ulerich <rhys.ulerich@gmail.com>
Packit 5e0819
#   Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
Packit 5e0819
#
Packit 5e0819
#   Copying and distribution of this file, with or without modification, are
Packit 5e0819
#   permitted in any medium without royalty provided the copyright notice
Packit 5e0819
#   and this notice are preserved.
Packit 5e0819
Packit 5e0819
#serial 8
Packit 5e0819
Packit 5e0819
AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[
Packit 5e0819
    AC_BEFORE([$0],[AC_PROG_CC])dnl
Packit 5e0819
    AC_BEFORE([$0],[AC_PROG_CXX])dnl
Packit 5e0819
    AC_BEFORE([$0],[AC_PROG_F77])dnl
Packit 5e0819
    AC_BEFORE([$0],[AC_PROG_FC])dnl
Packit 5e0819
Packit 5e0819
    AC_MSG_CHECKING(whether to enable debugging)
Packit 5e0819
Packit 5e0819
    ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1])))
Packit 5e0819
    ax_enable_debug_is_release=m4_tolower(m4_normalize(ifelse([$4],,
Packit 5e0819
                                                              [$ax_is_release],
Packit 5e0819
                                                              [$4])))
Packit 5e0819
Packit 5e0819
    # If this is a release, override the default.
Packit 5e0819
    AS_IF([test "$ax_enable_debug_is_release" = "yes"],
Packit 5e0819
      [ax_enable_debug_default="no"])
Packit 5e0819
Packit 5e0819
    m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))])
Packit 5e0819
    m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))])
Packit 5e0819
Packit 5e0819
    AC_ARG_ENABLE(debug,
Packit 5e0819
        [AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])],
Packit 5e0819
        [],enable_debug=$ax_enable_debug_default)
Packit 5e0819
Packit 5e0819
    # empty mean debug yes
Packit 5e0819
    AS_IF([test "x$enable_debug" = "x"],
Packit 5e0819
      [enable_debug="yes"])
Packit 5e0819
Packit 5e0819
    # case of debug
Packit 5e0819
    AS_CASE([$enable_debug],
Packit 5e0819
      [yes],[
Packit 5e0819
        AC_MSG_RESULT(yes)
Packit 5e0819
        CFLAGS="${CFLAGS} -g -O0"
Packit 5e0819
        CXXFLAGS="${CXXFLAGS} -g -O0"
Packit 5e0819
        FFLAGS="${FFLAGS} -g -O0"
Packit 5e0819
        FCFLAGS="${FCFLAGS} -g -O0"
Packit 5e0819
        OBJCFLAGS="${OBJCFLAGS} -g -O0"
Packit 5e0819
      ],
Packit 5e0819
      [info],[
Packit 5e0819
        AC_MSG_RESULT(info)
Packit 5e0819
        CFLAGS="${CFLAGS} -g"
Packit 5e0819
        CXXFLAGS="${CXXFLAGS} -g"
Packit 5e0819
        FFLAGS="${FFLAGS} -g"
Packit 5e0819
        FCFLAGS="${FCFLAGS} -g"
Packit 5e0819
        OBJCFLAGS="${OBJCFLAGS} -g"
Packit 5e0819
      ],
Packit 5e0819
      [profile],[
Packit 5e0819
        AC_MSG_RESULT(profile)
Packit 5e0819
        CFLAGS="${CFLAGS} -g -pg"
Packit 5e0819
        CXXFLAGS="${CXXFLAGS} -g -pg"
Packit 5e0819
        FFLAGS="${FFLAGS} -g -pg"
Packit 5e0819
        FCFLAGS="${FCFLAGS} -g -pg"
Packit 5e0819
        OBJCFLAGS="${OBJCFLAGS} -g -pg"
Packit 5e0819
        LDFLAGS="${LDFLAGS} -pg"
Packit 5e0819
      ],
Packit 5e0819
      [
Packit 5e0819
        AC_MSG_RESULT(no)
Packit 5e0819
        dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags
Packit 5e0819
        dnl by setting any unset environment flag variables
Packit 5e0819
        AS_IF([test "x${CFLAGS+set}" != "xset"],
Packit 5e0819
          [CFLAGS=""])
Packit 5e0819
        AS_IF([test "x${CXXFLAGS+set}" != "xset"],
Packit 5e0819
          [CXXFLAGS=""])
Packit 5e0819
        AS_IF([test "x${FFLAGS+set}" != "xset"],
Packit 5e0819
          [FFLAGS=""])
Packit 5e0819
        AS_IF([test "x${FCFLAGS+set}" != "xset"],
Packit 5e0819
          [FCFLAGS=""])
Packit 5e0819
        AS_IF([test "x${OBJCFLAGS+set}" != "xset"],
Packit 5e0819
          [OBJCFLAGS=""])
Packit 5e0819
      ])
Packit 5e0819
Packit 5e0819
    dnl Define various variables if debugging is disabled.
Packit 5e0819
    dnl assert.h is a NOP if NDEBUG is defined, so define it by default.
Packit 5e0819
    AS_IF([test "x$enable_debug" = "xyes"],
Packit 5e0819
      [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])],
Packit 5e0819
      [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])])
Packit 5e0819
    ax_enable_debug=$enable_debug
Packit 5e0819
])