dpkg-compiler.m4 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Copyright © 2004 Scott James Remnant <scott@netsplit.com>
  2. # Copyright © 2006, 2009 Guillem Jover <guillem@debian.org>
  3. # DPKG_COMPILER_WARNINGS
  4. # ---------------------
  5. # Add configure option to enable additional compiler warnings and treat
  6. # them as errors.
  7. AC_DEFUN([DPKG_COMPILER_WARNINGS],
  8. [AC_ARG_ENABLE(compiler-warnings,
  9. AS_HELP_STRING([--enable-compiler-warnings],
  10. [Enable additional compiler warnings]),
  11. [WFLAGS="-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers \
  12. -Wmissing-declarations -Wmissing-format-attribute \
  13. -Wvla -Winit-self -Wwrite-strings -Wcast-align"
  14. WCFLAGS="-Wdeclaration-after-statement -Wnested-externs -Wbad-function-cast \
  15. -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition"
  16. # Temporarily here until #542031 gets fixed in ncurses
  17. WCXXFLAGS="-Wno-unused-value"
  18. if test "x$enable_compiler_warnings" = "xyes"; then
  19. if test "x$GCC" = "xyes"; then
  20. CFLAGS="$WFLAGS $WCFLAGS $CFLAGS"
  21. fi
  22. if test "x$GXX" = "xyes"; then
  23. CXXFLAGS="$WFLAGS $WCXXFLAGS $CXXFLAGS"
  24. fi
  25. fi])dnl
  26. ])
  27. # DPKG_COMPILER_OPTIMISATIONS
  28. # --------------------------
  29. # Add configure option to disable optimisations.
  30. AC_DEFUN([DPKG_COMPILER_OPTIMISATIONS],
  31. [AC_ARG_ENABLE(compiler-optimisations,
  32. AS_HELP_STRING([--disable-compiler-optimisations],
  33. [Disable compiler optimisations]),
  34. [if test "x$enable_compiler_optimisations" = "xno"; then
  35. [CFLAGS=$(echo "$CFLAGS" | sed -e "s/ -O[1-9]*\b/ -O0/g")]
  36. fi])dnl
  37. ])
  38. # DPKG_TRY_C99([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  39. # ------------------------------------------------------
  40. # Try compiling some C99 code to see whether it works
  41. AC_DEFUN([DPKG_TRY_C99],
  42. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  43. #include <inttypes.h>
  44. #include <stdbool.h>
  45. #include <stdio.h>
  46. /* Variadic macro arguments */
  47. #define variadic_macro(foo, ...) printf(foo, __VA_ARGS__)
  48. ]],
  49. [[
  50. /* Compound initialisers */
  51. struct { int a, b; } foo = { .a = 1, .b = 2 };
  52. /* Trailing comma in enum */
  53. enum { first, second, } quux;
  54. /* Boolean type */
  55. bool bar = false;
  56. /* Specific size type */
  57. uint32_t baz = 0;
  58. /* Magic __func__ variable */
  59. printf("%s", __func__);
  60. ]])], [$1], [$2])dnl
  61. ])# DPKG_TRY_C99
  62. # DPKG_C_C99
  63. # ----------
  64. # Check whether the compiler can do C99
  65. AC_DEFUN([DPKG_C_C99],
  66. [AC_CACHE_CHECK([whether compiler supports C99 features], [dpkg_cv_c99],
  67. [DPKG_TRY_C99([dpkg_cv_c99=yes], [dpkg_cv_c99=no])])
  68. AS_IF([test "x$dpkg_cv_c99" = "xyes"],
  69. [AC_DEFINE([HAVE_C99], 1, [Define to 1 if the compiler supports C99.])],
  70. [AC_CACHE_CHECK([what argument makes compiler support C99 features],
  71. [dpkg_cv_c99_arg],
  72. [dpkg_cv_c99_arg=none
  73. dpkg_save_CC="$CC"
  74. for arg in "-std=gnu99" "-std=c99" "-c99" "-AC99" \
  75. "-xc99=all" "-qlanglvl=extc99"; do
  76. CC="$dpkg_save_CC $arg"
  77. DPKG_TRY_C99([dpkg_arg_worked=yes], [dpkg_arg_worked=no])
  78. CC="$dpkg_save_CC"
  79. AS_IF([test "x$dpkg_arg_worked" = "xyes"],
  80. [dpkg_cv_c99_arg="$arg"; break])
  81. done])
  82. AS_IF([test "x$dpkg_cv_c99_arg" != "xnone"],
  83. [CC="$CC $dpkg_cv_c99_arg"
  84. AC_DEFINE([HAVE_C99], 1)],
  85. [AC_MSG_ERROR([unsupported required C99 extensions])])])[]dnl
  86. ])# DPKG_C_C99