dpkg-compiler.m4 3.4 KB

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