1*600f14f4SXin Li# =========================================================================== 2*600f14f4SXin Li# http://www.gnu.org/software/autoconf-archive/ax_check_enable_debug.html 3*600f14f4SXin Li# =========================================================================== 4*600f14f4SXin Li# 5*600f14f4SXin Li# SYNOPSIS 6*600f14f4SXin Li# 7*600f14f4SXin Li# AX_CHECK_ENABLE_DEBUG([enable by default=yes/info/profile/no], [ENABLE DEBUG VARIABLES ...], [DISABLE DEBUG VARIABLES NDEBUG ...], [IS-RELEASE]) 8*600f14f4SXin Li# 9*600f14f4SXin Li# DESCRIPTION 10*600f14f4SXin Li# 11*600f14f4SXin Li# Check for the presence of an --enable-debug option to configure, with 12*600f14f4SXin Li# the specified default value used when the option is not present. Return 13*600f14f4SXin Li# the value in the variable $ax_enable_debug. 14*600f14f4SXin Li# 15*600f14f4SXin Li# Specifying 'yes' adds '-g -O0' to the compilation flags for all 16*600f14f4SXin Li# languages. Specifying 'info' adds '-g' to the compilation flags. 17*600f14f4SXin Li# Specifying 'profile' adds '-g -pg' to the compilation flags and '-pg' to 18*600f14f4SXin Li# the linking flags. Otherwise, nothing is added. 19*600f14f4SXin Li# 20*600f14f4SXin Li# Define the variables listed in the second argument if debug is enabled, 21*600f14f4SXin Li# defaulting to no variables. Defines the variables listed in the third 22*600f14f4SXin Li# argument if debug is disabled, defaulting to NDEBUG. All lists of 23*600f14f4SXin Li# variables should be space-separated. 24*600f14f4SXin Li# 25*600f14f4SXin Li# If debug is not enabled, ensure AC_PROG_* will not add debugging flags. 26*600f14f4SXin Li# Should be invoked prior to any AC_PROG_* compiler checks. 27*600f14f4SXin Li# 28*600f14f4SXin Li# IS-RELEASE can be used to change the default to 'no' when making a 29*600f14f4SXin Li# release. Set IS-RELEASE to 'yes' or 'no' as appropriate. By default, it 30*600f14f4SXin Li# uses the value of $ax_is_release, so if you are using the AX_IS_RELEASE 31*600f14f4SXin Li# macro, there is no need to pass this parameter. 32*600f14f4SXin Li# 33*600f14f4SXin Li# AX_IS_RELEASE([git-directory]) 34*600f14f4SXin Li# AX_CHECK_ENABLE_DEBUG() 35*600f14f4SXin Li# 36*600f14f4SXin Li# LICENSE 37*600f14f4SXin Li# 38*600f14f4SXin Li# Copyright (c) 2011 Rhys Ulerich <[email protected]> 39*600f14f4SXin Li# Copyright (c) 2014, 2015 Philip Withnall <[email protected]> 40*600f14f4SXin Li# 41*600f14f4SXin Li# Copying and distribution of this file, with or without modification, are 42*600f14f4SXin Li# permitted in any medium without royalty provided the copyright notice 43*600f14f4SXin Li# and this notice are preserved. 44*600f14f4SXin Li 45*600f14f4SXin Li#serial 5 46*600f14f4SXin Li 47*600f14f4SXin LiAC_DEFUN([AX_CHECK_ENABLE_DEBUG],[ 48*600f14f4SXin Li AC_BEFORE([$0],[AC_PROG_CC])dnl 49*600f14f4SXin Li AC_BEFORE([$0],[AC_PROG_CXX])dnl 50*600f14f4SXin Li AC_BEFORE([$0],[AC_PROG_F77])dnl 51*600f14f4SXin Li AC_BEFORE([$0],[AC_PROG_FC])dnl 52*600f14f4SXin Li 53*600f14f4SXin Li AC_MSG_CHECKING(whether to enable debugging) 54*600f14f4SXin Li 55*600f14f4SXin Li ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1]))) 56*600f14f4SXin Li ax_enable_debug_is_release=m4_tolower(m4_normalize(ifelse([$4],, 57*600f14f4SXin Li [$ax_is_release], 58*600f14f4SXin Li [$4]))) 59*600f14f4SXin Li 60*600f14f4SXin Li # If this is a release, override the default. 61*600f14f4SXin Li AS_IF([test "$ax_enable_debug_is_release" = "yes"], 62*600f14f4SXin Li [ax_enable_debug_default="no"]) 63*600f14f4SXin Li 64*600f14f4SXin Li m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))]) 65*600f14f4SXin Li m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))]) 66*600f14f4SXin Li 67*600f14f4SXin Li AC_ARG_ENABLE(debug, 68*600f14f4SXin Li [AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])], 69*600f14f4SXin Li [],enable_debug=$ax_enable_debug_default) 70*600f14f4SXin Li 71*600f14f4SXin Li # empty mean debug yes 72*600f14f4SXin Li AS_IF([test "x$enable_debug" = "x"], 73*600f14f4SXin Li [enable_debug="yes"]) 74*600f14f4SXin Li 75*600f14f4SXin Li # case of debug 76*600f14f4SXin Li AS_CASE([$enable_debug], 77*600f14f4SXin Li [yes],[ 78*600f14f4SXin Li AC_MSG_RESULT(yes) 79*600f14f4SXin Li CFLAGS="${CFLAGS} -g -O0" 80*600f14f4SXin Li CXXFLAGS="${CXXFLAGS} -g -O0" 81*600f14f4SXin Li FFLAGS="${FFLAGS} -g -O0" 82*600f14f4SXin Li FCFLAGS="${FCFLAGS} -g -O0" 83*600f14f4SXin Li OBJCFLAGS="${OBJCFLAGS} -g -O0" 84*600f14f4SXin Li ], 85*600f14f4SXin Li [info],[ 86*600f14f4SXin Li AC_MSG_RESULT(info) 87*600f14f4SXin Li CFLAGS="${CFLAGS} -g" 88*600f14f4SXin Li CXXFLAGS="${CXXFLAGS} -g" 89*600f14f4SXin Li FFLAGS="${FFLAGS} -g" 90*600f14f4SXin Li FCFLAGS="${FCFLAGS} -g" 91*600f14f4SXin Li OBJCFLAGS="${OBJCFLAGS} -g" 92*600f14f4SXin Li ], 93*600f14f4SXin Li [profile],[ 94*600f14f4SXin Li AC_MSG_RESULT(profile) 95*600f14f4SXin Li CFLAGS="${CFLAGS} -g -pg" 96*600f14f4SXin Li CXXFLAGS="${CXXFLAGS} -g -pg" 97*600f14f4SXin Li FFLAGS="${FFLAGS} -g -pg" 98*600f14f4SXin Li FCFLAGS="${FCFLAGS} -g -pg" 99*600f14f4SXin Li OBJCFLAGS="${OBJCFLAGS} -g -pg" 100*600f14f4SXin Li LDFLAGS="${LDFLAGS} -pg" 101*600f14f4SXin Li ], 102*600f14f4SXin Li [ 103*600f14f4SXin Li AC_MSG_RESULT(no) 104*600f14f4SXin Li dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags 105*600f14f4SXin Li dnl by setting any unset environment flag variables 106*600f14f4SXin Li AS_IF([test "x${CFLAGS+set}" != "xset"], 107*600f14f4SXin Li [CFLAGS=""]) 108*600f14f4SXin Li AS_IF([test "x${CXXFLAGS+set}" != "xset"], 109*600f14f4SXin Li [CXXFLAGS=""]) 110*600f14f4SXin Li AS_IF([test "x${FFLAGS+set}" != "xset"], 111*600f14f4SXin Li [FFLAGS=""]) 112*600f14f4SXin Li AS_IF([test "x${FCFLAGS+set}" != "xset"], 113*600f14f4SXin Li [FCFLAGS=""]) 114*600f14f4SXin Li AS_IF([test "x${OBJCFLAGS+set}" != "xset"], 115*600f14f4SXin Li [OBJCFLAGS=""]) 116*600f14f4SXin Li ]) 117*600f14f4SXin Li 118*600f14f4SXin Li dnl Define various variables if debugging is disabled. 119*600f14f4SXin Li dnl assert.h is a NOP if NDEBUG is defined, so define it by default. 120*600f14f4SXin Li AS_IF([test "x$enable_debug" = "xyes"], 121*600f14f4SXin Li [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])], 122*600f14f4SXin Li [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])]) 123*600f14f4SXin Li ax_enable_debug=$enable_debug 124*600f14f4SXin Li]) 125