You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

125 lines
4.7 KiB

  1. # ===========================================================================
  2. # https://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. # Copying and distribution of this file, with or without modification, are
  42. # permitted in any medium without royalty provided the copyright notice
  43. # and this notice are preserved.
  44. #serial 8
  45. AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[
  46. AC_BEFORE([$0],[AC_PROG_CC])dnl
  47. AC_BEFORE([$0],[AC_PROG_CXX])dnl
  48. AC_BEFORE([$0],[AC_PROG_F77])dnl
  49. AC_BEFORE([$0],[AC_PROG_FC])dnl
  50. AC_MSG_CHECKING(whether to enable debugging)
  51. ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1])))
  52. ax_enable_debug_is_release=m4_tolower(m4_normalize(ifelse([$4],,
  53. [$ax_is_release],
  54. [$4])))
  55. # If this is a release, override the default.
  56. AS_IF([test "$ax_enable_debug_is_release" = "yes"],
  57. [ax_enable_debug_default="no"])
  58. m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))])
  59. m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))])
  60. AC_ARG_ENABLE(debug,
  61. [AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])],
  62. [],enable_debug=$ax_enable_debug_default)
  63. # empty mean debug yes
  64. AS_IF([test "x$enable_debug" = "x"],
  65. [enable_debug="yes"])
  66. # case of debug
  67. AS_CASE([$enable_debug],
  68. [yes],[
  69. AC_MSG_RESULT(yes)
  70. CFLAGS="${CFLAGS} -g -O0"
  71. CXXFLAGS="${CXXFLAGS} -g -O0"
  72. FFLAGS="${FFLAGS} -g -O0"
  73. FCFLAGS="${FCFLAGS} -g -O0"
  74. OBJCFLAGS="${OBJCFLAGS} -g -O0"
  75. ],
  76. [info],[
  77. AC_MSG_RESULT(info)
  78. CFLAGS="${CFLAGS} -g"
  79. CXXFLAGS="${CXXFLAGS} -g"
  80. FFLAGS="${FFLAGS} -g"
  81. FCFLAGS="${FCFLAGS} -g"
  82. OBJCFLAGS="${OBJCFLAGS} -g"
  83. ],
  84. [profile],[
  85. AC_MSG_RESULT(profile)
  86. CFLAGS="${CFLAGS} -g -pg"
  87. CXXFLAGS="${CXXFLAGS} -g -pg"
  88. FFLAGS="${FFLAGS} -g -pg"
  89. FCFLAGS="${FCFLAGS} -g -pg"
  90. OBJCFLAGS="${OBJCFLAGS} -g -pg"
  91. LDFLAGS="${LDFLAGS} -pg"
  92. ],
  93. [
  94. AC_MSG_RESULT(no)
  95. dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags
  96. dnl by setting any unset environment flag variables
  97. AS_IF([test "x${CFLAGS+set}" != "xset"],
  98. [CFLAGS=""])
  99. AS_IF([test "x${CXXFLAGS+set}" != "xset"],
  100. [CXXFLAGS=""])
  101. AS_IF([test "x${FFLAGS+set}" != "xset"],
  102. [FFLAGS=""])
  103. AS_IF([test "x${FCFLAGS+set}" != "xset"],
  104. [FCFLAGS=""])
  105. AS_IF([test "x${OBJCFLAGS+set}" != "xset"],
  106. [OBJCFLAGS=""])
  107. ])
  108. dnl Define various variables if debugging is disabled.
  109. dnl assert.h is a NOP if NDEBUG is defined, so define it by default.
  110. AS_IF([test "x$enable_debug" = "xyes"],
  111. [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])],
  112. [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])])
  113. ax_enable_debug=$enable_debug
  114. ])