dpkg-compiler.m4 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. if test "x$enable_compiler_warnings" = "xyes"; then
  13. if test "x$GCC" = "xyes"; then
  14. CFLAGS="$WFLAGS $CFLAGS"
  15. fi
  16. if test "x$GXX" = "xyes"; then
  17. CXXFLAGS="$WFLAGS $CXXFLAGS"
  18. fi
  19. fi])dnl
  20. ])
  21. # DPKG_COMPILER_OPTIMISATIONS
  22. # --------------------------
  23. # Add configure option to disable optimisations.
  24. AC_DEFUN([DPKG_COMPILER_OPTIMISATIONS],
  25. [AC_ARG_ENABLE(compiler-optimisations,
  26. AS_HELP_STRING([--disable-compiler-optimisations],
  27. [Disable compiler optimisations]),
  28. [if test "x$enable_compiler_optimisations" = "xno"; then
  29. [CFLAGS=$(echo "$CFLAGS" | sed -e "s/ -O[1-9]*\b/ -O0/g")]
  30. fi])dnl
  31. ])
  32. # DPKG_C_ATTRIBUTE
  33. # ----------------
  34. # Check whether the C compiler supports __attribute__, defines HAVE_C_ATTRIBUTE
  35. AC_DEFUN([DPKG_C_ATTRIBUTE],
  36. [AC_CACHE_CHECK([whether compiler supports __attribute__], [dpkg_cv_attribute],
  37. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  38. [[]],
  39. [[extern int testfunction(int x) __attribute__((unused))]]
  40. )],
  41. [dpkg_cv_attribute=yes],
  42. [dpkg_cv_attribute=no])])
  43. AS_IF([test "x$dpkg_cv_attribute" = "xyes"],
  44. [AC_DEFINE([HAVE_C_ATTRIBUTE], 1,
  45. [Define to 1 if compiler supports '__attribute__', 0 otherwise.])],
  46. [AC_DEFINE([HAVE_C_ATTRIBUTE], 0)])dnl
  47. ])# DPKG_C_ATTRIBUTE
  48. # DPKG_TRY_C99([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  49. # ------------------------------------------------------
  50. # Try compiling some C99 code to see whether it works
  51. AC_DEFUN([DPKG_TRY_C99],
  52. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  53. #include <inttypes.h>
  54. #include <stdbool.h>
  55. #include <stdio.h>
  56. /* Variadic macro arguments */
  57. #define variadic_macro(foo, ...) printf(foo, __VA_ARGS__)
  58. ]],
  59. [[
  60. /* Compound initialisers */
  61. struct { int a, b; } foo = { .a = 1, .b = 2 };
  62. /* Trailing comma in enum */
  63. enum { first, second, } quux;
  64. /* Boolean type */
  65. bool bar = false;
  66. /* Specific size type */
  67. uint32_t baz = 0;
  68. /* Magic __func__ variable */
  69. printf("%s", __func__);
  70. ]])], [$1], [$2])dnl
  71. ])# DPKG_TRY_C99
  72. # DPKG_C_C99
  73. # ----------
  74. # Check whether the compiler can do C99
  75. AC_DEFUN([DPKG_C_C99],
  76. [AC_CACHE_CHECK([whether compiler supports C99 features], [dpkg_cv_c99],
  77. [DPKG_TRY_C99([dpkg_cv_c99=yes], [dpkg_cv_c99=no])])
  78. AS_IF([test "x$dpkg_cv_c99" = "xyes"],
  79. [AC_DEFINE([HAVE_C99], 1, [Define to 1 if the compiler supports C99.])],
  80. [AC_CACHE_CHECK([what argument makes compiler support C99 features],
  81. [dpkg_cv_c99_arg],
  82. [dpkg_cv_c99_arg=none
  83. dpkg_save_CC="$CC"
  84. for arg in "-std=gnu99" "-std=c99" "-c99" "-AC99" \
  85. "-xc99=all" "-qlanglvl=extc99"; do
  86. CC="$dpkg_save_CC $arg"
  87. DPKG_TRY_C99([dpkg_arg_worked=yes], [dpkg_arg_worked=no])
  88. CC="$dpkg_save_CC"
  89. AS_IF([test "x$dpkg_arg_worked" = "xyes"],
  90. [dpkg_cv_c99_arg="$arg"; break])
  91. done])
  92. AS_IF([test "x$dpkg_cv_c99_arg" != "xnone"],
  93. [CC="$CC $dpkg_cv_c99_arg"
  94. AC_DEFINE([HAVE_C99], 1)],
  95. [AC_MSG_ERROR([unsupported required C99 extensions])])])[]dnl
  96. ])# DPKG_C_C99