Blame m4/ax_check_enable_debug.m4

Packit 712bc5
# ===========================================================================
Packit 712bc5
#         http://autoconf-archive.cryp.to/ax_check_enable_debug.html
Packit 712bc5
# ===========================================================================
Packit 712bc5
#
Packit 712bc5
# SYNOPSIS
Packit 712bc5
#
Packit 712bc5
#   Check for the presence of an --enable-debug option to configure and
Packit 712bc5
#   allow/avoid compiled debugging flags appropriately.
Packit 712bc5
#
Packit 712bc5
#   AX_CHECK_ENABLE_DEBUG([enable by default=yes/info/profile/no],
Packit 712bc5
#                         [ENABLE DEBUG VARIABLES …],
Packit 712bc5
#                         [DISABLE DEBUG VARIABLES NDEBUG …])
Packit 712bc5
#
Packit 712bc5
# DESCRIPTION
Packit 712bc5
#
Packit 712bc5
#   Check for the presence of an --enable-debug option to configure, with the
Packit 712bc5
#   specified default value used when the option is not present.  Return the
Packit 712bc5
#   value in the variable $ax_enable_debug.
Packit 712bc5
#
Packit 712bc5
#   Specifying 'yes' adds '-g -O0' to the compilation flags for all languages.
Packit 712bc5
#   Specifying 'info' adds '-g' to the compilation flags.  Specifying 'profile'
Packit 712bc5
#   adds '-g -pg' to the compilation flags and '-pg' to the linking flags.
Packit 712bc5
#   Otherwise, nothing is added.
Packit 712bc5
#
Packit 712bc5
#   Define the variables listed in the second argument if debug is enabled,
Packit 712bc5
#   defaulting to no variables.  Defines the variables listed in the third
Packit 712bc5
#   argument if debug is disabled, defaulting to NDEBUG.  All lists of
Packit 712bc5
#   variables should be space-separated.
Packit 712bc5
#
Packit 712bc5
#   If debug is not enabled, ensure AC_PROG_* will not add debugging flags.
Packit 712bc5
#   Should be invoked prior to any AC_PROG_* compiler checks.
Packit 712bc5
#
Packit 712bc5
# LAST MODIFICATION
Packit 712bc5
#
Packit 712bc5
#   2014-05-12
Packit 712bc5
#
Packit 712bc5
# COPYLEFT
Packit 712bc5
#
Packit 712bc5
#   Copyright (c) 2011 Rhys Ulerich <rhys.ulerich@gmail.com>
Packit 712bc5
#   Copyright © 2014 Philip Withnall <philip@tecnocode.co.uk>
Packit 712bc5
#
Packit 712bc5
#   Copying and distribution of this file, with or without modification, are
Packit 712bc5
#   permitted in any medium without royalty provided the copyright notice
Packit 712bc5
#   and this notice are preserved.
Packit 712bc5
Packit 712bc5
AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[
Packit 712bc5
    AC_BEFORE([$0],[AC_PROG_CC])dnl
Packit 712bc5
    AC_BEFORE([$0],[AC_PROG_CXX])dnl
Packit 712bc5
    AC_BEFORE([$0],[AC_PROG_F77])dnl
Packit 712bc5
    AC_BEFORE([$0],[AC_PROG_FC])dnl
Packit 712bc5
Packit 712bc5
    AC_MSG_CHECKING(whether to enable debugging)
Packit 712bc5
Packit 712bc5
    m4_define(ax_enable_debug_default,[m4_tolower(m4_normalize(ifelse([$1],,[no],[$1])))])
Packit 712bc5
    m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))])
Packit 712bc5
    m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))])
Packit 712bc5
Packit 712bc5
    AC_ARG_ENABLE(debug,
Packit 712bc5
        [AS_HELP_STRING([--enable-debug]@<:@=ax_enable_debug_default@:>@,[compile with debugging; one of yes/info/profile/no])],
Packit 712bc5
        [],enable_debug=ax_enable_debug_default)
Packit 712bc5
    if test "x$enable_debug" = "xyes" || test "x$enable_debug" = "x"; then
Packit 712bc5
        AC_MSG_RESULT(yes)
Packit 712bc5
        CFLAGS="${CFLAGS} -g -O0"
Packit 712bc5
        CXXFLAGS="${CXXFLAGS} -g -O0"
Packit 712bc5
        FFLAGS="${FFLAGS} -g -O0"
Packit 712bc5
        FCFLAGS="${FCFLAGS} -g -O0"
Packit 712bc5
        OBJCFLAGS="${OBJCFLAGS} -g -O0"
Packit 712bc5
Packit 712bc5
        dnl Define various variables if debugging is enabled.
Packit 712bc5
        m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])
Packit 712bc5
    else
Packit 712bc5
        if test "x$enable_debug" = "xinfo"; then
Packit 712bc5
            AC_MSG_RESULT(info)
Packit 712bc5
            CFLAGS="${CFLAGS} -g"
Packit 712bc5
            CXXFLAGS="${CXXFLAGS} -g"
Packit 712bc5
            FFLAGS="${FFLAGS} -g"
Packit 712bc5
            FCFLAGS="${FCFLAGS} -g"
Packit 712bc5
            OBJCFLAGS="${OBJCFLAGS} -g"
Packit 712bc5
        elif test "x$enable_debug" = "xprofile"; then
Packit 712bc5
            AC_MSG_RESULT(profile)
Packit 712bc5
            CFLAGS="${CFLAGS} -g -pg"
Packit 712bc5
            CXXFLAGS="${CXXFLAGS} -g -pg"
Packit 712bc5
            FFLAGS="${FFLAGS} -g -pg"
Packit 712bc5
            FCFLAGS="${FCFLAGS} -g -pg"
Packit 712bc5
            OBJCFLAGS="${OBJCFLAGS} -g -pg"
Packit 712bc5
            LDFLAGS="${LDFLAGS} -pg"
Packit 712bc5
        else
Packit 712bc5
            AC_MSG_RESULT(no)
Packit 712bc5
            dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags
Packit 712bc5
            dnl by setting any unset environment flag variables
Packit 712bc5
            if test "x${CFLAGS+set}" != "xset"; then
Packit 712bc5
                CFLAGS=""
Packit 712bc5
            fi
Packit 712bc5
            if test "x${CXXFLAGS+set}" != "xset"; then
Packit 712bc5
                CXXFLAGS=""
Packit 712bc5
            fi
Packit 712bc5
            if test "x${FFLAGS+set}" != "xset"; then
Packit 712bc5
                FFLAGS=""
Packit 712bc5
            fi
Packit 712bc5
            if test "x${FCFLAGS+set}" != "xset"; then
Packit 712bc5
                FCFLAGS=""
Packit 712bc5
            fi
Packit 712bc5
            if test "x${OBJCFLAGS+set}" != "xset"; then
Packit 712bc5
                OBJCFLAGS=""
Packit 712bc5
            fi
Packit 712bc5
        fi
Packit 712bc5
Packit 712bc5
        dnl Define various variables if debugging is disabled.
Packit 712bc5
        dnl assert.h is a NOP if NDEBUG is defined, so define it by default.
Packit 712bc5
        m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])
Packit 712bc5
    fi
Packit 712bc5
    ax_enable_debug=$enable_debug
Packit 712bc5
])