Collection of DPF-based plugins for packaging
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.

161 lines
5.6KB

  1. # =============================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cflags.html
  3. # =============================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_COMPILER_FLAGS_CFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-YES-FLAGS])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Add warning flags for the C compiler to VARIABLE, which defaults to
  12. # WARN_CFLAGS. VARIABLE is AC_SUBST-ed by this macro, but must be
  13. # manually added to the CFLAGS variable for each target in the code base.
  14. #
  15. # This macro depends on the environment set up by AX_COMPILER_FLAGS.
  16. # Specifically, it uses the value of $ax_enable_compile_warnings to decide
  17. # which flags to enable.
  18. #
  19. # LICENSE
  20. #
  21. # Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
  22. # Copyright (c) 2017, 2018 Reini Urban <rurban@cpan.org>
  23. #
  24. # Copying and distribution of this file, with or without modification, are
  25. # permitted in any medium without royalty provided the copyright notice
  26. # and this notice are preserved. This file is offered as-is, without any
  27. # warranty.
  28. #serial 16
  29. AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
  30. AC_REQUIRE([AC_PROG_SED])
  31. AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS])
  32. AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
  33. AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
  34. # Variable names
  35. m4_define([ax_warn_cflags_variable],
  36. [m4_normalize(ifelse([$1],,[WARN_CFLAGS],[$1]))])
  37. AC_LANG_PUSH([C])
  38. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
  39. [#ifndef __cplusplus
  40. #error "no C++"
  41. #endif]])],
  42. [ax_compiler_cxx=yes;],
  43. [ax_compiler_cxx=no;])
  44. # Always pass -Werror=unknown-warning-option to get Clang to fail on bad
  45. # flags, otherwise they are always appended to the warn_cflags variable, and
  46. # Clang warns on them for every compilation unit.
  47. # If this is passed to GCC, it will explode, so the flag must be enabled
  48. # conditionally.
  49. AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[
  50. ax_compiler_flags_test="-Werror=unknown-warning-option"
  51. ],[
  52. ax_compiler_flags_test=""
  53. ])
  54. # Check that -Wno-suggest-attribute=format is supported
  55. AX_CHECK_COMPILE_FLAG([-Wno-suggest-attribute=format],[
  56. ax_compiler_no_suggest_attribute_flags="-Wno-suggest-attribute=format"
  57. ],[
  58. ax_compiler_no_suggest_attribute_flags=""
  59. ])
  60. # Base flags
  61. AX_APPEND_COMPILE_FLAGS([ dnl
  62. -fno-strict-aliasing dnl
  63. $3 dnl
  64. ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
  65. AS_IF([test "$ax_enable_compile_warnings" != "no"],[
  66. # "yes" flags
  67. AX_APPEND_COMPILE_FLAGS([ dnl
  68. -Wall dnl
  69. -Wextra dnl
  70. -Wundef dnl
  71. -Wwrite-strings dnl
  72. -Wpointer-arith dnl
  73. -Wmissing-declarations dnl
  74. -Wredundant-decls dnl
  75. -Wno-unused-parameter dnl
  76. -Wno-missing-field-initializers dnl
  77. -Wformat=2 dnl
  78. -Wcast-align dnl
  79. -Wformat-nonliteral dnl
  80. -Wformat-security dnl
  81. -Wsign-compare dnl
  82. -Wstrict-aliasing dnl
  83. -Wshadow dnl
  84. -Winline dnl
  85. -Wpacked dnl
  86. -Wmissing-format-attribute dnl
  87. -Wmissing-noreturn dnl
  88. -Winit-self dnl
  89. -Wredundant-decls dnl
  90. -Wmissing-include-dirs dnl
  91. -Wunused-but-set-variable dnl
  92. -Warray-bounds dnl
  93. -Wreturn-type dnl
  94. -Wswitch-enum dnl
  95. -Wswitch-default dnl
  96. -Wduplicated-cond dnl
  97. -Wduplicated-branches dnl
  98. -Wlogical-op dnl
  99. -Wrestrict dnl
  100. -Wnull-dereference dnl
  101. -Wdouble-promotion dnl
  102. $4 dnl
  103. $5 dnl
  104. $6 dnl
  105. $7 dnl
  106. ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
  107. if test "$ax_compiler_cxx" = "no" ; then
  108. # C-only flags. Warn in C++
  109. AX_APPEND_COMPILE_FLAGS([ dnl
  110. -Wnested-externs dnl
  111. -Wmissing-prototypes dnl
  112. -Wstrict-prototypes dnl
  113. -Wdeclaration-after-statement dnl
  114. -Wimplicit-function-declaration dnl
  115. -Wold-style-definition dnl
  116. -Wjump-misses-init dnl
  117. ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
  118. fi
  119. ])
  120. AS_IF([test "$ax_enable_compile_warnings" = "error"],[
  121. # "error" flags; -Werror has to be appended unconditionally because
  122. # it's not possible to test for
  123. #
  124. # suggest-attribute=format is disabled because it gives too many false
  125. # positives
  126. AX_APPEND_FLAG([-Werror],ax_warn_cflags_variable)
  127. AX_APPEND_COMPILE_FLAGS([ dnl
  128. [$ax_compiler_no_suggest_attribute_flags] dnl
  129. ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
  130. ])
  131. # In the flags below, when disabling specific flags, always add *both*
  132. # -Wno-foo and -Wno-error=foo. This fixes the situation where (for example)
  133. # we enable -Werror, disable a flag, and a build bot passes CFLAGS=-Wall,
  134. # which effectively turns that flag back on again as an error.
  135. for flag in $ax_warn_cflags_variable; do
  136. AS_CASE([$flag],
  137. [-Wno-*=*],[],
  138. [-Wno-*],[
  139. AX_APPEND_COMPILE_FLAGS([-Wno-error=$(AS_ECHO([$flag]) | $SED 's/^-Wno-//')],
  140. ax_warn_cflags_variable,
  141. [$ax_compiler_flags_test])
  142. ])
  143. done
  144. AC_LANG_POP([C])
  145. # Substitute the variables
  146. AC_SUBST(ax_warn_cflags_variable)
  147. ])dnl AX_COMPILER_FLAGS