dk-warn.m4 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ## Copyright (c) 2004-2007 Daniel Elstner <daniel.kitta@gmail.com>
  2. ##
  3. ## This file is part of danielk's Autostuff.
  4. ##
  5. ## danielk's Autostuff is free software; you can redistribute it and/or
  6. ## modify it under the terms of the GNU General Public License as published
  7. ## by the Free Software Foundation; either version 2 of the License, or (at
  8. ## your option) any later version.
  9. ##
  10. ## danielk's Autostuff is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. ## for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License along
  16. ## with danielk's Autostuff; if not, write to the Free Software Foundation,
  17. ## Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. #serial 20070116
  19. ## DK_ARG_ENABLE_WARNINGS(variable, min-flags, max-flags, [deprecation-prefixes])
  20. ##
  21. ## Provide the --enable-warnings configure argument, set to "min" by default.
  22. ## <min-flags> and <max-flags> should be space-separated lists of compiler
  23. ## warning flags to use with --enable-warnings=min or --enable-warnings=max,
  24. ## respectively. Warning level "fatal" is the same as "max" but in addition
  25. ## enables -Werror mode.
  26. ##
  27. ## If not empty, <deprecation-prefixes> should be a list of module prefixes
  28. ## which is expanded to -D<module>_DISABLE_DEPRECATED flags if fatal warnings
  29. ## are enabled, too.
  30. ##
  31. AC_DEFUN([DK_ARG_ENABLE_WARNINGS],
  32. [dnl
  33. m4_if([$3],, [AC_FATAL([3 arguments expected])])[]dnl
  34. dnl
  35. AC_ARG_ENABLE([warnings], [AS_HELP_STRING(
  36. [--enable-warnings=@<:@min|max|fatal|no@:>@],
  37. [control compiler pickyness @<:@min@:>@])],
  38. [dk_enable_warnings=$enableval],
  39. [dk_enable_warnings=min])[]dnl
  40. dk_lang=
  41. case $ac_compile in
  42. *'$CXXFLAGS '*)
  43. dk_lang='C++'
  44. dk_cc=$CXX
  45. dk_conftest=conftest.${ac_ext-cc}
  46. ;;
  47. *'$CFLAGS '*)
  48. dk_lang=C
  49. dk_cc=$CC
  50. dk_conftest=conftest.${ac_ext-c}
  51. ;;
  52. esac
  53. AS_IF([test "x$dk_lang" != x],
  54. [
  55. AC_MSG_CHECKING([which $dk_lang compiler warning flags to use])
  56. case $dk_enable_warnings in
  57. no) dk_warning_flags=;;
  58. max) dk_warning_flags="$3";;
  59. fatal) dk_warning_flags="$3 -Werror";;
  60. *) dk_warning_flags="$2";;
  61. esac
  62. dk_deprecation_flags=
  63. m4_if([$4],,, [
  64. AS_IF([test "x$dk_enable_warnings" = xfatal],
  65. [
  66. dk_deprecation_prefixes="$4"
  67. for dk_prefix in $dk_deprecation_prefixes
  68. do
  69. dk_deprecation_flags="${dk_deprecation_flags}-D${dk_prefix}_DISABLE_DEPRECATED "
  70. done
  71. ])
  72. ])[]dnl
  73. dk_tested_flags=
  74. AS_IF([test "x$dk_warning_flags" != x],
  75. [
  76. # Keep in mind that the dummy source must be devoid of any
  77. # problems that might cause diagnostics.
  78. AC_LANG_CONFTEST([AC_LANG_SOURCE(
  79. [[int main(int argc, char** argv) { return (argv != 0) ? argc : 0; }]])])
  80. for dk_flag in $dk_warning_flags
  81. do
  82. # Test whether the compiler accepts the flag. GCC doesn't bail
  83. # out when given an unsupported flag but prints a warning, so
  84. # check the compiler output instead.
  85. dk_cc_out=`$dk_cc $dk_tested_flags $dk_flag -c "$dk_conftest" 2>&1 || echo failed`
  86. rm -f "conftest.${OBJEXT-o}"
  87. AS_IF([test "x$dk_cc_out" = x],
  88. [
  89. AS_IF([test "x$dk_tested_flags" = x],
  90. [dk_tested_flags=$dk_flag],
  91. [dk_tested_flags="$dk_tested_flags $dk_flag"])
  92. ], [
  93. echo "$dk_cc_out" >&AS_MESSAGE_LOG_FD
  94. ])
  95. done
  96. rm -f "$dk_conftest"
  97. ])
  98. dk_all_flags=$dk_deprecation_flags$dk_tested_flags
  99. AC_SUBST([$1], [$dk_all_flags])
  100. test "x$dk_all_flags" != x || dk_all_flags=none
  101. AC_MSG_RESULT([$dk_all_flags])
  102. ])
  103. ])