dpkg-compiler.m4 3.2 KB

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