Blame m4/ax_check_enable_debug.m4

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