ax_check_enable_debug.m4 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_check_enable_debug.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CHECK_ENABLE_DEBUG([enable by default=yes/info/profile/no], [ENABLE DEBUG VARIABLES ...], [DISABLE DEBUG VARIABLES NDEBUG ...], [IS-RELEASE])
  8. #
  9. # DESCRIPTION
  10. #
  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.
  14. #
  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.
  19. #
  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.
  24. #
  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.
  27. #
  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.
  32. #
  33. # AX_IS_RELEASE([git-directory])
  34. # AX_CHECK_ENABLE_DEBUG()
  35. #
  36. # LICENSE
  37. #
  38. # Copyright (c) 2011 Rhys Ulerich <rhys.ulerich@gmail.com>
  39. # Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
  40. #
  41. # SPDX-License-Identifier: FSFAP
  42. #serial 5
  43. AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[
  44. AC_BEFORE([$0],[AC_PROG_CC])dnl
  45. AC_BEFORE([$0],[AC_PROG_CXX])dnl
  46. AC_BEFORE([$0],[AC_PROG_F77])dnl
  47. AC_BEFORE([$0],[AC_PROG_FC])dnl
  48. AC_MSG_CHECKING(whether to enable debugging)
  49. ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1])))
  50. ax_enable_debug_is_release=m4_tolower(m4_normalize(ifelse([$4],,
  51. [$ax_is_release],
  52. [$4])))
  53. # If this is a release, override the default.
  54. AS_IF([test "$ax_enable_debug_is_release" = "yes"],
  55. [ax_enable_debug_default="no"])
  56. m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))])
  57. m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))])
  58. AC_ARG_ENABLE(debug,
  59. [AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])],
  60. [],enable_debug=$ax_enable_debug_default)
  61. # empty mean debug yes
  62. AS_IF([test "x$enable_debug" = "x"],
  63. [enable_debug="yes"])
  64. # case of debug
  65. AS_CASE([$enable_debug],
  66. [yes],[
  67. AC_MSG_RESULT(yes)
  68. CFLAGS="${CFLAGS} -g -O0"
  69. CXXFLAGS="${CXXFLAGS} -g -O0"
  70. FFLAGS="${FFLAGS} -g -O0"
  71. FCFLAGS="${FCFLAGS} -g -O0"
  72. OBJCFLAGS="${OBJCFLAGS} -g -O0"
  73. ],
  74. [info],[
  75. AC_MSG_RESULT(info)
  76. CFLAGS="${CFLAGS} -g"
  77. CXXFLAGS="${CXXFLAGS} -g"
  78. FFLAGS="${FFLAGS} -g"
  79. FCFLAGS="${FCFLAGS} -g"
  80. OBJCFLAGS="${OBJCFLAGS} -g"
  81. ],
  82. [profile],[
  83. AC_MSG_RESULT(profile)
  84. CFLAGS="${CFLAGS} -g -pg"
  85. CXXFLAGS="${CXXFLAGS} -g -pg"
  86. FFLAGS="${FFLAGS} -g -pg"
  87. FCFLAGS="${FCFLAGS} -g -pg"
  88. OBJCFLAGS="${OBJCFLAGS} -g -pg"
  89. LDFLAGS="${LDFLAGS} -pg"
  90. ],
  91. [
  92. AC_MSG_RESULT(no)
  93. dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags
  94. dnl by setting any unset environment flag variables
  95. AS_IF([test "x${CFLAGS+set}" != "xset"],
  96. [CFLAGS=""])
  97. AS_IF([test "x${CXXFLAGS+set}" != "xset"],
  98. [CXXFLAGS=""])
  99. AS_IF([test "x${FFLAGS+set}" != "xset"],
  100. [FFLAGS=""])
  101. AS_IF([test "x${FCFLAGS+set}" != "xset"],
  102. [FCFLAGS=""])
  103. AS_IF([test "x${OBJCFLAGS+set}" != "xset"],
  104. [OBJCFLAGS=""])
  105. ])
  106. dnl Define various variables if debugging is disabled.
  107. dnl assert.h is a NOP if NDEBUG is defined, so define it by default.
  108. AS_IF([test "x$enable_debug" = "xyes"],
  109. [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])],
  110. [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])])
  111. ax_enable_debug=$enable_debug
  112. ])