dpkg-compiler.m4 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. [],
  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. [],
  36. [enable_compiler_optimisations=yes])
  37. AS_IF([test "x$enable_compiler_optimisations" = "xno"], [
  38. CFLAGS=$(echo "$CFLAGS" | sed -e "s/ -O[[1-9]]*\b/ -O0/g")
  39. ])
  40. ])
  41. # DPKG_TRY_C99([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  42. # ------------------------------------------------------
  43. # Try compiling some C99 code to see whether it works
  44. AC_DEFUN([DPKG_TRY_C99],
  45. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  46. #include <inttypes.h>
  47. #include <stdbool.h>
  48. #include <stdio.h>
  49. /* Variadic macro arguments. */
  50. #define variadic_macro(foo, ...) printf(foo, __VA_ARGS__)
  51. ]],
  52. [[
  53. /* Compound initializers. */
  54. struct { int a, b; } foo = { .a = 1, .b = 2 };
  55. /* Trailing comma in enum. */
  56. enum { first, second, } quux;
  57. /* Boolean type. */
  58. bool bar = false;
  59. /* Specific size type. */
  60. uint32_t baz = 0;
  61. /* Magic __func__ variable. */
  62. printf("%s", __func__);
  63. ]])], [$1], [$2])dnl
  64. ])# DPKG_TRY_C99
  65. # DPKG_C_C99
  66. # ----------
  67. # Check whether the compiler can do C99
  68. AC_DEFUN([DPKG_C_C99],
  69. [AC_CACHE_CHECK([whether compiler supports C99 features], [dpkg_cv_c99],
  70. [DPKG_TRY_C99([dpkg_cv_c99=yes], [dpkg_cv_c99=no])])
  71. AS_IF([test "x$dpkg_cv_c99" = "xyes"],
  72. [AC_DEFINE([HAVE_C99], 1, [Define to 1 if the compiler supports C99.])],
  73. [AC_CACHE_CHECK([what argument makes compiler support C99 features],
  74. [dpkg_cv_c99_arg],
  75. [dpkg_cv_c99_arg=none
  76. dpkg_save_CC="$CC"
  77. for arg in "-std=gnu99" "-std=c99" "-c99" "-AC99" \
  78. "-xc99=all" "-qlanglvl=extc99"; do
  79. CC="$dpkg_save_CC $arg"
  80. DPKG_TRY_C99([dpkg_arg_worked=yes], [dpkg_arg_worked=no])
  81. CC="$dpkg_save_CC"
  82. AS_IF([test "x$dpkg_arg_worked" = "xyes"],
  83. [dpkg_cv_c99_arg="$arg"; break])
  84. done])
  85. AS_IF([test "x$dpkg_cv_c99_arg" != "xnone"],
  86. [CC="$CC $dpkg_cv_c99_arg"
  87. AC_DEFINE([HAVE_C99], 1)],
  88. [AC_MSG_ERROR([unsupported required C99 extensions])])])[]dnl
  89. ])# DPKG_C_C99