compiler.m4 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
  2. # DPKG_COMPILER_WARNINGS
  3. # ---------------------
  4. # Add configure option to enable additional compiler warnings and treat
  5. # them as errors.
  6. AC_DEFUN([DPKG_COMPILER_WARNINGS],
  7. [AC_ARG_ENABLE(compiler-warnings,
  8. AS_HELP_STRING([--enable-compiler-warnings],
  9. [Enable additional compiler warnings]),
  10. [if test "x$enable_compiler_warnings" = "xyes"; then
  11. if test "x$GCC" = "xyes"; then
  12. CFLAGS="-Wall -Werror $CFLAGS"
  13. fi
  14. if test "x$GXX" = "xyes"; then
  15. CXXFLAGS="-Wall -Werror $CXXFLAGS"
  16. fi
  17. fi])dnl
  18. ])
  19. # DPKG_COMPILER_OPTIMISATIONS
  20. # --------------------------
  21. # Add configure option to disable optimisations.
  22. AC_DEFUN([DPKG_COMPILER_OPTIMISATIONS],
  23. [AC_ARG_ENABLE(compiler-optimisations,
  24. AS_HELP_STRING([--disable-compiler-optimisations],
  25. [Disable compiler optimisations]),
  26. [if test "x$enable_compiler_optimisations" = "xno"; then
  27. [CFLAGS=`echo "$CFLAGS" | sed -e "s/ -O[1-9]*\b/ -O0/g"`]
  28. fi])dnl
  29. ])
  30. # DPKG_C_ATTRIBUTE
  31. # ----------------
  32. # Check whether the C compiler supports __attribute__, defines HAVE_C_ATTRIBUTE
  33. AC_DEFUN([DPKG_C_ATTRIBUTE],
  34. [AC_CACHE_CHECK([whether compiler supports __attribute__], [dpkg_cv_attribute],
  35. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  36. [[]],
  37. [[extern int testfunction(int x) __attribute__((unused))]]
  38. )],
  39. [dpkg_cv_attribute=yes],
  40. [dpkg_cv_attribute=no])])
  41. AS_IF([test "x$dpkg_cv_attribute" = "xyes"],
  42. [AC_DEFINE([HAVE_C_ATTRIBUTE], 1,
  43. [Define to 1 if compiler supports `__attribute__', 0 otherwise.])],
  44. [AC_DEFINE([HAVE_C_ATTRIBUTE], 0)])dnl
  45. ])# DPKG_C_ATTRIBUTE
  46. # DPKG_TRY_C99([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  47. # ------------------------------------------------------
  48. # Try compiling some C99 code to see whether it works
  49. AC_DEFUN([DPKG_TRY_C99],
  50. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  51. #include <stdio.h>
  52. #include <stdbool.h>
  53. #include <inttypes.h>
  54. /* Variadic macro arguments */
  55. #define variadic_macro(foo, ...) printf(foo, __VA_ARGS__)
  56. ]],
  57. [[
  58. /* Compound initialisers */
  59. struct { int a, b; } foo = { .a = 1, .b = 2 };
  60. /* Boolean type */
  61. bool bar = false;
  62. /* Specific size type */
  63. uint32_t baz = 0;
  64. /* C99-style for-loop declarations */
  65. for (int i = 0; i < 10; i++)
  66. continue;
  67. /* Magic __func__ variable */
  68. printf("%s", __func__);
  69. ]])], [$1], [$2])dnl
  70. ])# DPKG_TRY_C99
  71. # DPKG_C_C99
  72. # ----------
  73. # Check whether the compiler can do C99
  74. AC_DEFUN([DPKG_C_C99],
  75. [AC_CACHE_CHECK([whether compiler supports C99 features], [dpkg_cv_c99],
  76. [DPKG_TRY_C99([dpkg_cv_c99=yes], [dpkg_cv_c99=no])])
  77. AS_IF([test "x$dpkg_cv_c99" = "xyes"],
  78. [AC_DEFINE([HAVE_C99], 1, [Define to 1 if the compiler supports C99.])],
  79. [AC_CACHE_CHECK([what argument makes compiler support C99 features],
  80. [dpkg_cv_c99_arg],
  81. [dpkg_cv_c99_arg=none
  82. dpkg_save_CC="$CC"
  83. for arg in "-std=gnu99" "-std=c99" "-c99"; do
  84. CC="$dpkg_save_CC $arg"
  85. DPKG_TRY_C99([dpkg_arg_worked=yes], [dpkg_arg_worked=no])
  86. CC="$dpkg_save_CC"
  87. AS_IF([test "x$dpkg_arg_worked" = "xyes"],
  88. [dpkg_cv_c99_arg="$arg"; break])
  89. done])
  90. AS_IF([test "x$dpkg_cv_c99_arg" != "xnone"],
  91. [CC="$CC $dpkg_cv_c99_arg"
  92. AC_DEFINE([HAVE_C99], 1)])])[]dnl
  93. ])# DPKG_C_C99